LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
Simple.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #include <typeinfo>
3 
8 
9 namespace lsst {
10 namespace afw {
11 namespace 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 
20 namespace {
21 
22 class SimpleFitsWriter : public io::FitsWriter {
23 public:
24  explicit SimpleFitsWriter(Fits* fits, int flags) : io::FitsWriter(fits, flags) {}
25 
26 protected:
27  void _writeTable(std::shared_ptr<BaseTable const> const& table, std::size_t nRows) override;
28 };
29 
30 void SimpleFitsWriter::_writeTable(std::shared_ptr<BaseTable const> const& t, std::size_t nRows) {
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 
49 namespace {
50 
51 class SimpleFitsReader : public io::FitsReader {
52 public:
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.
65 static SimpleFitsReader const simpleFitsReader;
66 
67 } // namespace
68 
69 //-----------------------------------------------------------------------------------------------------------
70 //----- SimpleTable/Record member function implementations -----------------------------------------------
71 //-----------------------------------------------------------------------------------------------------------
72 
74 
75 SimpleRecord::~SimpleRecord() = default;
76 
79  if (!checkSchema(schema)) {
81  "Schema for Simple must contain at least the keys defined by makeMinimalSchema().");
82  }
83  return std::shared_ptr<SimpleTable>(new SimpleTable(schema, idFactory));
84 }
85 
87  : BaseTable(schema), _idFactory(idFactory) {}
88 
90  : BaseTable(other), _idFactory(other._idFactory ? other._idFactory->clone() : other._idFactory) {}
91 // Delegate to copy constructor for backwards compatibility
93 
94 SimpleTable::~SimpleTable() = default;
95 
96 SimpleTable::MinimalSchema::MinimalSchema() {
97  id = schema.addField<RecordId>("id", "unique ID");
98  coord = CoordKey::addFields(schema, "coord", "position in ra/dec");
99  schema.getCitizen().markPersistent();
100 }
101 
102 SimpleTable::MinimalSchema& SimpleTable::getMinimalSchema() {
103  static MinimalSchema it;
104  return it;
105 }
106 
107 std::shared_ptr<io::FitsWriter> SimpleTable::makeFitsWriter(fits::Fits* fitsfile, int flags) const {
108  return std::make_shared<SimpleFitsWriter>(fitsfile, flags);
109 }
110 
112  return std::shared_ptr<SimpleTable>(new SimpleTable(*this));
113 }
114 
116  std::shared_ptr<SimpleRecord> record(new SimpleRecord(getSelf<SimpleTable>()));
117  if (getIdFactory()) record->setId((*getIdFactory())());
118  return record;
119 }
120 
121 template class CatalogT<SimpleRecord>;
122 template class CatalogT<SimpleRecord const>;
123 
124 template class SortedCatalogT<SimpleRecord>;
126 } // namespace table
127 } // namespace afw
128 } // namespace lsst
Defines the fields and offsets for a table.
Definition: Schema.h:50
std::shared_ptr< BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
Definition: Simple.cc:115
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
SimpleTable(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Definition: Simple.cc:86
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:296
Fits * fits
Definition: FitsWriter.cc:90
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
Definition: Simple.cc:111
Table class that must contain a unique ID field and a celestial coordinate field. ...
Definition: Simple.h:91
A base class for image defects.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:63
table::Schema schema
Definition: Camera.cc:161
T dynamic_pointer_cast(T... args)
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
Definition: FitsWriter.cc:103
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
Base class for all records.
Definition: BaseRecord.h:31
std::shared_ptr< SimpleTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Simple.h:165
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:83
Reports invalid arguments.
Definition: Runtime.h:66
ItemVariant const * other
Definition: Schema.cc:56
friend class SimpleTable
Definition: Simple.h:81
Record class that must contain a unique ID field and a celestial coordinate field.
Definition: Simple.h:48
std::shared_ptr< IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:144
static std::shared_ptr< SimpleTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
Definition: Simple.cc:77
Base class for all tables.
Definition: BaseTable.h:44
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
SimpleRecord(const SimpleRecord &)=delete