Loading [MathJax]/extensions/tex2jax.js
LSST Applications g04a91732dc+a777afbe81,g07dc498a13+7e3c5f68a2,g12483e3c20+0145ec33cd,g1409bbee79+7e3c5f68a2,g1a7e361dbc+7e3c5f68a2,g1fd858c14a+9f35e23ec3,g35bb328faa+fcb1d3bbc8,g3ad4f90e5c+0145ec33cd,g3bd4b5ce2c+cbf1bea503,g4e0f332c67+5d362be553,g53246c7159+fcb1d3bbc8,g5477a8d5ce+db04660fe6,g60b5630c4e+0145ec33cd,g623d845a50+0145ec33cd,g6f0c2978f1+3526b51a37,g75b6c65c88+d54b601591,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g8852436030+4639f750a5,g89139ef638+7e3c5f68a2,g9125e01d80+fcb1d3bbc8,g919ac25b3e+6220c5324a,g95236ca021+f7a31438ed,g989de1cb63+7e3c5f68a2,g9f33ca652e+2d6fa11d35,gaaedd4e678+7e3c5f68a2,gabe3b4be73+1e0a283bba,gb1101e3267+4a428ef779,gb4a253aaf5+0122250889,gb58c049af0+f03b321e39,gc99c83e5f0+76d20ab76d,gcf25f946ba+4639f750a5,gd6cbbdb0b4+c8606af20c,gde0f65d7ad+3d8a3b7e46,ge278dab8ac+932305ba37,gf795337580+03b96afe58,gfba249425e+fcb1d3bbc8,w.2025.08
LSST Data Management Base Package
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
151 void preallocate(std::size_t nRecords);
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
218 BaseTable(BaseTable const& other);
219 BaseTable(BaseTable&& other) = delete;
220
221private:
222 friend class BaseRecord;
223 friend class io::FitsWriter;
224 friend class AliasMap;
225
226 // Obtain raw data pointers and their managing objects for a new record.
227 detail::RecordData _makeNewRecordData();
228
229 /*
230 * Called by BaseRecord dtor to notify the table when it is about to be destroyed.
231 *
232 * This could allow the table to reclaim that space, but that requires more bookkeeping than
233 * it's presently worth unless this was the most recently allocated record.
234 *
235 * The motivation for attempting to reclaim even some memory is not because we're paranoid
236 * about using every last bit of allocated memory efficiently - it's so we can keep
237 * records contiguous as much as possible to allow ColumnView to be used.
238 */
239 void _destroy(BaseRecord& record);
240
241 // Return a writer object that knows how to save in FITS format. See also FitsWriter.
242 virtual std::shared_ptr<io::FitsWriter> makeFitsWriter(fits::Fits* fitsfile, int flags) const;
243
244 // All these are definitely private, not protected - we don't want derived classes mucking with them.
245 Schema _schema; // schema that defines the table's fields
246 ndarray::Manager::Ptr _manager; // current memory block to use for new records
247 std::shared_ptr<daf::base::PropertyList> _metadata; // flexible metadata; may be null
248};
249
250} // namespace table
251} // namespace afw
252} // namespace lsst
253
254#endif // !AFW_TABLE_BaseTable_h_INCLUDED
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
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
CatalogT< const Record > ConstCatalog
Template of CatalogT used to hold const records of the associated type.
Definition BaseTable.h:73
virtual std::shared_ptr< BaseRecord > _makeRecord()
Default-construct an associated record (protected implementation).
Definition BaseTable.cc:150
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
CatalogT< Record > Catalog
Template of CatalogT used to hold records of the associated type.
Definition BaseTable.h:70
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
BaseColumnView ColumnView
The associated ColumnView class.
Definition BaseTable.h:67
BaseTable(BaseTable &&other)=delete
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
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:152
std::size_t getBufferSize() const
Return the number of additional records space has been already been allocated for.
Definition BaseTable.cc:112
static Schema makeMinimalSchema()
Return a minimal schema for Base tables and records.
Definition BaseTable.cc:126
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
BaseRecord Record
The associated record class.
Definition BaseTable.h:64
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
A custom container class for records, based on std::vector.
Definition Catalog.h:98
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
T swap(T... args)