LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Friends | List of all members
lsst::afw::table::BaseTable Class Reference

Base class for all tables. More...

#include <BaseTable.h>

Inheritance diagram for lsst::afw::table::BaseTable:
std::enable_shared_from_this< BaseTable > lsst::afw::detection::PeakTable lsst::afw::table::ExposureTable lsst::afw::table::SimpleTable lsst::afw::table::SourceTable

Public Types

using Record = BaseRecord
 The associated record class. More...
 
using ColumnView = BaseColumnView
 The associated ColumnView class. More...
 
using Catalog = CatalogT< Record >
 Template of CatalogT used to hold records of the associated type. More...
 
using ConstCatalog = CatalogT< const Record >
 Template of CatalogT used to hold const records of the associated type. More...
 

Public Member Functions

std::shared_ptr< daf::base::PropertyListgetMetadata () const
 Return the flexible metadata associated with the table. May be null. More...
 
void setMetadata (std::shared_ptr< daf::base::PropertyList > const &metadata)
 Set the flexible metadata associated with the table. May be null. More...
 
std::shared_ptr< daf::base::PropertyListpopMetadata ()
 Return the metadata and set the internal metadata to a null pointer. More...
 
std::shared_ptr< BaseTableclone () const
 Return a polymorphic deep copy of the table. More...
 
std::shared_ptr< BaseRecordmakeRecord ()
 Default-construct an associated record. More...
 
std::shared_ptr< BaseRecordcopyRecord (BaseRecord const &input)
 Deep-copy a record, requiring that it have the same schema as this table. More...
 
std::shared_ptr< BaseRecordcopyRecord (BaseRecord const &input, SchemaMapper const &mapper)
 Deep-copy a record, using a mapper to relate two schemas. More...
 
Schema getSchema () const
 Return the table's schema. More...
 
void preallocate (std::size_t nRecords)
 Allocate contiguous space for new records in advance. More...
 
std::size_t getBufferSize () const
 Return the number of additional records space has been already been allocated for. More...
 
BaseTableoperator= (BaseTable const &other)=delete
 
BaseTableoperator= (BaseTable &&other)=delete
 
virtual ~BaseTable ()
 
shared_from_this (T... args)
 

Static Public Member Functions

static std::shared_ptr< BaseTablemake (Schema const &schema)
 Construct a new table. More...
 
static Schema makeMinimalSchema ()
 Return a minimal schema for Base tables and records. More...
 

Static Public Attributes

static int nRecordsPerBlock = 100
 Number of records in each memory block. More...
 

Protected Member Functions

template<typename RecordT , typename ... Args>
std::shared_ptr< RecordT > constructRecord (Args &&...args)
 Helper function that must be used by all _makeRecord overrides to actually construct records. More...
 
virtual void handleAliasChange (std::string const &alias)
 
virtual std::shared_ptr< BaseTable_clone () const
 Clone implementation with noncovariant return types. More...
 
virtual std::shared_ptr< BaseRecord_makeRecord ()
 Default-construct an associated record (protected implementation). More...
 
 BaseTable (Schema const &schema)
 Construct from a schema. More...
 
 BaseTable (BaseTable const &other)
 Copy construct. More...
 
 BaseTable (BaseTable &&other)
 

Private Member Functions

virtual std::shared_ptr< io::FitsWritermakeFitsWriter (fits::Fits *fitsfile, int flags) const
 

Friends

class BaseRecord
 
class io::FitsWriter
 
class AliasMap
 

Detailed Description

Base class for all tables.

Tables have two largely distinct purposes:

It's mostly a matter of convenience that we use the same class to serve both needs.

Tables do not actually maintain a list of all the records they have allocated - but those records hold a pointer back to the table. This allows the work of holding and iterating over records to be delegated to templated container classes (such as CatalogT) while allowing tables to be polymorphic, non-template classes. In some sense, then, it may make more sense to think of a table as a combination factory and "container header".

