LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Access.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_DETAIL_Access_h_INCLUDED
3 #define AFW_TABLE_DETAIL_Access_h_INCLUDED
4 
5 #include <cstring>
6 
7 #include "ndarray/Manager.h"
11 
12 namespace lsst { namespace afw { namespace table {
13 
14 class BaseRecord;
15 class BaseTable;
16 
17 namespace detail {
18 
29 class Access {
30 public:
31 
33  template <typename T>
35  if (!static_cast<Key<T> const &>(kb).isValid()) {
36  throw LSST_EXCEPT(
37  pex::exceptions::LogicError,
38  (boost::format("Cannot extract subfield key from invalid key of type '%s' "
39  "(most often this is caused by failing to setup centroid or shape slots)")
40  % Key<T>::getTypeString()).str()
41  );
42  }
44  static_cast<Key<T> const &>(kb).getOffset() + n * sizeof(typename Key<T>::Element)
45  );
46  }
47 
49  template <typename T>
50  static Key< Array<T> > extractRange(KeyBase< Array<T> > const & kb, int begin, int end) {
51  if (!static_cast<Key< Array<T> > const &>(kb).isValid()) {
52  throw LSST_EXCEPT(
53  pex::exceptions::LogicError,
54  (boost::format("Cannot extract subfield key from invalid key of type '%s' ")
55  % Key<T>::getTypeString()).str()
56  );
57  }
58  return Key< Array<T> >(
59  static_cast<Key< Array<T> > const &>(kb).getOffset() + begin * sizeof(typename Key<T>::Element),
60  end - begin
61  );
62  }
63 
65  template <typename T>
66  static Key<T> makeKey(int offset) {
67  return Key<T>(offset);
68  }
69 
71  template <typename T>
72  static Key<T> makeKey(Field<T> const & field, int offset) {
73  return Key<T>(offset, field);
74  }
75 
77  static Key<Flag> makeKey(int offset, int bit) {
78  return Key<Flag>(offset, bit);
79  }
80 
82  static void padSchema(Schema & schema, int bytes) {
83  schema._edit();
84  schema._impl->_recordSize += bytes;
85  }
86 
87 };
88 
89 }}}} // namespace lsst::afw::table::detail
90 
91 #endif // !AFW_TABLE_DETAIL_Access_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:46
boost::shared_ptr< Impl > _impl
Definition: Schema.h:333
static void padSchema(Schema &schema, int bytes)
Definition: Access.h:82
static Key< T > makeKey(int offset)
Definition: Access.h:66
Definition of Manager, which manages the ownership of array data.
void _edit()
Copy on write; should be called by all mutators (except for alias mutators).
static Key< Array< T > > extractRange(KeyBase< Array< T > > const &kb, int begin, int end)
Definition: Access.h:50
static Key< T > makeKey(Field< T > const &field, int offset)
Definition: Access.h:72
tbl::Schema schema
Definition: CoaddPsf.cc:324
static Key< typename Key< T >::Element > extractElement(KeyBase< T > const &kb, int n)
Definition: Access.h:34
A description of a field in a table.
Definition: Field.h:22
static Key< Flag > makeKey(int offset, int bit)
Definition: Access.h:77
T Element
the type of subfields (the same as the type itself for scalars)
Definition: FieldBase.h:55
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
A base class for Key that allows subfield keys to be extracted for some field types.
Definition: KeyBase.h:17
A class used as a handle to a particular field in a table.
Definition: fwd.h:44
Key specialization for Flag.
Definition: Flag.h:82