LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
Simple.cc
Go to the documentation of this file.
1// -*- lsst-c++ -*-
2#include <typeinfo>
3
8
9namespace lsst {
10namespace afw {
11namespace table {
12
13//-----------------------------------------------------------------------------------------------------------
14//----- SimpleFitsWriter ---------------------------------------------------------------------------------
15//-----------------------------------------------------------------------------------------------------------
16
17// A custom FitsWriter for Simple - this just sets the AFW_TYPE key to SIMPLE, which should ensure
18// we use SimpleFitsReader to read it.
19
20namespace {
21
22class SimpleFitsWriter : public io::FitsWriter {
23public:
24 explicit SimpleFitsWriter(Fits* fits, int flags) : io::FitsWriter(fits, flags) {}
25
26protected:
27 void _writeTable(std::shared_ptr<BaseTable const> const& table, std::size_t nRows) override;
28};
29
30void SimpleFitsWriter::_writeTable(std::shared_ptr<BaseTable const> const& t, std::size_t nRows) {
31 std::shared_ptr<SimpleTable const> table = std::dynamic_pointer_cast<SimpleTable const>(t);
32 if (!table) {
34 "Cannot use a SimpleFitsWriter on a non-Simple table.");
35 }
36 io::FitsWriter::_writeTable(table, nRows);
37 _fits->writeKey("AFW_TYPE", "SIMPLE", "Tells lsst::afw to load this as a Simple table.");
38}
39
40} // namespace
41
42//-----------------------------------------------------------------------------------------------------------
43//----- SimpleFitsReader ---------------------------------------------------------------------------------
44//-----------------------------------------------------------------------------------------------------------
45
46// A custom FitsReader for SimpleTable/Record - this gets registered with name SIMPLE, so it should get used
47// whenever we read a table with AFW_TYPE set to that value.
48
49namespace {
50
51class SimpleFitsReader : public io::FitsReader {
52public:
53 SimpleFitsReader() : io::FitsReader("SIMPLE") {}
54
55 std::shared_ptr<BaseTable> makeTable(io::FitsSchemaInputMapper& mapper,
56 std::shared_ptr<daf::base::PropertyList> metadata, int ioFlags,
57 bool stripMetadata) const override {
59 table->setMetadata(metadata);
60 return table;
61 }
62};
63
64// registers the reader so FitsReader::make can use it.
65static SimpleFitsReader const simpleFitsReader;
66
67} // namespace
68
69//-----------------------------------------------------------------------------------------------------------
70//----- SimpleTable/Record member function implementations -----------------------------------------------
71//-----------------------------------------------------------------------------------------------------------
72
74
76 std::shared_ptr<IdFactory> const& idFactory) {
77 if (!checkSchema(schema)) {
79 "Schema for Simple must contain at least the keys defined by makeMinimalSchema().");
80 }
81 return std::shared_ptr<SimpleTable>(new SimpleTable(schema, idFactory));
82}
83
85 : BaseTable(schema), _idFactory(idFactory) {}
86
88 : BaseTable(other), _idFactory(other._idFactory ? other._idFactory->clone() : other._idFactory) {}
89// Delegate to copy constructor for backwards compatibility
91
93
94SimpleTable::MinimalSchema::MinimalSchema() {
95 id = schema.addField<RecordId>("id", "unique ID");
96 coord = CoordKey::addFields(schema, "coord", "position in ra/dec");
97}
98
99SimpleTable::MinimalSchema& SimpleTable::getMinimalSchema() {
100 static MinimalSchema it;
101 return it;
102}
103
104std::shared_ptr<io::FitsWriter> SimpleTable::makeFitsWriter(fits::Fits* fitsfile, int flags) const {
105 return std::make_shared<SimpleFitsWriter>(fitsfile, flags);
106}
107
109 return std::shared_ptr<SimpleTable>(new SimpleTable(*this));
110}
111
113 auto record = constructRecord<SimpleRecord>();
114 if (getIdFactory()) record->setId((*getIdFactory())());
115 return record;
116}
117
118template class CatalogT<SimpleRecord>;
119template class CatalogT<SimpleRecord const>;
120
121template class SortedCatalogT<SimpleRecord>;
123} // namespace table
124} // namespace afw
125} // namespace lsst
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
SchemaMapper * mapper
Definition: SchemaMapper.cc:71
table::Schema schema
Definition: python.h:134
Base class for all tables.
Definition: BaseTable.h:61
A custom container class for records, based on std::vector.
Definition: Catalog.h:98
static CoordKey addFields(afw::table::Schema &schema, std::string const &name, std::string const &doc)
Add a pair of _ra, _dec fields to a Schema, and return a CoordKey that points to them.
Definition: aggregates.cc:109
Defines the fields and offsets for a table.
Definition: Schema.h:51
Table class that must contain a unique ID field and a celestial coordinate field.
Definition: Simple.h:102
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid SimpleTable schema.
Definition: Simple.h:152
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
Definition: Simple.cc:108
std::shared_ptr< BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
Definition: Simple.cc:112
std::shared_ptr< IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:155
static std::shared_ptr< SimpleTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
Definition: Simple.cc:75
SimpleTable(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Definition: Simple.cc:84
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Definition: SortedCatalog.h:42
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
Definition: FitsWriter.cc:103
Reports invalid arguments.
Definition: Runtime.h:66
Reports errors in the logical structure of the program.
Definition: Runtime.h:46