LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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  int getVersion() const { return _schema.getVersion(); }
127 
129  Schema getSchema() const { return _schema; }
130 
143  void preallocate(std::size_t nRecords);
144 
150  std::size_t getBufferSize() const;
151 
164  static PTR(BaseTable) make(Schema const & schema);
165 
166  virtual ~BaseTable();
167 
168 protected:
169 
171  template <typename Derived>
172  PTR(Derived) getSelf() {
173  return boost::static_pointer_cast<Derived>(shared_from_this());
174  }
175 
177  template <typename Derived>
178  CONST_PTR(Derived) getSelf() const {
179  return boost::static_pointer_cast<Derived const>(shared_from_this());
180  }
181 
182  virtual void handleAliasChange(std::string const & alias) {}
183 
185  virtual PTR(BaseTable) _clone() const = 0;
186 
188  virtual PTR(BaseRecord) _makeRecord() = 0;
189 
191  explicit BaseTable(Schema const & schema);
192 
194  BaseTable(BaseTable const & other) :
195  daf::base::Citizen(other), _schema(other._schema),
196  _metadata(other._metadata)
197  {
198  if (_metadata)
199  _metadata = boost::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
200  }
201 
202 private:
203 
204  friend class BaseRecord;
205  friend class io::FitsWriter;
206  friend class AliasMap;
207 
208  // Called by BaseRecord ctor to fill in its _data, _table, and _manager members.
209  void _initialize(BaseRecord & record);
210 
211  /*
212  * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
213  *
214  * This could allow the table to reclaim that space, but that requires more bookkeeping than
215  * it's presently worth unless this was the most recently allocated record.
216  *
217  * The motivation for attempting to reclaim even some memory is not because we're paranoid
218  * about using every last bit of allocated memory efficiently - it's so we can keep
219  * records contiguous as much as possible to allow ColumnView to be used.
220  */
221  void _destroy(BaseRecord & record);
222 
223  // Tables are not assignable to prevent type slicing; this is intentionally not implemented,
224  // so we get linker errors if we do try to use the assignment operator.
225  void operator=(BaseTable const & other);
226 
227  // Return a writer object that knows how to save in FITS format. See also FitsWriter.
228  virtual PTR(io::FitsWriter) makeFitsWriter(fits::Fits * fitsfile, int flags) const;
229 
230  // All these are definitely private, not protected - we don't want derived classes mucking with them.
231  Schema _schema; // schema that defines the table's fields
232  ndarray::Manager::Ptr _manager; // current memory block to use for new records
233  PTR(daf::base::PropertyList) _metadata; // flexible metadata; may be null
234 };
235 
236 }}} // namespace lsst::afw::table
237 
238 #endif // !AFW_TABLE_BaseTable_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:46
int getVersion() const
Return the table&#39;s version.
Definition: Schema.h:322
#define CONST_PTR(...)
Definition: base.h:47
Column-wise view into a sequence of records that have been allocated contiguously.
Writer subclass for FITS binary tables.
Definition: FitsWriter.h:20
boost::shared_ptr< BaseRecord > makeRecord()
Default-construct an associated record.
Definition: BaseTable.h:97
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
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:68
boost::shared_ptr< Derived > getSelf()
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:34
void _initialize(BaseRecord &record)
Definition of Manager, which manages the ownership of array data.
virtual boost::shared_ptr< BaseTable > _clone() const =0
Clone implementation with noncovariant return types.
#define PTR(...)
Definition: base.h:41
void _destroy(BaseRecord &record)
BaseRecord Record
The associated record class.
Definition: BaseTable.h:53
virtual boost::shared_ptr< BaseRecord > _makeRecord()=0
Default-construct an associated record (protected implementation).
CatalogT< Record const > ConstCatalog
Template of CatalogT used to hold const records of the associated type.
Definition: BaseTable.h:62
static boost::shared_ptr< BaseTable > make(Schema const &schema)
Construct a new table.
CatalogT< Record > Catalog
Template of CatalogT used to hold records of the associated type.
Definition: BaseTable.h:59
void preallocate(std::size_t nRecords)
Allocate contiguous space for new records in advance.
boost::shared_ptr< BaseTable > clone() const
Return a polymorphic deep copy of the table.
Definition: BaseTable.h:89
tbl::Schema schema
Definition: CoaddPsf.cc:324
virtual boost::shared_ptr< io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const
Citizen(const std::type_info &)
Definition: Citizen.cc:173
BaseColumnView ColumnView
The associated ColumnView class.
Definition: BaseTable.h:56
static int nRecordsPerBlock
Number of records in each memory block.
Definition: BaseTable.h:65
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
boost::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
boost::shared_ptr< daf::base::PropertyList > popMetadata()
Return the metadata and set the internal metadata to a null pointer.
Definition: BaseTable.h:74
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:182
std::size_t getBufferSize() const
Return the number of additional records space has been already been allocated for.
int getVersion() const
Return the table&#39;s version.
Definition: BaseTable.h:126
boost::shared_ptr< daf::base::PropertyList > _metadata
Definition: BaseTable.h:233
ndarray::Manager::Ptr _manager
Definition: BaseTable.h:232
Base class for all records.
Definition: BaseRecord.h:27
Schema getSchema() const
Return the table&#39;s schema.
Definition: BaseTable.h:129
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:56
Base class for all tables.
Definition: BaseTable.h:44