LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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 
115  PTR(BaseRecord) copyRecord(BaseRecord const & input);
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
boost::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
BaseRecord Record
The associated record class.
Definition: BaseTable.h:52
virtual boost::shared_ptr< io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const
Column-wise view into a sequence of records that have been allocated contiguously.
Writer object for FITS binary tables.
Definition: FitsWriter.h:22
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
BaseColumnView ColumnView
The associated ColumnView class.
Definition: BaseTable.h:55
Mapping class that holds aliases for a Schema.
Definition: AliasMap.h:34
boost::shared_ptr< daf::base::PropertyList > popMetadata()
Return the metadata and set the internal metadata to a null pointer.
Definition: BaseTable.h:73
#define CONST_PTR(...)
Definition: base.h:47
static boost::shared_ptr< BaseTable > make(Schema const &schema)
Construct a new table.
ndarray::Manager::Ptr _manager
Definition: BaseTable.h:228
boost::shared_ptr< BaseTable > clone() const
Return a polymorphic deep copy of the table.
Definition: BaseTable.h:88
void _destroy(BaseRecord &record)
void preallocate(std::size_t nRecords)
Allocate contiguous space for new records in advance.
boost::shared_ptr< BaseRecord > makeRecord()
Default-construct an associated record.
Definition: BaseTable.h:96
static int nRecordsPerBlock
Number of records in each memory block.
Definition: BaseTable.h:64
CatalogT< Record const > ConstCatalog
Template of CatalogT used to hold const records of the associated type.
Definition: BaseTable.h:61
CatalogT< Record > Catalog
Template of CatalogT used to hold records of the associated type.
Definition: BaseTable.h:58
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
void _initialize(BaseRecord &record)
Base class for all records.
Definition: BaseRecord.h:27
virtual boost::shared_ptr< BaseTable > _clone() const =0
Clone implementation with noncovariant return types.
Citizen(const std::type_info &)
Definition: Citizen.cc:174
virtual boost::shared_ptr< BaseRecord > _makeRecord()=0
Default-construct an associated record (protected implementation).
#define PTR(...)
Definition: base.h:41
Schema getSchema() const
Return the table&#39;s schema.
Definition: BaseTable.h:125
boost::shared_ptr< Derived > getSelf()
Convenience function for static-casting shared_from_this for use by derived classes.
Definition: BaseTable.h:168
void operator=(BaseTable const &other)
boost::shared_ptr< daf::base::PropertyList > _metadata
Definition: BaseTable.h:229
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:53
std::size_t getBufferSize() const
Return the number of additional records space has been already been allocated for.
boost::shared_ptr< daf::base::PropertyList > getMetadata() const
Return the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:67
Base class for all tables.
Definition: BaseTable.h:43
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:178