LSST Applications g070148d5b3+33e5256705,g0d53e28543+25c8b88941,g0da5cf3356+2dd1178308,g1081da9e2a+62d12e78cb,g17e5ecfddb+7e422d6136,g1c76d35bf8+ede3a706f7,g295839609d+225697d880,g2e2c1a68ba+cc1f6f037e,g2ffcdf413f+853cd4dcde,g38293774b4+62d12e78cb,g3b44f30a73+d953f1ac34,g48ccf36440+885b902d19,g4b2f1765b6+7dedbde6d2,g5320a0a9f6+0c5d6105b6,g56b687f8c9+ede3a706f7,g5c4744a4d9+ef6ac23297,g5ffd174ac0+0c5d6105b6,g6075d09f38+66af417445,g667d525e37+2ced63db88,g670421136f+2ced63db88,g71f27ac40c+2ced63db88,g774830318a+463cbe8d1f,g7876bc68e5+1d137996f1,g7985c39107+62d12e78cb,g7fdac2220c+0fd8241c05,g96f01af41f+368e6903a7,g9ca82378b8+2ced63db88,g9d27549199+ef6ac23297,gabe93b2c52+e3573e3735,gb065e2a02a+3dfbe639da,gbc3249ced9+0c5d6105b6,gbec6a3398f+0c5d6105b6,gc9534b9d65+35b9f25267,gd01420fc67+0c5d6105b6,geee7ff78d7+a14128c129,gf63283c776+ede3a706f7,gfed783d017+0c5d6105b6,w.2022.47
LSST Data Management Base Package
Loading...
Searching...
No Matches
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 "ndarray/Manager.h"
10
11namespace lsst {
12namespace afw {
13
14namespace fits {
15
16class Fits;
17
18} // namespace fits
19
20namespace table {
21
22namespace detail {
23
32struct RecordData {
33 void * data;
35 ndarray::Manager::Ptr manager;
36};
37
38} // namespace detail
39
61class BaseTable : public std::enable_shared_from_this<BaseTable> {
62public:
65
68
71
74
76 static int nRecordsPerBlock;
77
80
82 void setMetadata(std::shared_ptr<daf::base::PropertyList> const& metadata) { _metadata = metadata; }
83
87 _metadata.swap(tmp);
88 return tmp;
89 }
90
101
109
128
135
137 Schema getSchema() const { return _schema; }
138
151 void preallocate(std::size_t nRecords);
152
159
173
179 static Schema makeMinimalSchema();
180
181 // Tables are not assignable to prevent type slicing.
182 BaseTable& operator=(BaseTable const& other) = delete;
183 BaseTable& operator=(BaseTable&& other) = delete;
184
185 virtual ~BaseTable();
186
187protected:
188
203 // n.b. this is implemented in BaseRecord.h, as it requires the BaseRecord
204 // definition, and must go in a header.
205 template <typename RecordT, typename ...Args>
207
208 virtual void handleAliasChange(std::string const& alias) {}
209
211 virtual std::shared_ptr<BaseTable> _clone() const;
212
215
217 explicit BaseTable(Schema const& schema);
218
220 BaseTable(BaseTable const& other) : _schema(other._schema), _metadata(other._metadata) {
221 if (_metadata) _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
222 }
223 // Delegate to copy-constructor for backwards compatibility
224 BaseTable(BaseTable&& other) : BaseTable(other) {}
225
226private:
227 friend class BaseRecord;
228 friend class io::FitsWriter;
229 friend class AliasMap;
230
231 // Obtain raw data pointers and their managing objects for a new record.
232 detail::RecordData _makeNewRecordData();
233
234 /*
235 * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
236 *
237 * This could allow the table to reclaim that space, but that requires more bookkeeping than
238 * it's presently worth unless this was the most recently allocated record.
239 *
240 * The motivation for attempting to reclaim even some memory is not because we're paranoid
241 * about using every last bit of allocated memory efficiently - it's so we can keep
242 * records contiguous as much as possible to allow ColumnView to be used.
243 */
244 void _destroy(BaseRecord& record);
245
246 // Return a writer object that knows how to save in FITS format. See also FitsWriter.
247 virtual std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const;
248
249 // All these are definitely private, not protected - we don't want derived classes mucking with them.
250 Schema _schema; // schema that defines the table's fields
251 ndarray::Manager::Ptr _manager; // current memory block to use for new records
252 std::shared_ptr<daf::base::PropertyList> _metadata; // flexible metadata; may be null
253};
254
255} // namespace table
256} // namespace afw
257} // namespace lsst
258
259#endif // !AFW_TABLE_BaseTable_h_INCLUDED
SchemaMapper * mapper
Definition: SchemaMapper.cc:71
table::Schema schema
Definition: python.h:134
Basic LSST definitions.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:308
Mapping class that holds aliases for a Schema.
Definition: AliasMap.h:36
Column-wise view into a sequence of records that have been allocated contiguously.
Base class for all records.
Definition: BaseRecord.h:31
Base class for all tables.
Definition: BaseTable.h:61
void setMetadata(std::shared_ptr< daf::base::PropertyList > const &metadata)
Set the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:82
virtual std::shared_ptr< BaseRecord > _makeRecord()
Default-construct an associated record (protected implementation).
Definition: BaseTable.cc:148
BaseTable & operator=(BaseTable const &other)=delete
std::shared_ptr< daf::base::PropertyList > popMetadata()
Return the metadata and set the internal metadata to a null pointer.
Definition: BaseTable.h:85
virtual std::shared_ptr< io::FitsWriter > makeFitsWriter(fits::Fits *fitsfile, int flags) const
Definition: BaseTable.cc:140
Schema getSchema() const
Return the table's schema.
Definition: BaseTable.h:137
void preallocate(std::size_t nRecords)
Allocate contiguous space for new records in advance.
Definition: BaseTable.cc:110
std::shared_ptr< RecordT > constructRecord(Args &&...args)
Helper function that must be used by all _makeRecord overrides to actually construct records.
Definition: BaseRecord.h:227
BaseTable & operator=(BaseTable &&other)=delete
std::shared_ptr< daf::base::PropertyList > getMetadata() const
Return the flexible metadata associated with the table. May be null.
Definition: BaseTable.h:79
std::shared_ptr< BaseRecord > copyRecord(BaseRecord const &input)
Deep-copy a record, requiring that it have the same schema as this table.
Definition: BaseTable.cc:128
BaseTable(BaseTable const &other)
Copy construct.
Definition: BaseTable.h:220
std::shared_ptr< BaseTable > clone() const
Return a polymorphic deep copy of the table.
Definition: BaseTable.h:100
std::size_t getBufferSize() const
Return the number of additional records space has been already been allocated for.
Definition: BaseTable.cc:112
BaseTable(BaseTable &&other)
Definition: BaseTable.h:224
static Schema makeMinimalSchema()
Return a minimal schema for Base tables and records.
Definition: BaseTable.cc:124
static int nRecordsPerBlock
Number of records in each memory block.
Definition: BaseTable.h:76
static std::shared_ptr< BaseTable > make(Schema const &schema)
Construct a new table.
Definition: BaseTable.cc:120
virtual void handleAliasChange(std::string const &alias)
Definition: BaseTable.h:208
virtual std::shared_ptr< BaseTable > _clone() const
Clone implementation with noncovariant return types.
Definition: BaseTable.cc:144
std::shared_ptr< BaseRecord > makeRecord()
Default-construct an associated record.
Definition: BaseTable.h:108
Defines the fields and offsets for a table.
Definition: Schema.h:51
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
Helper struct that contains the information passed from BaseTable to BaseRecord at construction.
Definition: BaseTable.h:32
ndarray::Manager::Ptr manager
Definition: BaseTable.h:35
std::shared_ptr< BaseTable > table
Definition: BaseTable.h:34