LSSTApplications  16.0-11-g09ed895+2,16.0-11-g12e47bd,16.0-11-g9bb73b2+6,16.0-12-g5c924a4+6,16.0-14-g9a974b3+1,16.0-15-g1417920+1,16.0-15-gdd5ca33+1,16.0-16-gf0259e2,16.0-17-g31abd91+7,16.0-17-g7d7456e+7,16.0-17-ga3d2e9f+13,16.0-18-ga4d4bcb+1,16.0-18-gd06566c+1,16.0-2-g0febb12+21,16.0-2-g9d5294e+69,16.0-2-ga8830df+6,16.0-20-g21842373+7,16.0-24-g3eae5ec,16.0-28-gfc9ea6c+4,16.0-29-ge8801f9,16.0-3-ge00e371+34,16.0-4-g18f3627+13,16.0-4-g5f3a788+20,16.0-4-ga3eb747+10,16.0-4-gabf74b7+29,16.0-4-gb13d127+6,16.0-49-g42e581f7+6,16.0-5-g27fb78a+7,16.0-5-g6a53317+34,16.0-5-gb3f8a4b+87,16.0-6-g9321be7+4,16.0-6-gcbc7b31+42,16.0-6-gf49912c+29,16.0-7-gd2eeba5+51,16.0-71-ge89f8615e,16.0-8-g21fd5fe+29,16.0-8-g3a9f023+20,16.0-8-g4734f7a+1,16.0-8-g5858431+3,16.0-9-gf5c1f43+8,master-gd73dc1d098+1,w.2019.01
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"
8 #include "ndarray/Manager.h"
9 #include "lsst/afw/table/fwd.h"
10 #include "lsst/afw/table/Schema.h"
11 
12 namespace lsst {
13 namespace afw {
14 
15 namespace fits {
16 
17 class Fits;
18 
19 } // namespace fits
20 
21 namespace table {
22 
44 class BaseTable : public std::enable_shared_from_this<BaseTable>, public daf::base::Citizen {
45 public:
47  typedef BaseRecord Record;
48 
51 
54 
57 
59  static int nRecordsPerBlock;
60 
63 
65  void setMetadata(std::shared_ptr<daf::base::PropertyList> const& metadata) { _metadata = metadata; }
66 
70  _metadata.swap(tmp);
71  return tmp;
72  }
73 
83  std::shared_ptr<BaseTable> clone() const { return _clone(); }
84 
91  std::shared_ptr<BaseRecord> makeRecord() { return _makeRecord(); }
92 
110  std::shared_ptr<BaseRecord> copyRecord(BaseRecord const& input);
111 
117  std::shared_ptr<BaseRecord> copyRecord(BaseRecord const& input, SchemaMapper const& mapper);
118 
120  Schema getSchema() const { return _schema; }
121 
134  void preallocate(std::size_t nRecords);
135 
141  std::size_t getBufferSize() const;
142 
155  static std::shared_ptr<BaseTable> make(Schema const& schema);
156 
157  // Tables are not assignable to prevent type slicing.
158  BaseTable& operator=(BaseTable const& other) = delete;
159  BaseTable& operator=(BaseTable&& other) = delete;
160 
161  virtual ~BaseTable();
162 
163 protected:
165  template <typename Derived>
167  return std::static_pointer_cast<Derived>(shared_from_this());
168  }
169 
171  template <typename Derived>
173  return std::static_pointer_cast<Derived const>(shared_from_this());
174  }
175 
176  virtual void handleAliasChange(std::string const& alias) {}
177 
179  virtual std::shared_ptr<BaseTable> _clone() const;
180 
182  virtual std::shared_ptr<BaseRecord> _makeRecord();
183 
185  explicit BaseTable(Schema const& schema);
186 
188  BaseTable(BaseTable const& other)
189  : daf::base::Citizen(other), _schema(other._schema), _metadata(other._metadata) {
190  if (_metadata) _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
191  }
192  // Delegate to copy-constructor for backwards compatibility
193  BaseTable(BaseTable&& other) : BaseTable(other) {}
194 
195 private:
196  friend class BaseRecord;
197  friend class io::FitsWriter;
198  friend class AliasMap;
199 
200  // Called by BaseRecord ctor to fill in its _data, _table, and _manager members.
201  void _initialize(BaseRecord& record);
202 
203  /*
204  * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
205  *
206  * This could allow the table to reclaim that space, but that requires more bookkeeping than
207  * it's presently worth unless this was the most recently allocated record.
208  *
209  * The motivation for attempting to reclaim even some memory is not because we're paranoid
210  * about using every last bit of allocated memory efficiently - it's so we can keep
211  * records contiguous as much as possible to allow ColumnView to be used.
212  */
213  void _destroy(BaseRecord& record);
214 
215  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
216  virtual std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const;
217 
218  // All these are definitely private, not protected - we don't want derived classes mucking with them.
219  Schema _schema; // schema that defines the table's fields
220  ndarray::Manager::Ptr _manager; // current memory block to use for new records
221  std::shared_ptr<daf::base::PropertyList> _metadata; // flexible metadata; may be null
222 };
223 } // namespace table
224 } // namespace afw
225 } // namespace lsst
226 
227 #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:47
std::shared_ptr< daf::base::PropertyList > getMetadata() const
Return the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:62
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:83
std::shared_ptr< BaseRecord > makeRecord()
Default-construct an associated record.
Definition: BaseTable.h:91
BaseTable(BaseTable &&other)
Definition: BaseTable.h:193
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
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:50
Schema getSchema() const
Return the table&#39;s schema.
Definition: BaseTable.h:120
std::shared_ptr< Derived const > getSelf() const
Convenience function for static-casting shared_from_this for use by derived classes.
Definition: BaseTable.h:172
Mapping class that holds aliases for a Schema.
Definition: AliasMap.h:36
BaseTable(BaseTable const &other)
Copy construct.
Definition: BaseTable.h:188
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:296
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:65
static int nRecordsPerBlock
Number of records in each memory block.
Definition: BaseTable.h:59
A base class for image defects.
Definition: cameraGeom.dox:3
CatalogT< Record const > ConstCatalog
Template of CatalogT used to hold const records of the associated type.
Definition: BaseTable.h:56
CatalogT< Record > Catalog
Template of CatalogT used to hold records of the associated type.
Definition: BaseTable.h:53
Basic LSST definitions.
table::Schema schema
Definition: Camera.cc:161
T static_pointer_cast(T... args)
std::shared_ptr< Derived > getSelf()
Convenience function for static-casting shared_from_this for use by derived classes.
Definition: BaseTable.h:166
Base class for all records.
Definition: BaseRecord.h:31
ItemVariant const * other
Definition: Schema.cc:56
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:55
std::shared_ptr< daf::base::PropertyList > popMetadata()
Return the metadata and set the internal metadata to a null pointer.
Definition: BaseTable.h:68
Base class for all tables.
Definition: BaseTable.h:44
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:176
SchemaMapper * mapper
Definition: SchemaMapper.cc:78