LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
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
Fits * fits
Definition: FitsWriter.cc:90
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:297
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
BaseTable(Schema const &schema)
Construct from a schema.
Definition: BaseTable.cc:152
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
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.
Definition: SchemaMapper.h:21
Writer object for FITS binary tables.
Definition: FitsWriter.h:25
A base class for image defects.
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