LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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.
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
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
Basic LSST definitions.