LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
LSSTDataManagementBasePackage
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 
100  std::shared_ptr<BaseTable> clone() const { return _clone(); }
101 
108  std::shared_ptr<BaseRecord> makeRecord() { return _makeRecord(); }
109 
127  std::shared_ptr<BaseRecord> copyRecord(BaseRecord const& input);
128 
134  std::shared_ptr<BaseRecord> copyRecord(BaseRecord const& input, SchemaMapper const& mapper);
135 
137  Schema getSchema() const { return _schema; }
138 
151  void preallocate(std::size_t nRecords);
152 
158  std::size_t getBufferSize() const;
159 
172  static std::shared_ptr<BaseTable> make(Schema const& schema);
173 
174  // Tables are not assignable to prevent type slicing.
175  BaseTable& operator=(BaseTable const& other) = delete;
176  BaseTable& operator=(BaseTable&& 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>
199  std::shared_ptr<RecordT> constructRecord(Args && ...args);
200 
201  virtual void handleAliasChange(std::string const& alias) {}
202 
204  virtual std::shared_ptr<BaseTable> _clone() const;
205 
207  virtual std::shared_ptr<BaseRecord> _makeRecord();
208 
210  explicit BaseTable(Schema const& schema);
211 
213  BaseTable(BaseTable const& other)
214  : _schema(other._schema), _metadata(other._metadata) {
215  if (_metadata) _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
216  }
217  // Delegate to copy-constructor for backwards compatibility
218  BaseTable(BaseTable&& other) : BaseTable(other) {}
219 
220 private:
221  friend class BaseRecord;
222  friend class io::FitsWriter;
223  friend class AliasMap;
224 
225  // Obtain raw data pointers and their managing objects for a new record.
226  detail::RecordData _makeNewRecordData();
227 
228  /*
229  * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
230  *
231  * This could allow the table to reclaim that space, but that requires more bookkeeping than
232  * it's presently worth unless this was the most recently allocated record.
233  *
234  * The motivation for attempting to reclaim even some memory is not because we're paranoid
235  * about using every last bit of allocated memory efficiently - it's so we can keep
236  * records contiguous as much as possible to allow ColumnView to be used.
237  */
238  void _destroy(BaseRecord& record);
239 
240  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
241  virtual std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const;
242 
243  // All these are definitely private, not protected - we don't want derived classes mucking with them.
244  Schema _schema; // schema that defines the table's fields
245  ndarray::Manager::Ptr _manager; // current memory block to use for new records
246  std::shared_ptr<daf::base::PropertyList> _metadata; // flexible metadata; may be null
247 };
248 
249 } // namespace table
250 } // namespace afw
251 } // namespace lsst
252 
253 #endif // !AFW_TABLE_BaseTable_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:50
BaseRecord Record
The associated record class.
Definition: BaseTable.h:64
std::shared_ptr< daf::base::PropertyList > getMetadata() const
Return the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:79
Column-wise view into a sequence of records that have been allocated contiguously.
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
std::shared_ptr< BaseTable > clone() const
Return a polymorphic deep copy of the table.
Definition: BaseTable.h:100
std::shared_ptr< BaseRecord > makeRecord()
Default-construct an associated record.
Definition: BaseTable.h:108
Helper struct that contains the information passed from BaseTable to BaseRecord at construction...
Definition: BaseTable.h:32
BaseTable(BaseTable &&other)
Definition: BaseTable.h:218
T swap(T... args)
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
Class for storing ordered metadata with comments.
Definition: PropertyList.h:68
Basic LSST definitions.
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
BaseColumnView ColumnView
The associated ColumnView class.
Definition: BaseTable.h:67
Schema getSchema() const
Return the table&#39;s schema.
Definition: BaseTable.h:137
Mapping class that holds aliases for a Schema.
Definition: AliasMap.h:36
BaseTable(BaseTable const &other)
Copy construct.
Definition: BaseTable.h:213
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
Fits * fits
Definition: FitsWriter.cc:90
STL class.
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
static int nRecordsPerBlock
Number of records in each memory block.
Definition: BaseTable.h:76
A base class for image defects.
CatalogT< Record const > ConstCatalog
Template of CatalogT used to hold const records of the associated type.
Definition: BaseTable.h:73
CatalogT< Record > Catalog
Template of CatalogT used to hold records of the associated type.
Definition: BaseTable.h:70
ndarray::Manager::Ptr manager
Definition: BaseTable.h:35
table::Schema schema
Definition: Camera.cc:161
T static_pointer_cast(T... args)
std::shared_ptr< BaseTable > table
Definition: BaseTable.h:34
Base class for all records.
Definition: BaseRecord.h:31
ItemVariant const * other
Definition: Schema.cc:56
std::shared_ptr< daf::base::PropertyList > popMetadata()
Return the metadata and set the internal metadata to a null pointer.
Definition: BaseTable.h:85
Base class for all tables.
Definition: BaseTable.h:61
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:201
SchemaMapper * mapper
Definition: SchemaMapper.cc:78