LSST Applications g0f08755f38+c89d42e150,g1635faa6d4+b6cf076a36,g1653933729+a8ce1bb630,g1a0ca8cf93+4c08b13bf7,g28da252d5a+f33f8200ef,g29321ee8c0+0187be18b1,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+e740673f1a,g5fbc88fb19+17cd334064,g7642f7d749+c89d42e150,g781aacb6e4+a8ce1bb630,g80478fca09+f8b2ab54e1,g82479be7b0+e2bd23ab8b,g858d7b2824+c89d42e150,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+065360aec4,gacf8899fa4+9553554aa7,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gbd46683f8f+ac57cbb13d,gc28159a63d+9634bc57db,gcf0d15dbbd+e37acf7834,gda3e153d99+c89d42e150,gda6a2b7d83+e37acf7834,gdaeeff99f8+1711a396fd,ge2409df99d+cb1e6652d6,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+02b11634a5,w.2024.45
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
lsst::afw::table::ArrayKey< T > Class Template Referenceabstract

A FunctorKey used to get or set a ndarray::Array from a sequence of scalar Keys. More...

#include <arrays.h>

Inheritance diagram for lsst::afw::table::ArrayKey< T >:
lsst::afw::table::FunctorKey< ndarray::Array< T const, 1, 1 > > lsst::afw::table::ReferenceFunctorKey< ndarray::ArrayRef< T, 1, 1 > > lsst::afw::table::ConstReferenceFunctorKey< ndarray::ArrayRef< T const, 1, 1 > > lsst::afw::table::OutputFunctorKey< T > lsst::afw::table::InputFunctorKey< T >

Public Types

using Value
 The data type for get and set.
 

Public Member Functions

 ArrayKey () noexcept
 Default constructor; instance will not be usable unless subsequently assigned to.
 
 ArrayKey (std::vector< Key< T > > const &keys)
 Construct from a vector of scalar Keys.
 
 ArrayKey (Key< Array< T > > const &other) noexcept
 Construct from a compound Key< Array<T> >
 
 ArrayKey (SubSchema const &s)
 Construct from a subschema, assuming *_0, *_1, *_2, etc.
 
 ArrayKey (ArrayKey const &) noexcept
 
 ArrayKey (ArrayKey &&) noexcept
 
ArrayKeyoperator= (ArrayKey const &) noexcept
 
ArrayKeyoperator= (ArrayKey &&) noexcept
 
 ~ArrayKey () noexcept override
 
std::size_t getSize () const noexcept
 Return the number of elements in the array.
 
ndarray::Array< T const, 1, 1 > get (BaseRecord const &record) const override
 Get an array from the given record.
 
void set (BaseRecord &record, ndarray::Array< T const, 1, 1 > const &value) const override
 Set an array in the given record.
 
ndarray::ArrayRef< T, 1, 1 > getReference (BaseRecord &record) const override
 Get non-const reference array from the given record.
 
ndarray::ArrayRef< T const, 1, 1 > getConstReference (BaseRecord const &record) const override
 Get const reference array from the given record.
 
bool operator== (ArrayKey< T > const &other) const noexcept
 Compare the FunctorKey for equality with another, using the underlying scalar Keys.
 
bool operator!= (ArrayKey< T > const &other) const noexcept
 
std::size_t hash_value () const noexcept
 Return a hash of this object.
 
bool isValid () const noexcept
 Return True if the FunctorKey contains valid scalar keys.
 
Key< T > operator[] (std::size_t i) const
 Return a scalar Key for an element of the array.
 
ArrayKey slice (std::size_t begin, std::size_t end) const
 Return a FunctorKey corresponding to a range of elements.
 
virtual void set (BaseRecord &record, T const &value) const =0
 

Static Public Member Functions

static ArrayKey addFields (Schema &schema, std::string const &name, std::string const &doc, std::string const &unit, std::vector< T > const &docData)
 Add an array of fields to a Schema, and return an ArrayKey that points to them.
 
