LSSTApplications  19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+13,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+5,19.0.0-20-g5a5a17ab+11,19.0.0-21-g2644856+13,19.0.0-23-g84eeccb+1,19.0.0-24-g878c510+1,19.0.0-25-g6c8df7140,19.0.0-25-gb330496+1,19.0.0-3-g2b32d65+5,19.0.0-3-g8227491+12,19.0.0-3-g9c54d0d+12,19.0.0-3-gca68e65+8,19.0.0-3-gcfc5f51+5,19.0.0-3-ge110943+11,19.0.0-3-ge74d124,19.0.0-3-gfe04aa6+13,19.0.0-30-g9c3fd16+1,19.0.0-4-g06f5963+5,19.0.0-4-g3d16501+13,19.0.0-4-g4a9c019+5,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8278b9b+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+13,19.0.0-4-ge404a01+12,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gfb03ce7+13,19.0.0-6-gbaebbfb+12,19.0.0-61-gec4c6e08+1,19.0.0-7-g039c0b5+11,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+13,19.0.0-71-g41c0270,19.0.0-9-g2f02add+1,19.0.0-9-g463f923+12,w.2020.22
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | List of all members
lsst::afw::table::ArrayKey< T > Class Template Reference

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< ndarray::Array< T const, 1, 1 > > lsst::afw::table::InputFunctorKey< ndarray::Array< T const, 1, 1 > >

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
 
int 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[] (int i) const
 Return a scalar Key for an element of the array. More...
 
ArrayKey slice (int begin, int end) const
 Return a FunctorKey corresponding to a range of elements. More...
 

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, int 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 (int i = 1; i < _size; ++i) {
70  if (keys[i].getOffset() - _begin.getOffset() != static_cast<int>(i * sizeof(T))) {
71  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
72  "Keys passed to ArrayKey constructor are not contiguous");
73  }
74  }
75 }

◆ 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)

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() != static_cast<int>(_size * sizeof(T))) {
90  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
91  "Keys discovered in Schema are not contiguous");
92  }
93  ++_size;
94  }
95 }

◆ 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,
int  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 (int i = 1; i < result._size; ++i) {
60  schema.addField<T>(schema.join(name, std::to_string(i)), doc, unit);
61  }
62  return result;
63 }

◆ 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 (int 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 }

◆ 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< ndarray::Array< T const, 1, 1 > >.

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 >
int 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  }

◆ 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); }

◆ 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[] ( int  i) const

Return a scalar Key for an element of the array.

Definition at line 135 of file arrays.cc.

135  {
136  if (i < 0 || 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()

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

Set an array in the given record.

Implements lsst::afw::table::InputFunctorKey< ndarray::Array< T const, 1, 1 > >.

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 }

◆ slice()

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

Return a FunctorKey corresponding to a range of elements.

Definition at line 143 of file arrays.cc.

143  {
144  if (begin < 0 || 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 }

The documentation for this class was generated from the following files:
schema
table::Schema schema
Definition: Amplifier.cc:115
LSST_THROW_IF_NE
#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
std::vector::size
T size(T... args)
pex.config.history.format
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
astshim.keyMap.keyMapContinued.keys
def keys(self)
Definition: keyMapContinued.py:6
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
std::vector::front
T front(T... args)
end
int end
Definition: BoundedField.cc:105
lsst::afw::table::ArrayKey::ArrayKey
ArrayKey() noexcept
Default constructor; instance will not be usable unless subsequently assigned to.
Definition: arrays.h:78
other
ItemVariant const * other
Definition: Schema.cc:56
std::to_string
T to_string(T... args)
std::copy
T copy(T... args)
result
py::object result
Definition: _schema.cc:429
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::utils::hashCombine
std::size_t hashCombine(std::size_t seed) noexcept
Combine hashes.
Definition: hashCombine.h:35
lsst::afw::table::ArrayKey::operator==
bool operator==(ArrayKey< T > const &other) const noexcept
Compare the FunctorKey for equality with another, using the underlying scalar Keys.
Definition: arrays.h:124
std::vector::empty
T empty(T... args)
std::size_t