lsst.afw  13.0-109-g62eb66483
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 "lsst/daf/base/Citizen.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 
62  std::shared_ptr<daf::base::PropertyList> getMetadata() const { return _metadata; }
63 
65  void setMetadata(std::shared_ptr<daf::base::PropertyList> const& metadata) { _metadata = metadata; }
66 
68  std::shared_ptr<daf::base::PropertyList> popMetadata() {
69  std::shared_ptr<daf::base::PropertyList> tmp;
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  virtual ~BaseTable();
158 
159 protected:
161  template <typename Derived>
162  std::shared_ptr<Derived> getSelf() {
163  return std::static_pointer_cast<Derived>(shared_from_this());
164  }
165 
167  template <typename Derived>
168  std::shared_ptr<Derived const> getSelf() const {
169  return std::static_pointer_cast<Derived const>(shared_from_this());
170  }
171 
172  virtual void handleAliasChange(std::string const& alias) {}
173 
175  virtual std::shared_ptr<BaseTable> _clone() const;
176 
178  virtual std::shared_ptr<BaseRecord> _makeRecord();
179 
181  explicit BaseTable(Schema const& schema);
182 
184  BaseTable(BaseTable const& other)
185  : daf::base::Citizen(other), _schema(other._schema), _metadata(other._metadata) {
186  if (_metadata) _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
187  }
188 
189 private:
190  friend class BaseRecord;
191  friend class io::FitsWriter;
192  friend class AliasMap;
193 
194  // Called by BaseRecord ctor to fill in its _data, _table, and _manager members.
195  void _initialize(BaseRecord& record);
196 
197  /*
198  * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
199  *
200  * This could allow the table to reclaim that space, but that requires more bookkeeping than
201  * it's presently worth unless this was the most recently allocated record.
202  *
203  * The motivation for attempting to reclaim even some memory is not because we're paranoid
204  * about using every last bit of allocated memory efficiently - it's so we can keep
205  * records contiguous as much as possible to allow ColumnView to be used.
206  */
207  void _destroy(BaseRecord& record);
208 
209  // Tables are not assignable to prevent type slicing; this is intentionally not implemented,
210  // so we get linker errors if we do try to use the assignment operator.
211  void operator=(BaseTable const& other);
212 
213  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
214  virtual std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const;
215 
216  // All these are definitely private, not protected - we don't want derived classes mucking with them.
217  Schema _schema; // schema that defines the table's fields
218  ndarray::Manager::Ptr _manager; // current memory block to use for new records
219  std::shared_ptr<daf::base::PropertyList> _metadata; // flexible metadata; may be null
220 };
221 }
222 }
223 } // namespace lsst::afw::table
224 
225 #endif // !AFW_TABLE_BaseTable_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:46
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
A custom container class for records, based on std::vector.
Definition: Catalog.h:96
afw::table::Schema schema
Definition: GaussianPsf.cc:43
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:168
Mapping class that holds aliases for a Schema.
Definition: AliasMap.h:36
BaseTable(BaseTable const &other)
Copy construct.
Definition: BaseTable.h:184
lsst::daf::base::PropertyList PropertyList
Definition: Wcs.cc:56
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:279
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
std::shared_ptr< Derived > getSelf()
Convenience function for static-casting shared_from_this for use by derived classes.
Definition: BaseTable.h:162
Base class for all records.
Definition: BaseRecord.h:29
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:172