LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
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) {
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
schema
table::Schema schema
Definition: Amplifier.cc:115
Simple.h
lsst::afw::table::SimpleTable::make
static std::shared_ptr< SimpleTable > make(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Construct a new table.
Definition: Simple.cc:75
std::shared_ptr
STL class.
lsst::afw::table::SimpleTable::SimpleTable
SimpleTable(Schema const &schema, std::shared_ptr< IdFactory > const &idFactory)
Definition: Simple.cc:84
lsst::afw::table::SimpleRecord::~SimpleRecord
~SimpleRecord() override
lsst::afw::table::SimpleTable::checkSchema
static bool checkSchema(Schema const &other)
Return true if the given schema is a valid SimpleTable schema.
Definition: Simple.h:152
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::afw::table::BaseTable
Base class for all tables.
Definition: BaseTable.h:61
fits
Fits * fits
Definition: FitsWriter.cc:90
FitsReader.h
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::table::SimpleTable::_makeRecord
std::shared_ptr< BaseRecord > _makeRecord() override
Default-construct an associated record (protected implementation).
Definition: Simple.cc:112
lsst.pex::exceptions::LogicError
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
std::int64_t
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::afw::table::SimpleTable
Table class that must contain a unique ID field and a celestial coordinate field.
Definition: Simple.h:102
lsst::afw::table::io::FitsWriter::_writeTable
virtual void _writeTable(std::shared_ptr< BaseTable const > const &table, std::size_t nRows)
Write a table and its schema.
Definition: FitsWriter.cc:103
lsst::afw::table::SimpleTable::_clone
std::shared_ptr< BaseTable > _clone() const override
Clone implementation with noncovariant return types.
Definition: Simple.cc:108
lsst.pex::exceptions::InvalidParameterError
Reports invalid arguments.
Definition: Runtime.h:66
mapper
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
std::size_t
FitsWriter.h
lsst::afw::table::SimpleTable::getIdFactory
std::shared_ptr< IdFactory > getIdFactory()
Return the object that generates IDs for the table (may be null).
Definition: Simple.h:155
lsst::afw::table::SimpleTable::~SimpleTable
~SimpleTable() override
lsst::afw::table::CatalogT
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
lsst::afw::image.slicing.clone
clone
Definition: slicing.py:257
Access.h
lsst::afw::table::SortedCatalogT
Custom catalog class for record/table subclasses that are guaranteed to have an ID,...
Definition: fwd.h:63
lsst::afw::table::CoordKey::addFields
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