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 | 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 = ndarray::Array< T const, 1, 1 >
 The data type for get and set. More...
 

Public Member Functions

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

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< ndarray::Array< T const, 1, 1 > >::Value = ndarray::Array< T const, 1, 1 >
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
table::Key< std::string > name
Definition: Amplifier.cc:116
table::Schema schema
Definition: python.h:134
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)
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
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: