LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+bd2ed33bd6,g1470d8bcf6+c6d6eb38e2,g14a832a312+9d12ad093c,g2079a07aa2+86d27d4dc4,g2305ad1205+91a32aca49,g295015adf3+88246b6574,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+c34e8be1fa,g487adcacf7+85dcfbcc36,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ea1711114f,g5a732f18d5+53520f316c,g64a986408d+bd2ed33bd6,g858d7b2824+bd2ed33bd6,g8a8a8dda67+585e252eca,g99cad8db69+016a06b37a,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+b6d7b42999,gc120e1dc64+f745648b3a,gc28159a63d+0e5473021a,gcf0d15dbbd+c34e8be1fa,gdaeeff99f8+f9a426f77a,ge6526c86ff+508d0e0a30,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+8d59551888,gf1cff7945b+bd2ed33bd6,w.2024.16
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 utils::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: