LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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 {
58 std::shared_ptr<SimpleTable> table = SimpleTable::make(mapper.finalize());
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, std::make_shared<daf::base::PropertyList>()), _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
105 return std::make_shared<SimpleFitsWriter>(fitsfile, flags);
106}
107
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
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition fits.h:308
Tag types used to declare specialized field types.
Definition misc.h:31
Base class for all tables.
Definition BaseTable.h:61
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.
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
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
Definition Simple.cc:108
std::shared_ptr< io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const override
Definition Simple.cc:104
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
Reports invalid arguments.
Definition Runtime.h:66
Reports errors in the logical structure of the program.
Definition Runtime.h:46
STL namespace.