LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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