LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 
5 #include "boost/enable_shared_from_this.hpp"
6 
7 #include "lsst/base.h"
9 #include "ndarray/Manager.h"
10 #include "lsst/afw/table/fwd.h"
11 #include "lsst/afw/table/Schema.h"
12 
13 namespace lsst { namespace afw {
14 
15 namespace fits {
16 
17 class Fits;
18 
19 } // namespace fits
20 
21 namespace table {
22 
44 class BaseTable
45 #ifndef SWIG // swig complains about these not being %shared_ptrs, but it doesn't need to know about them
46 : public boost::enable_shared_from_this<BaseTable>,
47  public daf::base::Citizen
48 #endif
49 {
50 public:
51 
53  typedef BaseRecord Record;
54 
57 
60 
63 
65  static int nRecordsPerBlock;
66 
69 
71  void setMetadata(PTR(daf::base::PropertyList) const & metadata) { _metadata = metadata; }
72 
76  _metadata.swap(tmp);
77  return tmp;
78  }
79 
89  PTR(BaseTable) clone() const { return _clone(); }
90 
98 
116  PTR(BaseRecord) copyRecord(BaseRecord const & input);
117 
123  PTR(BaseRecord) copyRecord(BaseRecord const & input, SchemaMapper const & mapper);
124 
126  Schema getSchema() const { return _schema; }
127 
140  void preallocate(std::size_t nRecords);
141 
147  std::size_t getBufferSize() const;
148 
161  static PTR(BaseTable) make(Schema const & schema);
162 
163  virtual ~BaseTable();
164 
165 protected:
166 
168  template <typename Derived>
169  PTR(Derived) getSelf() {
170  return boost::static_pointer_cast<Derived>(shared_from_this());
171  }
172 
174  template <typename Derived>
175  CONST_PTR(Derived) getSelf() const {
176  return boost::static_pointer_cast<Derived const>(shared_from_this());
177  }
178 
179  virtual void handleAliasChange(std::string const & alias) {}
180 
182  virtual PTR(BaseTable) _clone() const = 0;
183 
185  virtual PTR(BaseRecord) _makeRecord() = 0;
186 
188  explicit BaseTable(Schema const & schema);
189 
191  BaseTable(BaseTable const & other) :
192  daf::base::Citizen(other), _schema(other._schema),
193  _metadata(other._metadata)
194  {
195  if (_metadata)
196  _metadata = boost::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
197  }
198 
199 private:
200 
201  friend class BaseRecord;
202  friend class io::FitsWriter;
203  friend class AliasMap;
204 
205  // Called by BaseRecord ctor to fill in its _data, _table, and _manager members.
206  void _initialize(BaseRecord & record);
207 
208  /*
209  * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
210  *
211  * This could allow the table to reclaim that space, but that requires more bookkeeping than
212  * it's presently worth unless this was the most recently allocated record.
213  *
214  * The motivation for attempting to reclaim even some memory is not because we're paranoid
215  * about using every last bit of allocated memory efficiently - it's so we can keep
216  * records contiguous as much as possible to allow ColumnView to be used.
217  */
218  void _destroy(BaseRecord & record);
219 
220  // Tables are not assignable to prevent type slicing; this is intentionally not implemented,
221  // so we get linker errors if we do try to use the assignment operator.
222  void operator=(BaseTable const & other);
223 
224  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
225  virtual PTR(io::FitsWriter) makeFitsWriter(fits::Fits * fitsfile, int flags) const;
226 
227  // All these are definitely private, not protected - we don't want derived classes mucking with them.
228  Schema _schema; // schema that defines the table's fields
229  ndarray::Manager::Ptr _manager; // current memory block to use for new records
230  PTR(daf::base::PropertyList) _metadata; // flexible metadata; may be null
231 };
232 
233 }}} // namespace lsst::afw::table
234 
235 #endif // !AFW_TABLE_BaseTable_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:46
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:53
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:94
Class for storing ordered metadata with comments.
Definition: PropertyList.h:81
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:56
Mapping class that holds aliases for a Schema.
Definition: AliasMap.h:34
#define PTR(...)
Definition: base.h:41
Definition of Manager, which manages the ownership of array data.
boost::shared_ptr< daf::base::PropertyList > popMetadata()
Return the metadata and set the internal metadata to a null pointer.
Definition: BaseTable.h:74
static boost::shared_ptr< BaseTable > make(Schema const &schema)
Construct a new table.
ndarray::Manager::Ptr _manager
Definition: BaseTable.h:229
boost::shared_ptr< BaseTable > clone() const
Return a polymorphic deep copy of the table.
Definition: BaseTable.h:89
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:97
static int nRecordsPerBlock
Number of records in each memory block.
Definition: BaseTable.h:65
CatalogT< Record const > ConstCatalog
Template of CatalogT used to hold const records of the associated type.
Definition: BaseTable.h:62
CatalogT< Record > Catalog
Template of CatalogT used to hold records of the associated type.
Definition: BaseTable.h:59
void setMetadata(boost::shared_ptr< daf::base::PropertyList > const &metadata)
Set the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:71
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:173
virtual boost::shared_ptr< BaseRecord > _makeRecord()=0
Default-construct an associated record (protected implementation).
Schema getSchema() const
Return the table&#39;s schema.
Definition: BaseTable.h:126
#define CONST_PTR(...)
Definition: base.h:47
boost::shared_ptr< Derived > getSelf()
Convenience function for static-casting shared_from_this for use by derived classes.
Definition: BaseTable.h:169
void operator=(BaseTable const &other)
boost::shared_ptr< daf::base::PropertyList > _metadata
Definition: BaseTable.h:230
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
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:68
Base class for all tables.
Definition: BaseTable.h:44
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:179