LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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:44
boost::shared_ptr< Impl > _impl
Definition: Schema.h:289
static void padSchema(Schema &schema, int bytes)
Definition: Access.h:82
afw::table::Schema schema
Definition: GaussianPsf.cc:41
static Key< T > makeKey(int offset)
Definition: Access.h:66
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
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
Tag types used to declare specialized field types.
Definition: misc.h:34
T Element
the type of subfields (the same as the type itself for scalars)
Definition: FieldBase.h:53
#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:84
table::Key< int > field
Definition: ApCorrMap.cc:72