LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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 
73 SimpleRecord::~SimpleRecord() = default;
74 
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 
92 SimpleTable::~SimpleTable() = default;
93 
94 SimpleTable::MinimalSchema::MinimalSchema() {
95  id = schema.addField<RecordId>("id", "unique ID");
96  coord = CoordKey::addFields(schema, "coord", "position in ra/dec");
97  schema.getCitizen().markPersistent();
98 }
99 
100 SimpleTable::MinimalSchema& SimpleTable::getMinimalSchema() {
101  static MinimalSchema it;
102  return it;
103 }
104 
105 std::shared_ptr<io::FitsWriter> SimpleTable::makeFitsWriter(fits::Fits* fitsfile, int flags) const {
106  return std::make_shared<SimpleFitsWriter>(fitsfile, flags);
107 }
108 
110  return std::shared_ptr<SimpleTable>(new SimpleTable(*this));
111 }
112 
114  auto record = constructRecord<SimpleRecord>();
115  if (getIdFactory()) record->setId((*getIdFactory())());
116  return record;
117 }
118 
119 template class CatalogT<SimpleRecord>;
120 template class CatalogT<SimpleRecord const>;
121 
122 template class SortedCatalogT<SimpleRecord>;
124 } // namespace table
125 } // namespace afw
126 } // 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:113
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:84
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
Fits * fits
Definition: FitsWriter.cc:90
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
Definition: Simple.cc:109
Table class that must contain a unique ID field and a celestial coordinate field. ...
Definition: Simple.h:102
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
std::shared_ptr< SimpleTable > clone() const
Return a polymorphic deep copy of the table.
Definition: Simple.h:176
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
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
Base class for all tables.
Definition: BaseTable.h:61
SchemaMapper * mapper
Definition: SchemaMapper.cc:78