LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
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
90
101
109
128
135
137 Schema getSchema() const { return _schema; }
138
152
159
172 static std::shared_ptr<BaseTable> make(Schema const& schema);
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:
202 // n.b. this is implemented in BaseRecord.h, as it requires the BaseRecord
203 // definition, and must go in a header.
204 template <typename RecordT, typename... Args>
206
207 virtual void handleAliasChange(std::string const& alias) {}
208
210 virtual std::shared_ptr<BaseTable> _clone() const;
211
214
216 explicit BaseTable(Schema const& schema, std::shared_ptr<daf::base::PropertyList> metadata = nullptr);
217
219 BaseTable(BaseTable const& other) : _schema(other._schema), _metadata(other._metadata) {
220 if (_metadata) _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
221 }
222 // Delegate to copy-constructor for backwards compatibility
223 BaseTable(BaseTable&& other) : BaseTable(other) {}
224
225private:
226 friend class BaseRecord;
227 friend class io::FitsWriter;
228 friend class AliasMap;
229
230 // Obtain raw data pointers and their managing objects for a new record.
231 detail::RecordData _makeNewRecordData();
232
233 /*
234 * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
235 *
236 * This could allow the table to reclaim that space, but that requires more bookkeeping than
237 * it's presently worth unless this was the most recently allocated record.
238 *
239 * The motivation for attempting to reclaim even some memory is not because we're paranoid
240 * about using every last bit of allocated memory efficiently - it's so we can keep
241 * records contiguous as much as possible to allow ColumnView to be used.
242 */
243 void _destroy(BaseRecord& record);
244
245 // Return a writer object that knows how to save in FITS format. See also FitsWriter.
247
248 // All these are definitely private, not protected - we don't want derived classes mucking with them.
249 Schema _schema; // schema that defines the table's fields
250 ndarray::Manager::Ptr _manager; // current memory block to use for new records
251 std::shared_ptr<daf::base::PropertyList> _metadata; // flexible metadata; may be null
252};
253
254} // namespace table
255} // namespace afw
256} // namespace lsst
257
258#endif // !AFW_TABLE_BaseTable_h_INCLUDED
SchemaMapper * mapper
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
Tag types used to declare specialized field types.
Definition misc.h:31
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
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
virtual std::shared_ptr< BaseRecord > _makeRecord()
Default-construct an associated record (protected implementation).
Definition BaseTable.cc:146
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:138
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
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:126
BaseTable(BaseTable const &other)
Copy construct.
Definition BaseTable.h:219
std::shared_ptr< BaseTable > clone() const
Return a polymorphic deep copy of the table.
Definition BaseTable.h:100
BaseTable(Schema const &schema, std::shared_ptr< daf::base::PropertyList > metadata=nullptr)
Construct from a schema.
Definition BaseTable.cc:148
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:223
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:207
virtual std::shared_ptr< BaseTable > _clone() const
Clone implementation with noncovariant return types.
Definition BaseTable.cc:142
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.
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