LSST Applications g1cfbe01172+01aa18f939,g20cdd03214+31e6b93548,g28da252d5a+ea8665a95b,g2bbee38e9b+9ec6cc348d,g2bc492864f+9ec6cc348d,g347aa1857d+9ec6cc348d,g3a166c0a6a+9ec6cc348d,g4322eb9e3a+65eff1e020,g461a3dce89+b86e4b8053,g50ff169b8f+f991eae79d,g52b1c1532d+b86e4b8053,g607f77f49a+31e6b93548,g78056777b3+8ae2798781,g858d7b2824+31e6b93548,g8cd86fa7b1+4851e61ca4,g9ddcbc5298+f24b38b85a,ga1e77700b3+3309dba821,gae0086650b+b86e4b8053,gb0e22166c9+6076c0b52b,gbb886bcc26+dccb771098,gbd462c55f0+dc07f8e65d,gc0c51c7ec2+31e6b93548,gc120e1dc64+a417ce3171,gc28159a63d+9ec6cc348d,gc2a6998b7e+f95f64aeae,gcdd4ae20e8+507450c4cd,gcf0d15dbbd+507450c4cd,gd1535ee943+bcf88ba65f,gd598c5cd71+66126f91fb,gdaeeff99f8+006e14e809,gdbce86181e+39d5515b1a,ge3d4d395c2+b12d4d6a95,ge79ae78c31+9ec6cc348d,gf048a9a2f4+d9c36e6b63,gfbcc870c63+ea41c4420b,w.2024.27
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Member Functions | Friends | List of all members
lsst::afw::table::BaseRecord Class Reference

Base class for all records. More...

#include <BaseRecord.h>

Inheritance diagram for lsst::afw::table::BaseRecord:
lsst::afw::detection::PeakRecord lsst::afw::table::ExposureRecord lsst::afw::table::SimpleRecord lsst::afw::table::SourceRecord

Classes

class  ConstructionToken
 

Public Types

using Table = BaseTable
 The associated table class.
 
using ColumnView = BaseColumnView
 The associated ColumnView class.
 
using Catalog = CatalogT<BaseRecord>
 Template of CatalogT used to hold records of this type.
 
using ConstCatalog = CatalogT<const BaseRecord>
 Template of CatalogT used to hold const records of this type.
 

Public Member Functions

 BaseRecord (ConstructionToken const &, detail::RecordData &&data)
 Construct a record with uninitialized data.
 
 BaseRecord (const BaseRecord &)=delete
 
BaseRecordoperator= (const BaseRecord &)=delete
 
 BaseRecord (BaseRecord &&)=delete
 
BaseRecordoperator= (BaseRecord &&)=delete
 
Schema getSchema () const
 Return the Schema that holds this record's fields and keys.
 
std::shared_ptr< BaseTable constgetTable () const
 Return the table this record is associated with.
 
template<typename T >
Field< T >::Element * getElement (Key< T > const &key)
 Return a pointer to the underlying elements of a field (non-const).
 
template<typename T >
Field< T >::Element constgetElement (Key< T > const &key) const
 Return a pointer to the underlying elements of a field (const).
 
template<typename T >
Field< T >::Reference operator[] (Key< T > const &key)
 Return a reference (or reference-like type) to the field's value.
 
template<typename T >
Field< T >::ConstReference operator[] (Key< T > const &key) const
 Return a const reference (or const-reference-like type) to the field's value.
 
template<typename T >
Field< T >::Value get (Key< T > const &key) const
 Return the value of a field for the given key.
 
template<typename T , typename U >
void set (Key< T > const &key, U const &value)
 Set value of a field for the given key.
 
template<typename T >
get (OutputFunctorKey< T > const &key) const
 Compute a calculated or aggregate field.
 
template<typename T , typename U >
void set (InputFunctorKey< T > const &key, U const &value)
 Set a calculated or aggregate field.
 
template<typename Ref >
Ref operator[] (ReferenceFunctorKey< Ref > const &key)
 
template<typename ConstRef >
ConstRef operator[] (ConstReferenceFunctorKey< ConstRef > const &key) const
 
void assign (BaseRecord const &other)
 Copy all field values from other to this, requiring that they have equal schemas.
 
void assign (BaseRecord const &other, SchemaMapper const &mapper)
 Copy field values from other to this, using a mapper.
 
ndarray::Manager::Ptr getManager () const
 
virtual ~BaseRecord ()
 

Protected Member Functions

virtual void _assign (BaseRecord const &other)
 Called by assign() after transferring fields to allow subclass data members to be copied.
 
virtual void _stream (std::ostream &os) const
 Called by operator<<.
 

Friends

class BaseTable
 
class BaseColumnView
 
std::ostreamoperator<< (std::ostream &os, BaseRecord const &record)
 Write the record's content out, one field on each line.
 

Detailed Description

Base class for all records.

BaseRecord is a polymorphic base class that provides the core record interface: access to fields and links back to the table it is associated with. Field access is provided by the templated get, set, and operator[] member functions. As templates they are nonvirtual and cannot be overridden by subclasses. The implementations for these accessors is in the FieldBase template specializations.

Each subclass of BaseRecord should be paired with a subclass of BaseTable. All record creation goes through a table, as the table allocates the memory used to store a record's fields and holds the Schema instance that defines those fields.

Records are noncopyable, and are hence usually passed by shared_ptr or [const-]reference.

Definition at line 31 of file BaseRecord.h.

Member Typedef Documentation

◆ Catalog

Template of CatalogT used to hold records of this type.

Definition at line 74 of file BaseRecord.h.

◆ ColumnView

The associated ColumnView class.

Definition at line 71 of file BaseRecord.h.

◆ ConstCatalog

Template of CatalogT used to hold const records of this type.

Definition at line 77 of file BaseRecord.h.

◆ Table

The associated table class.

Definition at line 68 of file BaseRecord.h.

Constructor & Destructor Documentation

◆ BaseRecord() [1/3]

lsst::afw::table::BaseRecord::BaseRecord ( ConstructionToken const & ,
detail::RecordData && data )

Construct a record with uninitialized data.

Access to this constructor is restricted to BaseTable and BaseRecord subclasses via the ConstructionToken argument, which can only be constructed by BaseTable. This constructor is public so it can still be called by std::make_shared code with access to ConstructionToken.

Definition at line 143 of file BaseRecord.cc.

143 :
144 _data(std::move(data.data)),
145 _table(std::move(data.table)),
146 _manager(std::move(data.manager))
147{
148 RecordInitializer f = {reinterpret_cast<char *>(_data)};
149 _table->getSchema().forEach(f);
150}
char * data
Definition BaseRecord.cc:61
T move(T... args)

◆ BaseRecord() [2/3]

lsst::afw::table::BaseRecord::BaseRecord ( const BaseRecord & )
delete

◆ BaseRecord() [3/3]

lsst::afw::table::BaseRecord::BaseRecord ( BaseRecord && )
delete

◆ ~BaseRecord()

virtual lsst::afw::table::BaseRecord::~BaseRecord ( )
inlinevirtual

Definition at line 202 of file BaseRecord.h.

202{ _table->_destroy(*this); }

Member Function Documentation

◆ _assign()

virtual void lsst::afw::table::BaseRecord::_assign ( BaseRecord const & other)
inlineprotectedvirtual

Called by assign() after transferring fields to allow subclass data members to be copied.

Reimplemented in lsst::afw::table::SourceRecord, and lsst::afw::table::ExposureRecord.

Definition at line 209 of file BaseRecord.h.

209{}

◆ _stream()

void lsst::afw::table::BaseRecord::_stream ( std::ostream & os) const
protectedvirtual

Called by operator<<.

Overrides should call the base class implementation and append additional fields on new lines, with the syntax "%(name)s: %(value)s".

Definition at line 152 of file BaseRecord.cc.

152 {
153 getSchema().forEach([&os, this](auto const& item) {
154 os << item.field.getName() << ": " << this->get(item.key) << std::endl;
155 });
156}
Field< T >::Value get(Key< T > const &key) const
Return the value of a field for the given key.
Definition BaseRecord.h:151
Schema getSchema() const
Return the Schema that holds this record's fields and keys.
Definition BaseRecord.h:80
void forEach(F &func) const
Apply a functor to each SchemaItem in the Schema.
Definition Schema.h:214
T endl(T... args)

◆ assign() [1/2]

void lsst::afw::table::BaseRecord::assign ( BaseRecord const & other)

Copy all field values from other to this, requiring that they have equal schemas.

Definition at line 122 of file BaseRecord.cc.

122 {
123 if (this->getSchema() != other.getSchema()) {
124 throw LSST_EXCEPT(lsst::pex::exceptions::LogicError, "Unequal schemas in record assignment.");
125 }
126 this->getSchema().forEach(CopyValue(&other, this));
127 this->_assign(other); // let derived classes assign their own stuff
128}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
virtual void _assign(BaseRecord const &other)
Called by assign() after transferring fields to allow subclass data members to be copied.
Definition BaseRecord.h:209
Reports errors in the logical structure of the program.
Definition Runtime.h:46

◆ assign() [2/2]

void lsst::afw::table::BaseRecord::assign ( BaseRecord const & other,
SchemaMapper const & mapper )

Copy field values from other to this, using a mapper.

Definition at line 130 of file BaseRecord.cc.

130 {
131 if (!other.getSchema().contains(mapper.getInputSchema())) {
133 "Unequal schemas between input record and mapper.");
134 }
135 if (!this->getSchema().contains(mapper.getOutputSchema())) {
137 "Unequal schemas between output record and mapper.");
138 }
139 mapper.forEach(CopyValue(&other, this)); // use the functor we defined above
140 this->_assign(other); // let derived classes assign their own stuff
141}
SchemaMapper * mapper

◆ get() [1/2]

template<typename T >
Field< T >::Value lsst::afw::table::BaseRecord::get ( Key< T > const & key) const
inline

Return the value of a field for the given key.

No checking is done to ensure the Key belongs to the correct schema.

Definition at line 151 of file BaseRecord.h.

151 {
152 return key.getValue(getElement(key), _manager);
153 }
Field< T >::Element * getElement(Key< T > const &key)
Return a pointer to the underlying elements of a field (non-const).
Definition BaseRecord.h:93

◆ get() [2/2]

template<typename T >
T lsst::afw::table::BaseRecord::get ( OutputFunctorKey< T > const & key) const
inline

Compute a calculated or aggregate field.

Definition at line 172 of file BaseRecord.h.

172 {
173 return key.get(*this);
174 }

◆ getElement() [1/2]

template<typename T >
Field< T >::Element * lsst::afw::table::BaseRecord::getElement ( Key< T > const & key)
inline

Return a pointer to the underlying elements of a field (non-const).

This low-level access is intended mostly for use with serialization; users should generally prefer the safer get(), set() and operator[] member functions.

Definition at line 93 of file BaseRecord.h.

93 {
94 if (!key.isValid()) {
95 throw LSST_EXCEPT(
96 pex::exceptions::LogicError,
97 "Key is not valid (if this is a SourceRecord, make sure slot aliases have been set up).");
98 }
99 return reinterpret_cast<typename Field<T>::Element*>(reinterpret_cast<char*>(_data) +
100 key.getOffset());
101 }

◆ getElement() [2/2]

template<typename T >
Field< T >::Element const * lsst::afw::table::BaseRecord::getElement ( Key< T > const & key) const
inline

Return a pointer to the underlying elements of a field (const).

This low-level access is intended mostly for use with serialization; users should generally prefer the safer get(), set() and operator[] member functions.

Definition at line 111 of file BaseRecord.h.

111 {
112 if (!key.isValid()) {
113 throw LSST_EXCEPT(
114 pex::exceptions::LogicError,
115 "Key is not valid (if this is a SourceRecord, make sure slot aliases have been set up).");
116 }
117 return reinterpret_cast<typename Field<T>::Element const*>(reinterpret_cast<char const*>(_data) +
118 key.getOffset());
119 }

◆ getManager()

ndarray::Manager::Ptr lsst::afw::table::BaseRecord::getManager ( ) const
inline

Definition at line 200 of file BaseRecord.h.

200{ return _manager; }

◆ getSchema()

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

Return the Schema that holds this record's fields and keys.

Definition at line 80 of file BaseRecord.h.

80{ return _table->getSchema(); }

◆ getTable()

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

Return the table this record is associated with.

Definition at line 83 of file BaseRecord.h.

83{ return _table; }

◆ operator=() [1/2]

BaseRecord & lsst::afw::table::BaseRecord::operator= ( BaseRecord && )
delete

◆ operator=() [2/2]

BaseRecord & lsst::afw::table::BaseRecord::operator= ( const BaseRecord & )
delete

◆ operator[]() [1/4]

template<typename ConstRef >
ConstRef lsst::afw::table::BaseRecord::operator[] ( ConstReferenceFunctorKey< ConstRef > const & key) const
inline

Definition at line 190 of file BaseRecord.h.

190 {
191 return key.getConstReference(*this);
192 }

◆ operator[]() [2/4]

template<typename T >
Field< T >::Reference lsst::afw::table::BaseRecord::operator[] ( Key< T > const & key)
inline

Return a reference (or reference-like type) to the field's value.

Some field types (Point, Moments, Flag, Covariance, and SpherePoint) do not support reference access.

No checking is done to ensure the Key belongs to the correct schema.

Definition at line 129 of file BaseRecord.h.

129 {
130 return key.getReference(getElement(key), _manager);
131 }

◆ operator[]() [3/4]

template<typename T >
Field< T >::ConstReference lsst::afw::table::BaseRecord::operator[] ( Key< T > const & key) const
inline

Return a const reference (or const-reference-like type) to the field's value.

Some field types (Point, Moments, Flag, Covariance, and SpherePoint) do not support reference access.

No checking is done to ensure the Key belongs to the correct schema.

Definition at line 141 of file BaseRecord.h.

141 {
142 return key.getConstReference(getElement(key), _manager);
143 }

◆ operator[]() [4/4]

template<typename Ref >
Ref lsst::afw::table::BaseRecord::operator[] ( ReferenceFunctorKey< Ref > const & key)
inline

Definition at line 185 of file BaseRecord.h.

185 {
186 return key.getReference(*this);
187 }

◆ set() [1/2]

template<typename T , typename U >
void lsst::afw::table::BaseRecord::set ( InputFunctorKey< T > const & key,
U const & value )
inline

Set a calculated or aggregate field.

Definition at line 180 of file BaseRecord.h.

180 {
181 return key.set(*this, value);
182 }

◆ set() [2/2]

template<typename T , typename U >
void lsst::afw::table::BaseRecord::set ( Key< T > const & key,
U const & value )
inline

Set value of a field for the given key.

This method has an additional template parameter because some fields accept and convert different types to the stored field type.

No checking is done to ensure the Key belongs to the correct schema.

Definition at line 164 of file BaseRecord.h.

164 {
165 key.setValue(getElement(key), _manager, value);
166 }

Friends And Related Symbol Documentation

◆ BaseColumnView

Definition at line 218 of file BaseRecord.h.

◆ BaseTable

Definition at line 217 of file BaseRecord.h.

◆ operator<<

std::ostream & operator<< ( std::ostream & os,
BaseRecord const & record )
friend

Write the record's content out, one field on each line.

Definition at line 158 of file BaseRecord.cc.

158 {
159 record._stream(os);
160 return os;
161}
std::ostream * os
Definition Schema.cc:557

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