static ArrayKey addFields (Schema &schema, std::string const &name, std::string const &doc, std::string const &unit, size_t size)
 Add an array of fields to a Schema, and return an ArrayKey that points to them.
 

Detailed Description

template<typename T>
class lsst::afw::table::ArrayKey< T >

A FunctorKey used to get or set a ndarray::Array from a sequence of scalar Keys.

ArrayKey operates on the convention that arrays are defined by a set of contiguous scalar fields (i.e. added to the Schema in order, with no interruption) of the same type, with a common field name prefix and "_0", "_1" etc. suffixes.

Definition at line 43 of file arrays.h.

Member Typedef Documentation

◆ Value

using lsst::afw::table::FunctorKey< T >::Value
inherited

The data type for get and set.

Definition at line 77 of file FunctorKey.h.

Constructor & Destructor Documentation

◆ ArrayKey() [1/6]

template<typename T >
lsst::afw::table::ArrayKey< T >::ArrayKey ( )
inlinenoexcept

Default constructor; instance will not be usable unless subsequently assigned to.

Definition at line 78 of file arrays.h.

78: _begin(), _size(0) {}

◆ ArrayKey() [2/6]

template<typename T >
lsst::afw::table::ArrayKey< T >::ArrayKey ( std::vector< Key< T > > const & keys)
explicit

Construct from a vector of scalar Keys.

Definition at line 66 of file arrays.cc.

66 : _begin(), _size(keys.size()) {
67 if (keys.empty()) return;
68 _begin = keys.front();
69 for (std::size_t i = 1; i < _size; ++i) {
70 if (keys[i].getOffset() - _begin.getOffset() != (i * sizeof(T))) {
71 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
72 "Keys passed to ArrayKey constructor are not contiguous");
73 }
74 }
75}
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48

◆ ArrayKey() [3/6]

template<typename T >
lsst::afw::table::ArrayKey< T >::ArrayKey ( Key< Array< T > > const & other)
explicitnoexcept

Construct from a compound Key< Array<T> >

Key< Array<T> > is needed in some cases, but ArrayKey should be preferred in new code when possible. This converting constructor is intended to aid compatibility between the two.

Definition at line 78 of file arrays.cc.

78: _begin(other[0]), _size(other.getSize()) {}

◆ ArrayKey() [4/6]

template<typename T >
lsst::afw::table::ArrayKey< T >::ArrayKey ( SubSchema const & s)
explicit

Construct from a subschema, assuming *_0, *_1, *_2, etc.

subfields

If a schema has "a_0", "a_1", and "a_2" fields, this constructor allows you to construct a 3-element ArrayKey via:

ArrayKey<T> k(schema["a"]);

Definition at line 81 of file arrays.cc.

81 : _begin(s["0"]), _size(1) {
82 Key<T> current;
83 while (true) {
84 try {
85 current = s[std::to_string(_size)];
86 } catch (pex::exceptions::NotFoundError &) {
87 return;
88 }
89 if (current.getOffset() - _begin.getOffset() != (_size * sizeof(T))) {
90 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
91 "Keys discovered in Schema are not contiguous");
92 }
93 ++_size;
94 }
95}
T to_string(T... args)

◆ ArrayKey() [5/6]

template<typename T >
lsst::afw::table::ArrayKey< T >::ArrayKey ( ArrayKey< T > const & )
defaultnoexcept

◆ ArrayKey() [6/6]

template<typename T >
lsst::afw::table::ArrayKey< T >::ArrayKey ( ArrayKey< T > && )
defaultnoexcept

◆ ~ArrayKey()

template<typename T >
lsst::afw::table::ArrayKey< T >::~ArrayKey ( )
overridedefaultnoexcept

Member Function Documentation

◆ addFields() [1/2]

template<typename T >
ArrayKey< T > lsst::afw::table::ArrayKey< T >::addFields ( Schema & schema,
std::string const & name,
std::string const & doc,
std::string const & unit,
size_t size )
static