Tables are always created in shared_ptrs (a requirement of enable_shared_from_this). BaseTable provides a make static member function to create a new table, and most derived table classes should do the same.

Each table class should be associated with a particular record class (1-to-1). Each table instance may be associated with many record instances.

Definition at line 61 of file BaseTable.h.

Member Typedef Documentation

◆ Catalog

Template of CatalogT used to hold records of the associated type.

Definition at line 70 of file BaseTable.h.

◆ ColumnView

The associated ColumnView class.

Definition at line 67 of file BaseTable.h.

◆ ConstCatalog

Template of CatalogT used to hold const records of the associated type.

Definition at line 73 of file BaseTable.h.

◆ Record

The associated record class.

Definition at line 64 of file BaseTable.h.

Constructor & Destructor Documentation

◆ ~BaseTable()

lsst::afw::table::BaseTable::~BaseTable ( )
virtual

Definition at line 158 of file BaseTable.cc.

158 { _schema.getAliasMap()->_table = nullptr; }
std::shared_ptr< AliasMap > getAliasMap() const
Return the map of aliases.
Definition: Schema.h:279

◆ BaseTable() [1/3]

lsst::afw::table::BaseTable::BaseTable ( Schema const &  schema)
explicitprotected

Construct from a schema.

Definition at line 152 of file BaseTable.cc.

152  : _schema(schema) {
153  Block::padSchema(_schema);
154  _schema.disconnectAliases();
155  _schema.getAliasMap()->_table = this;
156 }
table::Schema schema
Definition: python.h:134
void disconnectAliases()
Sever the connection between this schema and any others with which it shares aliases.
Definition: Schema.cc:540

◆ BaseTable() [2/3]

lsst::afw::table::BaseTable::BaseTable ( BaseTable const &  other)
inlineprotected

Copy construct.

Definition at line 220 of file BaseTable.h.

220  : _schema(other._schema), _metadata(other._metadata) {
221  if (_metadata) _metadata = std::static_pointer_cast<daf::base::PropertyList>(_metadata->deepCopy());
222  }

◆ BaseTable() [3/3]

lsst::afw::table::BaseTable::BaseTable ( BaseTable &&  other)
inlineprotected

Definition at line 224 of file BaseTable.h.

224 : BaseTable(other) {}
BaseTable(Schema const &schema)
Construct from a schema.
Definition: BaseTable.cc:152

Member Function Documentation

◆ _clone()

std::shared_ptr< BaseTable > lsst::afw::table::BaseTable::_clone ( ) const
protectedvirtual

Clone implementation with noncovariant return types.

Reimplemented in lsst::afw::table::SourceTable, lsst::afw::table::SimpleTable, lsst::afw::table::ExposureTable, and lsst::afw::detection::PeakTable.

Definition at line 144 of file BaseTable.cc.

144  {
145  return std::shared_ptr<BaseTable>(new BaseTable(*this));
146 }

◆ _makeRecord()

std::shared_ptr< BaseRecord > lsst::afw::table::BaseTable::_makeRecord ( )
protectedvirtual

Default-construct an associated record (protected implementation).

Reimplemented in lsst::afw::table::SourceTable, lsst::afw::table::SimpleTable, lsst::afw::table::ExposureTable, and lsst::afw::detection::PeakTable.

Definition at line 148 of file BaseTable.cc.

148  {
149  return constructRecord<BaseRecord>();
150 }

◆ clone()

std::shared_ptr<BaseTable> lsst::afw::table::BaseTable::clone ( ) const
inline

Return a polymorphic deep copy of the table.

Derived classes should reimplement by static-casting the output of _clone to a pointer-to-derived to simulate covariant return types.

Cloning a table does not clone its associated records; the new table produced by clone() does not have any associated records.

Definition at line 100 of file BaseTable.h.

100 { return _clone(); }
virtual std::shared_ptr< BaseTable > _clone() const
Clone implementation with noncovariant return types.
Definition: BaseTable.cc:144

◆ constructRecord()

template<typename RecordT , typename ... Args>
std::shared_ptr< RecordT > lsst::afw::table::BaseTable::constructRecord ( Args &&...  args)
protected

Helper function that must be used by all _makeRecord overrides to actually construct records.

Use of this function is enforced by the fact that Record::ConstructionToken can only be created by BaseTable, and is only ever constructed inside this method.

This function expects Record subclasses to have a constructor signature of the form

Record(ConstructionToken const &, detail::RecordData &&, Args && ...);

Definition at line 227 of file BaseRecord.h.

227  {
228  return std::make_shared<RecordT>(BaseRecord::ConstructionToken(0), _makeNewRecordData(),
229  std::forward<Args>(args)...);
230 }

◆ copyRecord() [1/2]

std::shared_ptr< BaseRecord > lsst::afw::table::BaseTable::copyRecord ( BaseRecord const &  input)

Deep-copy a record, requiring that it have the same schema as this table.

Regardless of the type or associated table of the input record, the type of the output record will be the type associated with this table and the record instance will be associated with this table.

Allowing derived-class records to be constructed from base-class records could be considered a form of type-slicing, but because we already demand that all records be constructable from nothing but a table, this isn't anything new.

Derived classes should reimplement by static-casting the output of BaseTable::copyRecord to the appropriate BaseRecord subclass.

This is implemented using makeRecord and calling record.assign on the results; override those to change the behavior.

Definition at line 128 of file BaseTable.cc.

128  {
130  output->assign(input);
131  return output;
132 }
std::shared_ptr< BaseRecord > makeRecord()
Default-construct an associated record.
Definition: BaseTable.h:108

◆ copyRecord() [2/2]

std::shared_ptr< BaseRecord > lsst::afw::table::BaseTable::copyRecord ( BaseRecord const &  input,
SchemaMapper const &  mapper 
)

Deep-copy a record, using a mapper to relate two schemas.

Regardless of the type or associated table of the input record, the type of the output record will be the type associated with this table and the record instance will be associated with this table.

Allowing derived-class records to be constructed from base-class records could be considered a form of type-slicing, but because we already demand that all records be constructable from nothing but a table, this isn't anything new.

Derived classes should reimplement by static-casting the output of BaseTable::copyRecord to the appropriate BaseRecord subclass.

This is implemented using makeRecord and calling record.assign on the results; override those to change the behavior.

Definition at line 134 of file BaseTable.cc.

134  {
136  output->assign(input, mapper);
137  return output;
138 }
SchemaMapper * mapper
Definition: SchemaMapper.cc:71

◆ getBufferSize()

std::size_t lsst::afw::table::BaseTable::getBufferSize ( ) const

Return the number of additional records space has been already been allocated for.

Unlike std::vector::capacity, this does not factor in existing records in any way.

Definition at line 112 of file BaseTable.cc.

112  {
113  if (_manager) {
114  return Block::getBufferSize(_schema.getRecordSize(), _manager);
115  } else {
116  return 0;
117  }
118 }
std::size_t getRecordSize() const
Return the raw size of a record in bytes.
Definition: Schema.h:149

◆ getMetadata()

std::shared_ptr<daf::base::PropertyList> lsst::afw::table::BaseTable::getMetadata ( ) const
inline

Return the flexible metadata associated with the table. May be null.

Definition at line 79 of file BaseTable.h.

79 { return _metadata; }

◆ getSchema()

Schema lsst::afw::table::BaseTable::getSchema ( ) const
inline

Return the table's schema.

Definition at line 137 of file BaseTable.h.

137 { return _schema; }

◆ handleAliasChange()

virtual void lsst::afw::table::BaseTable::handleAliasChange ( std::string const &  alias)
inlineprotectedvirtual

Reimplemented in lsst::afw::table::SourceTable.

Definition at line 208 of file BaseTable.h.

208 {}

◆ make()

