LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
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.