Add an array of fields to a Schema, and return an ArrayKey that points to them.

Parameters
[in,out]schemaSchema to add fields to.
[in]nameName prefix for all fields; "_0", "_1", etc. will be appended to this to form the full field names.
[in]docString used as the documentation for the fields.
[in]unitString used as the unit for all fields.
[in]sizeNumber of fields to add.

Definition at line 51 of file arrays.cc.

52 {
54 if (size == 0) return result;
55 result._size = size;
56 result._begin = schema.addField<T>(
57 schema.join(name, "0"), // we use getPrefix in order to get the version-dependent delimiter
58 doc, unit);
59 for (std::size_t i = 1; i < result._size; ++i) {
60 schema.addField<T>(schema.join(name, std::to_string(i)), doc, unit);
61 }
62 return result;
63}
py::object result
Definition _schema.cc:429
ArrayKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to.
Definition arrays.h:78

◆ addFields() [2/2]

template<typename T >
ArrayKey< T > lsst::afw::table::ArrayKey< T >::addFields ( Schema & schema,
std::string const & name,
std::string const & doc,
std::string const & unit,
std::vector< T > const & docData )
static

Add an array of fields to a Schema, and return an ArrayKey that points to them.

Parameters
[in,out]schemaSchema to add fields to.
[in]nameName prefix for all fields; "_0", "_1", etc. will be appended to this to form the full field names.
[in]docString used as the documentation for the fields. Should include a single boost::format template string, which will be substituted with the appropriate element from the docData array to form the full documentation string.
[in]unitString used as the unit for all fields.
[in]docDataVector of values substituted into the doc fields. The length of the vector determines the number of fields added.

Definition at line 35 of file arrays.cc.

36 {
37 ArrayKey<T> result;
38 if (docData.empty()) return result;
39 result._size = docData.size();
40 result._begin = schema.addField<T>(
41 schema.join(name, "0"), // we use getPrefix in order to get the version-dependent delimiter
42 (boost::format(doc) % docData.front()).str(), unit);
43 for (std::size_t i = 1; i < result._size; ++i) {
44 schema.addField<T>(schema.join(name, std::to_string(i)), (boost::format(doc) % docData[i]).str(),
45 unit);
46 }
47 return result;
48}
T empty(T... args)
T front(T... args)
T size(T... args)

◆ get()

template<typename T >
ndarray::Array< T const, 1, 1 > lsst::afw::table::ArrayKey< T >::get ( BaseRecord const & record) const
overridevirtual

Get an array from the given record.

Implements lsst::afw::table::OutputFunctorKey< T >.

Definition at line 109 of file arrays.cc.

109 {
110 return ndarray::external(record.getElement(_begin), ndarray::makeVector(_size), ndarray::ROW_MAJOR,
111 record.getManager());
112}

◆ getConstReference()

template<typename T >
ndarray::ArrayRef< T const, 1, 1 > lsst::afw::table::ArrayKey< T >::getConstReference ( BaseRecord const & record) const
overridevirtual

Get const reference array from the given record.

Implements lsst::afw::table::ConstReferenceFunctorKey< ndarray::ArrayRef< T const, 1, 1 > >.

Definition at line 129 of file arrays.cc.

129 {
130 return ndarray::external(record.getElement(_begin), ndarray::makeVector(_size), ndarray::ROW_MAJOR,
131 record.getManager());
132}

◆ getReference()

template<typename T >
ndarray::ArrayRef< T, 1, 1 > lsst::afw::table::ArrayKey< T >::getReference ( BaseRecord & record) const
overridevirtual

Get non-const reference array from the given record.

Implements lsst::afw::table::ReferenceFunctorKey< ndarray::ArrayRef< T, 1, 1 > >.

Definition at line 123 of file arrays.cc.

123 {
124 return ndarray::external(record.getElement(_begin), ndarray::makeVector(_size), ndarray::ROW_MAJOR,
125 record.getManager());
126}

◆ getSize()

template<typename T >
std::size_t lsst::afw::table::ArrayKey< T >::getSize ( ) const
inlinenoexcept

Return the number of elements in the array.

Definition at line 108 of file arrays.h.

108{ return _size; }

◆ hash_value()

template<typename T >
std::size_t lsst::afw::table::ArrayKey< T >::hash_value ( ) const
inlinenoexcept

Return a hash of this object.

Definition at line 131 of file arrays.h.

131 {
132 // Completely arbitrary seed
133 return cpputils::hashCombine(17, _begin, _size);
134 }
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition hashCombine.h:35

◆ isValid()

template<typename T >
bool lsst::afw::table::ArrayKey< T >::isValid ( ) const
inlinenoexcept

Return True if the FunctorKey contains valid scalar keys.

Definition at line 137 of file arrays.h.

137{ return _begin.isValid(); }

◆ operator!=()

template<typename T >
bool lsst::afw::table::ArrayKey< T >::operator!= ( ArrayKey< T > const & other) const
inlinenoexcept

Definition at line 127 of file arrays.h.

127{ return !operator==(other); }
bool operator==(ArrayKey< T > const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying scalar Keys.
Definition arrays.h:124

◆ operator=() [1/2]

template<typename T >
ArrayKey< T > & lsst::afw::table::ArrayKey< T >::operator= ( ArrayKey< T > && )
defaultnoexcept

◆ operator=() [2/2]

template<typename T >
ArrayKey< T > & lsst::afw::table::ArrayKey< T >::operator= ( ArrayKey< T > const & )
defaultnoexcept

◆ operator==()

template<typename T >
bool lsst::afw::table::ArrayKey< T >::operator== ( ArrayKey< T > const & other) const
inlinenoexcept

Compare the FunctorKey for equality with another, using the underlying scalar Keys.

Definition at line 124 of file arrays.h.

124 {
125 return other._begin == _begin && other._size == _size;
126 }

◆ operator[]()

template<typename T >
Key< T > lsst::afw::table::ArrayKey< T >::operator[] ( std::size_t i) const

Return a scalar Key for an element of the array.

Definition at line 135 of file arrays.cc.

135 {
136 if (i >= _size) {
137 throw LSST_EXCEPT(pex::exceptions::LengthError, "ArrayKey index does not fit within valid range");
138 }
139 return detail::Access::makeKey<T>(_begin.getOffset() + i * sizeof(T));
140}

◆ set() [1/2]

template<typename T >
void lsst::afw::table::ArrayKey< T >::set ( BaseRecord & record,
ndarray::Array< T const, 1, 1 > const & value ) const
override

Set an array in the given record.

Definition at line 115 of file arrays.cc.

115 {
116 LSST_THROW_IF_NE(value.template getSize<0>(), static_cast<std::size_t>(_size),
117 pex::exceptions::LengthError,
118 "Size of input array (%d) does not match size of array field (%d)");
119 std::copy(value.begin(), value.end(), record.getElement(_begin));
120}
#define LSST_THROW_IF_NE(N1, N2, EXC_CLASS, MSG)
Check whether the given values are equal, and throw an LSST Exception if they are not.
Definition asserts.h:38
T copy(T... args)

◆ set() [2/2]

template<typename T >
virtual void lsst::afw::table::InputFunctorKey< T >::set ( BaseRecord & record,
T const & value ) const
pure virtualinherited

◆ slice()

template<typename T >
ArrayKey< T > lsst::afw::table::ArrayKey< T >::slice ( std::size_t begin,
std::size_t end ) const

Return a FunctorKey corresponding to a range of elements.

Definition at line 143 of file arrays.cc.

143 {
144 if (begin >= end || end > _size) {
145 throw LSST_EXCEPT(pex::exceptions::LengthError,
146 "ArrayKey slice range does not fit within valid range");
147 }
148 return ArrayKey((*this)[begin], end - begin);
149}
int end

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