LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
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 { namespace afw {
13 
14 namespace fits {
15 
16 class Fits;
17 
18 } // namespace fits
19 
20 namespace table {
21 
43 class BaseTable
44 #ifndef SWIG // swig complains about these not being %shared_ptrs, but it doesn't need to know about them
45 : public std::enable_shared_from_this<BaseTable>,
46  public daf::base::Citizen
47 #endif
48 {
49 public:
50 
52  typedef BaseRecord Record;
53 
56 
59 
62 
64  static int nRecordsPerBlock;
65 
68 
70  void setMetadata(PTR(daf::base::PropertyList) const & metadata) { _metadata = metadata; }
71 
75  _metadata.swap(tmp);
76  return tmp;
77  }
78 
88  PTR(BaseTable) clone() const { return _clone(); }
89 
97 
116 
122  PTR(BaseRecord) copyRecord(BaseRecord const & input, SchemaMapper const & mapper);
123 
125  Schema getSchema() const { return _schema; }
126 
139  void preallocate(std::size_t nRecords);
140 
146  std::size_t getBufferSize() const;
147 
160  static PTR(BaseTable) make(Schema const & schema);
161 
162  virtual ~BaseTable();
163 
164 protected:
165 
167  template <typename Derived>
168  PTR(Derived) getSelf() {
169  return std::static_pointer_cast<Derived>(shared_from_this());
170  }
171 
173  template <typename Derived>
174  CONST_PTR(Derived) getSelf() const {
175  return std::static_pointer_cast<Derived const>(shared_from_this());
176  }
177 
178  virtual void handleAliasChange(std::string const & alias) {}
179 
181  virtual PTR(BaseTable) _clone() const = 0;
182 
184  virtual PTR(BaseRecord) _makeRecord() = 0;
185 
187  explicit BaseTable(Schema const & schema);
188 
190  BaseTable(BaseTable const & other) :
191  daf::base::Citizen(other), _schema(other._schema),
192  _metadata(other._metadata)
193  {
194  if (_metadata)
195  _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
196  }
197 
198 private:
199 
200  friend class BaseRecord;
201  friend class io::FitsWriter;
202  friend class AliasMap;
203 
204  // Called by BaseRecord ctor to fill in its _data, _table, and _manager members.
205  void _initialize(BaseRecord & record);
206 
207  /*
208  * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
209  *
210  * This could allow the table to reclaim that space, but that requires more bookkeeping than
211  * it's presently worth unless this was the most recently allocated record.
212  *
213  * The motivation for attempting to reclaim even some memory is not because we're paranoid
214  * about using every last bit of allocated memory efficiently - it's so we can keep
215  * records contiguous as much as possible to allow ColumnView to be used.
216  */
217  void _destroy(BaseRecord & record);
218 
219  // Tables are not assignable to prevent type slicing; this is intentionally not implemented,
220  // so we get linker errors if we do try to use the assignment operator.
221  void operator=(BaseTable const & other);
222 
223  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
224  virtual PTR(io::FitsWriter) makeFitsWriter(fits::Fits * fitsfile, int flags) const;
225 
226  // All these are definitely private, not protected - we don't want derived classes mucking with them.
227  Schema _schema; // schema that defines the table's fields
228  ndarray::Manager::Ptr _manager; // current memory block to use for new records
229  PTR(daf::base::PropertyList) _metadata; // flexible metadata; may be null
230 };
231 
232 }}} // namespace lsst::afw::table
233 
234 #endif // !AFW_TABLE_BaseTable_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:44
Column-wise view into a sequence of records that have been allocated contiguously.
Writer object for FITS binary tables.
Definition: FitsWriter.h:22
Citizen(const std::type_info &)
Definition: Citizen.cc:174
void _initialize(BaseRecord &record)
boost::shared_ptr< Derived > getSelf()
Convenience function for static-casting shared_from_this for use by derived classes.
Definition: BaseTable.h:168
void setMetadata(boost::shared_ptr< daf::base::PropertyList > const &metadata)
Set the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:70
static boost::shared_ptr< BaseTable > make(Schema const &schema)
Construct a new table.
A custom container class for records, based on std::vector.
Definition: Catalog.h:95
Class for storing ordered metadata with comments.
Definition: PropertyList.h:82
afw::table::Schema schema
Definition: GaussianPsf.cc:41
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
boost::shared_ptr< daf::base::PropertyList > getMetadata() const
Return the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:67
boost::shared_ptr< BaseTable > clone() const
Return a polymorphic deep copy of the table.
Definition: BaseTable.h:88
Schema getSchema() const
Return the table&#39;s schema.
Definition: BaseTable.h:125
Mapping class that holds aliases for a Schema.
Definition: AliasMap.h:34
BaseRecord Record
The associated record class.
Definition: BaseTable.h:52
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:178
Forward declarations and typedefs for afw::table.
BaseColumnView ColumnView
The associated ColumnView class.
Definition: BaseTable.h:55
void _destroy(BaseRecord &record)
boost::shared_ptr< daf::base::PropertyList > popMetadata()
Return the metadata and set the internal metadata to a null pointer.
Definition: BaseTable.h:73
virtual boost::shared_ptr< BaseTable > _clone() const =0
Clone implementation with noncovariant return types.
virtual boost::shared_ptr< BaseRecord > _makeRecord()=0
Default-construct an associated record (protected implementation).
boost::shared_ptr< daf::base::PropertyList > _metadata
Definition: BaseTable.h:229
Base class for all records.
Definition: BaseRecord.h:27
#define PTR(...)
Definition: base.h:41
std::size_t getBufferSize() const
Return the number of additional records space has been already been allocated for.
boost::shared_ptr< BaseRecord > makeRecord()
Default-construct an associated record.
Definition: BaseTable.h:96
boost::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
metadata input
void preallocate(std::size_t nRecords)
Allocate contiguous space for new records in advance.
static int nRecordsPerBlock
Number of records in each memory block.
Definition: BaseTable.h:64
void operator=(BaseTable const &other)
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:53
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
virtual boost::shared_ptr< io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const
ndarray::Manager::Ptr _manager
Definition: BaseTable.h:228
Basic LSST definitions.
CatalogT< Record > Catalog
Template of CatalogT used to hold records of the associated type.
Definition: BaseTable.h:58
Base class for all tables.
Definition: BaseTable.h:43
CatalogT< Record const > ConstCatalog
Template of CatalogT used to hold const records of the associated type.
Definition: BaseTable.h:61