LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
LSST Data Management Base Package
BaseTable.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_BaseTable_h_INCLUDED
3 #define AFW_TABLE_BaseTable_h_INCLUDED
4 #include <memory>
5 
6 #include "lsst/base.h"
7 #include "ndarray/Manager.h"
8 #include "lsst/afw/table/fwd.h"
10 
11 namespace lsst {
12 namespace afw {
13 
14 namespace fits {
15 
16 class Fits;
17 
18 } // namespace fits
19 
20 namespace table {
21 
22 namespace detail {
23 
32 struct RecordData {
33  void * data;
35  ndarray::Manager::Ptr manager;
36 };
37 
38 } // namespace detail
39 
61 class BaseTable : public std::enable_shared_from_this<BaseTable> {
62 public:
64  using Record = BaseRecord;
65 
68 
71 
74 
76  static int nRecordsPerBlock;
77 
80 
82  void setMetadata(std::shared_ptr<daf::base::PropertyList> const& metadata) { _metadata = metadata; }
83 
87  _metadata.swap(tmp);
88  return tmp;
89  }
90 
101 
109 
128 
135 
137  Schema getSchema() const { return _schema; }
138 
151  void preallocate(std::size_t nRecords);
152 
158  std::size_t getBufferSize() const;
159 
173 
179  static Schema makeMinimalSchema();
180 
181  // Tables are not assignable to prevent type slicing.
182  BaseTable& operator=(BaseTable const& other) = delete;
183  BaseTable& operator=(BaseTable&& other) = delete;
184 
185  virtual ~BaseTable();
186 
187 protected:
188 
203  // n.b. this is implemented in BaseRecord.h, as it requires the BaseRecord
204  // definition, and must go in a header.
205  template <typename RecordT, typename ...Args>
207 
208  virtual void handleAliasChange(std::string const& alias) {}
209 
211  virtual std::shared_ptr<BaseTable> _clone() const;
212 
215 
217  explicit BaseTable(Schema const& schema);
218 
220  BaseTable(BaseTable const& other) : _schema(other._schema), _metadata(other._metadata) {
221  if (_metadata) _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
222  }
223  // Delegate to copy-constructor for backwards compatibility
224  BaseTable(BaseTable&& other) : BaseTable(other) {}
225 
226 private:
227  friend class BaseRecord;
228  friend class io::FitsWriter;
229  friend class AliasMap;
230 
231  // Obtain raw data pointers and their managing objects for a new record.
232  detail::RecordData _makeNewRecordData();
233 
234  /*
235  * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
236  *
237  * This could allow the table to reclaim that space, but that requires more bookkeeping than
238  * it's presently worth unless this was the most recently allocated record.
239  *
240  * The motivation for attempting to reclaim even some memory is not because we're paranoid
241  * about using every last bit of allocated memory efficiently - it's so we can keep
242  * records contiguous as much as possible to allow ColumnView to be used.
243  */
244  void _destroy(BaseRecord& record);
245 
246  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
247  virtual std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const;
248 
249  // All these are definitely private, not protected - we don't want derived classes mucking with them.
250  Schema _schema; // schema that defines the table's fields
251  ndarray::Manager::Ptr _manager; // current memory block to use for new records
252  std::shared_ptr<daf::base::PropertyList> _metadata; // flexible metadata; may be null
253 };
254 
255 } // namespace table
256 } // namespace afw
257 } // namespace lsst
258 
259 #endif // !AFW_TABLE_BaseTable_h_INCLUDED
Fits * fits
Definition: FitsWriter.cc:90
SchemaMapper * mapper
Definition: SchemaMapper.cc:71
table::Schema schema
Definition: python.h:134
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
Mapping class that holds aliases for a Schema.
Definition: AliasMap.h:36
Column-wise view into a sequence of records that have been allocated contiguously.
Base class for all records.
Definition: BaseRecord.h:31
Base class for all tables.
Definition: BaseTable.h:61
void setMetadata(std::shared_ptr< daf::base::PropertyList > const &metadata)
Set the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:82
std::shared_ptr< BaseRecord > makeRecord()
Default-construct an associated record.
Definition: BaseTable.h:108
virtual std::shared_ptr< BaseRecord > _makeRecord()
Default-construct an associated record (protected implementation).
Definition: BaseTable.cc:148
virtual std::shared_ptr< io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const
Definition: BaseTable.cc:140
Schema getSchema() const
Return the table's schema.
Definition: BaseTable.h:137
std::shared_ptr< BaseTable > clone() const
Return a polymorphic deep copy of the table.
Definition: BaseTable.h:100
void preallocate(std::size_t nRecords)
Allocate contiguous space for new records in advance.
Definition: BaseTable.cc:110
std::shared_ptr< RecordT > constructRecord(Args &&...args)
Helper function that must be used by all _makeRecord overrides to actually construct records.
Definition: BaseRecord.h:227
std::shared_ptr< daf::base::PropertyList > popMetadata()
Return the metadata and set the internal metadata to a null pointer.
Definition: BaseTable.h:85
std::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
Definition: BaseTable.cc:128
std::shared_ptr< daf::base::PropertyList > getMetadata() const
Return the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:79
BaseTable & operator=(BaseTable &&other)=delete
BaseTable(BaseTable const &other)
Copy construct.
Definition: BaseTable.h:220
BaseTable(Schema const &schema)
Construct from a schema.
Definition: BaseTable.cc:152
std::size_t getBufferSize() const
Return the number of additional records space has been already been allocated for.
Definition: BaseTable.cc:112
BaseTable(BaseTable &&other)
Definition: BaseTable.h:224
static Schema makeMinimalSchema()
Return a minimal schema for Base tables and records.
Definition: BaseTable.cc:124
static int nRecordsPerBlock
Number of records in each memory block.
Definition: BaseTable.h:76
static std::shared_ptr< BaseTable > make(Schema const &schema)
Construct a new table.
Definition: BaseTable.cc:120
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:208
BaseTable & operator=(BaseTable const &other)=delete
virtual std::shared_ptr< BaseTable > _clone() const
Clone implementation with noncovariant return types.
Definition: BaseTable.cc:144
A custom container class for records, based on std::vector.
Definition: Catalog.h:98
Defines the fields and offsets for a table.
Definition: Schema.h:51
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
A base class for image defects.
Helper struct that contains the information passed from BaseTable to BaseRecord at construction.
Definition: BaseTable.h:32
ndarray::Manager::Ptr manager
Definition: BaseTable.h:35
std::shared_ptr< BaseTable > table
Definition: BaseTable.h:34