std::shared_ptr< BaseTable > lsst::afw::table::BaseTable::make ( Schema const &  schema)
static

Construct a new table.

Because BaseTable is an abstract class, this actually returns a hidden trivial subclass (which is associated with a hidden trivial subclass of BaseRecord).

Hiding concrete table and record classes in anonymous namespaces is not required, but it makes it easier to ensure instances are always created within shared_ptrs, and it eliminates some multilateral friending that would otherwise be necessary. In some cases it may also serve as a form of pimpl, keeping class implementation details out of header files.

Definition at line 120 of file BaseTable.cc.

120  {
122 }

◆ makeFitsWriter()

std::shared_ptr< io::FitsWriter > lsst::afw::table::BaseTable::makeFitsWriter ( fits::Fits fitsfile,
int  flags 
) const
privatevirtual

Definition at line 140 of file BaseTable.cc.

140  {
141  return std::make_shared<io::FitsWriter>(fitsfile, flags);
142 }

◆ makeMinimalSchema()

Schema lsst::afw::table::BaseTable::makeMinimalSchema ( )
static

Return a minimal schema for Base tables and records.

The returned empty schema can and generally should be modified further.

Definition at line 124 of file BaseTable.cc.

124  {
125  return Schema();
126 }

◆ makeRecord()

std::shared_ptr<BaseRecord> lsst::afw::table::BaseTable::makeRecord ( )
inline

Default-construct an associated record.

Derived classes should reimplement by static-casting the output of _makeRecord to the appropriate BaseRecord subclass to simulate covariant return types.

Definition at line 108 of file BaseTable.h.

108 { return _makeRecord(); }
virtual std::shared_ptr< BaseRecord > _makeRecord()
Default-construct an associated record (protected implementation).
Definition: BaseTable.cc:148

◆ operator=() [1/2]

BaseTable& lsst::afw::table::BaseTable::operator= ( BaseTable &&  other)
delete

◆ operator=() [2/2]

BaseTable& lsst::afw::table::BaseTable::operator= ( BaseTable const &  other)
delete

◆ popMetadata()

std::shared_ptr<daf::base::PropertyList> lsst::afw::table::BaseTable::popMetadata ( )
inline

Return the metadata and set the internal metadata to a null pointer.

Definition at line 85 of file BaseTable.h.

85  {
87  _metadata.swap(tmp);
88  return tmp;
89  }

◆ preallocate()

void lsst::afw::table::BaseTable::preallocate ( std::size_t  nRecords)

Allocate contiguous space for new records in advance.

If a contiguous memory block for at least n additional records has already been allocated, this is a no-op. If not, a new block will be allocated, and any remaining space on the old block will go to waste; this ensures the new records will be allocated contiguously. Note that "wasted" memory is not leaked; it will be deallocated along with any records created from that block when those records go out of scope.

Note that unlike std::vector::reserve, this does not factor in existing records in any way; nRecords refers to a number of new records to reserve space for.

Definition at line 110 of file BaseTable.cc.

110 { Block::preallocate(_schema.getRecordSize(), n, _manager); }

◆ setMetadata()

void lsst::afw::table::BaseTable::setMetadata ( std::shared_ptr< daf::base::PropertyList > const &  metadata)
inline

Set the flexible metadata associated with the table. May be null.

Definition at line 82 of file BaseTable.h.

82 { _metadata = metadata; }

Friends And Related Function Documentation

◆ AliasMap

friend class AliasMap
friend

Definition at line 229 of file BaseTable.h.

◆ BaseRecord

friend class BaseRecord
friend

Definition at line 227 of file BaseTable.h.

◆ io::FitsWriter

friend class io::FitsWriter
friend

Definition at line 228 of file BaseTable.h.

Member Data Documentation

◆ nRecordsPerBlock

int lsst::afw::table::BaseTable::nRecordsPerBlock = 100
static

Number of records in each memory block.

Definition at line 76 of file BaseTable.h.


The documentation for this class was generated from the following files: