LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
|
Defines the fields and offsets for a table. More...
#include <Schema.h>
Public Types | |
enum | ComparisonFlags { EQUAL_KEYS = 0x01 , EQUAL_NAMES = 0x02 , EQUAL_DOCS = 0x04 , EQUAL_UNITS = 0x08 , EQUAL_FIELDS = 0x0F , EQUAL_ALIASES = 0x10 , IDENTICAL = 0x1F } |
Bit flags used when comparing schemas. More... | |
Public Member Functions | |
std::string | join (std::string const &a, std::string const &b) const |
Join strings using the field delimiter appropriate for this Schema. | |
std::string | join (std::string const &a, std::string const &b, std::string const &c) const |
std::string | join (std::string const &a, std::string const &b, std::string const &c, std::string const &d) const |
template<typename T > | |
SchemaItem< T > | find (std::string const &name) const |
Find a SchemaItem in the Schema by name. | |
template<typename T > | |
SchemaItem< T > | find (Key< T > const &key) const |
Find a SchemaItem in the Schema by key. | |
template<typename F > | |
void | findAndApply (std::string const &name, F &&func) const |
Find a SchemaItem by name and run a functor on it. | |
SubSchema | operator[] (std::string const &name) const |
Look up a (possibly incomplete) name in the Schema. | |
std::set< std::string > | getNames (bool topOnly=false) const |
Return a set of field names in the schema. | |
std::size_t | getRecordSize () const |
Return the raw size of a record in bytes. | |
std::size_t | getFieldCount () const |
The total number of fields. | |
std::size_t | getFlagFieldCount () const |
The number of Flag fields. | |
std::size_t | getNonFlagFieldCount () const |
The number of non-Flag fields. | |
template<typename T > | |
Key< T > | addField (Field< T > const &field, bool doReplace=false) |
Add a new field to the Schema, and return the associated Key. | |
template<typename T > | |
Key< T > | addField (std::string const &name, std::string const &doc, std::string const &units="", FieldBase< T > const &base=FieldBase< T >(), bool doReplace=false) |
Add a new field to the Schema, and return the associated Key. | |
template<typename T > | |
Key< T > | addField (std::string const &name, std::string const &doc, FieldBase< T > const &base, bool doReplace=false) |
Add a new field to the Schema, and return the associated Key. | |
template<typename T > | |
void | replaceField (Key< T > const &key, Field< T > const &field) |
Replace the Field (name/description) for an existing Key. | |
template<typename F > | |
void | forEach (F &func) const |
Apply a functor to each SchemaItem in the Schema. | |
template<typename F > | |
void | forEach (F const &func) const |
bool | operator== (Schema const &other) const |
Equality comparison. | |
bool | operator!= (Schema const &other) const |
std::size_t | hash_value () const noexcept |
Return a hash of this object. | |
int | compare (Schema const &other, int flags=EQUAL_KEYS) const |
Do a detailed equality comparison of two schemas. | |
int | contains (Schema const &other, int flags=EQUAL_KEYS) const |
Test whether the given schema is a subset of this. | |
template<typename T > | |
int | contains (SchemaItem< T > const &item, int flags=EQUAL_KEYS) const |
Return true if the given item is in this schema. | |
std::shared_ptr< AliasMap > | getAliasMap () const |
Return the map of aliases. | |
void | setAliasMap (std::shared_ptr< AliasMap > aliases) |
Set the alias map. | |
void | disconnectAliases () |
Sever the connection between this schema and any others with which it shares aliases. | |
Schema () | |
Construct an empty Schema. | |
Schema (Schema const &other) | |
Copy constructor. | |
Schema (Schema &&other) | |
Schema & | operator= (Schema const &other) |
Schema & | operator= (Schema &&other) |
~Schema () | |
Static Public Member Functions | |
static Schema | readFits (std::string const &filename, int hdu=fits::DEFAULT_HDU) |
Construct from reading a FITS file. | |
static Schema | readFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU) |
static Schema | readFits (fits::Fits &fitsfile) |
static Schema | fromFitsMetadata (daf::base::PropertyList &header, bool stripMetadata=true) |
Construct from reading a FITS header. | |
Static Public Attributes | |
static int const | VERSION = detail::SchemaImpl::VERSION |
Friends | |
class | detail::Access |
class | SubSchema |
std::ostream & | operator<< (std::ostream &os, Schema const &schema) |
Stringification. | |
Defines the fields and offsets for a table.
Schema behaves like a container of SchemaItem objects, mapping a descriptive Field object with the Key object used to access record and ColumnView values. A Schema is the most important ingredient in creating a table.
Because offsets for fields are assigned when the field is added to the Schema, Schemas do not support removing fields, though they do allow renaming.
Field names in Schemas are expected to be underscore-separated names (e.g. 'a_b_c', but see Field Names for the full conventions, including when to use underscores vs. CamelCase). The SubSchema class and Schema::operator[] provide a heirarchical interface to these names, but are implemented entirely as string splitting/joining operations that ultimately forward to member functions that operate on the fully-qualified field name, so there is no requirement that names be separated by underscores, and no performance advantage to using a SubSchema.
A SchemaMapper object can be used to define a relationship between two Schemas to be used when copying values from one table to another or loading/saving selected fields to disk.
Schema uses copy-on-write, and hence should always be held by value rather than smart pointer. When creating a Python interface, functions that return Schema by const reference should be converted to return by value (returnCopy) to ensure proper memory management and encapsulation.
Bit flags used when comparing schemas.
All quantities are compared in insertion order, so if two schemas have the same fields added in opposite order, they will not be considered equal.
Definition at line 65 of file Schema.h.
lsst::afw::table::Schema::Schema | ( | ) |
lsst::afw::table::Schema::Schema | ( | Schema && | other | ) |
|
default |
Key< T > lsst::afw::table::Schema::addField | ( | Field< T > const & | field, |
bool | doReplace = false ) |
Add a new field to the Schema, and return the associated Key.
The offsets of fields are determined by the order they are added, but may be not contiguous (the Schema may add padding to align fields, and how much padding is considered an implementation detail).
If doReplace is true and the field exists, it will be replaced instead of throwing an exception.
Definition at line 479 of file Schema.cc.
|
inline |
Add a new field to the Schema, and return the associated Key.
This is simply a convenience wrapper, equivalent to:
addField(Field<T>(name, doc, base), doReplace)
Definition at line 194 of file Schema.h.
|
inline |
int lsst::afw::table::Schema::compare | ( | Schema const & | other, |
int | flags = EQUAL_KEYS ) const |
Do a detailed equality comparison of two schemas.
See ComparisonFlags for a description of the possible return values
[in] | other | The other schema to compare to. |
[in] | flags | Which types of comparisions to perform. Flag bits not present here will never be returned. |
Definition at line 509 of file Schema.cc.
int lsst::afw::table::Schema::contains | ( | Schema const & | other, |
int | flags = EQUAL_KEYS ) const |
Test whether the given schema is a subset of this.
This function behaves very similarly to compare(), but ignores fields that are present in this but absent in other.
Definition at line 490 of file Schema.cc.
int lsst::afw::table::Schema::contains | ( | SchemaItem< T > const & | item, |
int | flags = EQUAL_KEYS ) const |
Return true if the given item is in this schema.
The flags must include the EQUAL_KEYS bit, and if the item cannot be found by key no bits will be set on return.
void lsst::afw::table::Schema::disconnectAliases | ( | ) |
SchemaItem< T > lsst::afw::table::Schema::find | ( | Key< T > const & | key | ) | const |
Find a SchemaItem in the Schema by key.
Keys corresponding to named subfields are accepted, and will return a SchemaItem whose field is copied from the parent field with only the name changed. Keys corresponding to unnamed subfields (such as array elements) are not accepted.
Definition at line 474 of file Schema.cc.
SchemaItem< T > lsst::afw::table::Schema::find | ( | std::string const & | name | ) | const |
Find a SchemaItem in the Schema by name.
Names corresponding to named subfields are accepted, and will return a SchemaItem whose field is copied from the parent field with only the name changed.
|
inline |
Find a SchemaItem by name and run a functor on it.
Names corresponding to named subfields are not accepted. The given functor must have an overloaded function call operator that accepts any SchemaItem type (the same as a functor provided to forEach).
Definition at line 117 of file Schema.h.
Apply a functor to each SchemaItem in the Schema.
The functor must have a templated or sufficiently overloaded operator() that supports SchemaItems of all supported field types - even those that are not present in this particular Schema.
Fields will be processed in the order they were added to the schema.
Definition at line 214 of file Schema.h.
|
static |
|
inline |
Return the map of aliases.
Note that while this is a const method, it does allow the Schema's aliases to be edited - this allows the aliases to be modified even after a Table has been constructed from the Schema.
See AliasMap for more information on schema aliases.
Definition at line 279 of file Schema.h.
|
inline |
The total number of fields.
Definition at line 152 of file Schema.h.
|
inline |
The number of Flag fields.
Definition at line 155 of file Schema.h.
std::set< std::string > lsst::afw::table::Schema::getNames | ( | bool | topOnly = false | ) | const |
Return a set of field names in the schema.
If topOnly==true, return a unique list of only the part of the names before the first underscore. For example, if the full list of field names is ['a_b_c', 'a_d', 'e_f'], topOnly==true will return ['a', 'e'].
Returns an instance of Python's builtin set in Python.
Aliases are not returned.
Definition at line 464 of file Schema.cc.
|
inline |
The number of non-Flag fields.
Definition at line 158 of file Schema.h.
|
inline |
Return the raw size of a record in bytes.
Definition at line 149 of file Schema.h.
|
noexcept |
Return a hash of this object.
Definition at line 520 of file Schema.cc.
std::string lsst::afw::table::Schema::join | ( | std::string const & | a, |
std::string const & | b ) const |
|
inline |
Definition at line 78 of file Schema.h.
|
inline |
Definition at line 236 of file Schema.h.
Equality comparison.
Schemas are considered equal according the standard equality operator if their sequence of keys are identical (same types with the same offsets); names and descriptions of fields are not considered. For a more precise comparison, use compare() or contains().
Definition at line 235 of file Schema.h.
|
inline |
Look up a (possibly incomplete) name in the Schema.
See SubSchema for more information.
This member function should generally only be used on "finished" Schemas; modifying a Schema after a SubSchema to it has been constructed will not allow the proxy to track the additions, and will invoke the copy-on-write mechanism of the Schema itself.
Definition at line 464 of file Schema.h.
|
static |
Definition at line 442 of file Schema.cc.
|
static |
Definition at line 436 of file Schema.cc.
|
static |
Construct from reading a FITS file.
Reads from the nominated 'hdu' (0=PHU which cannot be a catalog, afw::fits::DEFAULT_HDU is a special value meaning read from the first HDU with NAXIS != 0).
Definition at line 430 of file Schema.cc.
void lsst::afw::table::Schema::replaceField | ( | Key< T > const & | key, |
Field< T > const & | field ) |
Replace the Field (name/description) for an existing Key.
Definition at line 485 of file Schema.cc.
void lsst::afw::table::Schema::setAliasMap | ( | std::shared_ptr< AliasMap > | aliases | ) |
Set the alias map.
This resets the internal pointer to the alias map, disconnecting this schema from any others it shares aliases with.
Passing a null pointer is equivalent to passing an empty map.
Definition at line 533 of file Schema.cc.
|
friend |
|
friend |
|
static |