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
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  typedef BaseRecord Record;
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 
174  // Tables are not assignable to prevent type slicing.
175  BaseTable& operator=(BaseTable const& other) = delete;
177 
178  virtual ~BaseTable();
179 
180 protected:
181 
196  // n.b. this is implemented in BaseRecord.h, as it requires the BaseRecord
197  // definition, and must go in a header.
198  template <typename RecordT, typename ...Args>
200 
201  virtual void handleAliasChange(std::string const& alias) {}
202 
204  virtual std::shared_ptr<BaseTable> _clone() const;
205 
208 
210  explicit BaseTable(Schema const& schema);
211 
213  BaseTable(BaseTable const& other) : _schema(other._schema), _metadata(other._metadata) {
214  if (_metadata) _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
215  }
216  // Delegate to copy-constructor for backwards compatibility
218 
219 private:
220  friend class BaseRecord;
221  friend class io::FitsWriter;
222  friend class AliasMap;
223 
224  // Obtain raw data pointers and their managing objects for a new record.
225  detail::RecordData _makeNewRecordData();
226 
227  /*
228  * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
229  *
230  * This could allow the table to reclaim that space, but that requires more bookkeeping than
231  * it's presently worth unless this was the most recently allocated record.
232  *
233  * The motivation for attempting to reclaim even some memory is not because we're paranoid
234  * about using every last bit of allocated memory efficiently - it's so we can keep
235  * records contiguous as much as possible to allow ColumnView to be used.
236  */
237  void _destroy(BaseRecord& record);
238 
239  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
240  virtual std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const;
241 
242  // All these are definitely private, not protected - we don't want derived classes mucking with them.
243  Schema _schema; // schema that defines the table's fields
244  ndarray::Manager::Ptr _manager; // current memory block to use for new records
245  std::shared_ptr<daf::base::PropertyList> _metadata; // flexible metadata; may be null
246 };
247 
248 } // namespace table
249 } // namespace afw
250 } // namespace lsst
251 
252 #endif // !AFW_TABLE_BaseTable_h_INCLUDED
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
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
CatalogT< Record const > ConstCatalog
Template of CatalogT used to hold const records of the associated type.
Definition: BaseTable.h:73
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:145
virtual std::shared_ptr< io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const
Definition: BaseTable.cc:137
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
CatalogT< Record > Catalog
Template of CatalogT used to hold records of the associated type.
Definition: BaseTable.h:70
void preallocate(std::size_t nRecords)
Allocate contiguous space for new records in advance.
Definition: BaseTable.cc:111
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:125
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:213
BaseTable(Schema const &schema)
Construct from a schema.
Definition: BaseTable.cc:149
std::size_t getBufferSize() const
Return the number of additional records space has been already been allocated for.
Definition: BaseTable.cc:113
BaseColumnView ColumnView
The associated ColumnView class.
Definition: BaseTable.h:67
BaseTable(BaseTable &&other)
Definition: BaseTable.h:217
BaseRecord Record
The associated record class.
Definition: BaseTable.h:64
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:121
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:201
BaseTable & operator=(BaseTable const &other)=delete
virtual std::shared_ptr< BaseTable > _clone() const
Clone implementation with noncovariant return types.
Definition: BaseTable.cc:141
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
Defines the fields and offsets for a table.
Definition: Schema.h:50
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