LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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) {
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 
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 {
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 
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 
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 }
98 
99 SimpleTable::MinimalSchema& SimpleTable::getMinimalSchema() {
100  static MinimalSchema it;
101  return it;
102 }
103 
104 std::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 
118 template class CatalogT<SimpleRecord>;
119 template class CatalogT<SimpleRecord const>;
120 
121 template 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
Fits * fits
Definition: FitsWriter.cc:90
ItemVariant const * other
Definition: Schema.cc:56
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
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:97
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
Defines the fields and offsets for a table.
Definition: Schema.h:50
Table class that must contain a unique ID field and a celestial coordinate field.
Definition: Simple.h:102
std::shared_ptr< IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:155
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
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
A base class for image defects.