LSSTApplications  20.0.0
LSSTDataManagementBasePackage
BaseColumnView.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_BaseColumnView_h_INCLUDED
3 #define AFW_TABLE_BaseColumnView_h_INCLUDED
4 
5 #include <cstdint>
6 
8 
9 namespace lsst {
10 namespace afw {
11 namespace table {
12 
13 namespace detail {
14 
16 struct FlagExtractor {
18  typedef bool result_type;
19 
20  result_type operator()(argument_type element) const { return element & _mask; }
21 
22  explicit FlagExtractor(Key<Flag> const& key) : _mask(argument_type(1) << key.getBit()) {}
23 
24 private:
25  argument_type _mask;
26 };
27 
28 } // namespace detail
29 
30 class BaseTable;
31 
32 class BaseColumnView;
33 
42 class BitsColumn final {
43 public:
44  typedef std::int64_t IntT;
45 
46  ndarray::Array<IntT, 1, 1> getArray() const { return _array; }
47 
48  IntT getBit(Key<Flag> const& key) const;
49  IntT getBit(std::string const& name) const;
50 
51  IntT getMask(Key<Flag> const& key) const { return IntT(1) << getBit(key); }
52  IntT getMask(std::string const& name) const { return IntT(1) << getBit(name); }
53 
54  std::vector<SchemaItem<Flag> > const& getSchemaItems() const { return _items; }
55 
56 private:
57  friend class BaseColumnView;
58 
59  explicit BitsColumn(int size);
60 
61  ndarray::Array<IntT, 1, 1> _array;
63 };
64 
84 public:
87 
89  Schema getSchema() const { return getTable()->getSchema(); }
90 
92  template <typename T>
93  ndarray::ArrayRef<T, 1> const operator[](Key<T> const& key) const;
94 
96  template <typename T>
97  ndarray::ArrayRef<T, 2, 1> const operator[](Key<Array<T> > const& key) const;
98 
106  ndarray::result_of::vectorize<detail::FlagExtractor, ndarray::Array<Field<Flag>::Element const, 1> >::type
107  operator[](Key<Flag> const& key) const;
108 
117  BitsColumn getBits(std::vector<Key<Flag> > const& keys) const;
118 
127  BitsColumn getAllBits() const;
128 
135  template <typename InputIterator>
136  static BaseColumnView make(std::shared_ptr<BaseTable> const& table, InputIterator first,
137  InputIterator last);
138 
146  template <typename InputIterator>
147  static bool isRangeContiguous(std::shared_ptr<BaseTable> const& table, InputIterator first,
148  InputIterator last);
149 
154 
156 
157 protected:
158  BaseColumnView(std::shared_ptr<BaseTable> const& table, int recordCount, void* buf,
159  ndarray::Manager::Ptr const& manager);
160 
161 private:
162  friend class BaseTable;
163 
164  struct Impl;
165 
166  std::shared_ptr<Impl> _impl;
167 };
168 
169 template <typename RecordT>
170 class ColumnViewT : public BaseColumnView {
171 public:
172  typedef RecordT Record;
173  typedef typename RecordT::Table Table;
174 
177  return std::static_pointer_cast<Table>(BaseColumnView::getTable());
178  }
179 
181  template <typename InputIterator>
182  static ColumnViewT make(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last) {
183  return ColumnViewT(BaseColumnView::make(table, first, last));
184  }
185 
186  ColumnViewT(ColumnViewT const&) = default;
187  ColumnViewT(ColumnViewT&&) = default;
188  ColumnViewT& operator=(ColumnViewT const&) = default;
190  ~ColumnViewT() = default;
191 
192 protected:
194 };
195 
196 template <typename InputIterator>
198  InputIterator last) {
199  if (first == last) {
200  return BaseColumnView(table, 0, 0, ndarray::Manager::Ptr());
201  }
202  Schema schema = table->getSchema();
203  std::size_t recordSize = schema.getRecordSize();
204  std::size_t recordCount = 1;
205  void* buf = first->_data;
206  ndarray::Manager::Ptr manager = first->_manager;
207  char* expected = reinterpret_cast<char*>(buf) + recordSize;
208  for (++first; first != last; ++first, ++recordCount, expected += recordSize) {
209  if (first->_data != expected || first->_manager != manager) {
211  "Record data is not contiguous in memory.");
212  }
213  }
214  return BaseColumnView(table, recordCount, buf, manager);
215 }
216 
217 template <typename InputIterator>
219  InputIterator last) {
220  if (first == last) return true;
221  Schema schema = table->getSchema();
222  std::size_t recordSize = schema.getRecordSize();
223  std::size_t recordCount = 1;
224  void* buf = first->_data;
225  ndarray::Manager::Ptr manager = first->_manager;
226  char* expected = reinterpret_cast<char*>(buf) + recordSize;
227  for (++first; first != last; ++first, ++recordCount, expected += recordSize) {
228  if (first->_data != expected || first->_manager != manager) {
229  return false;
230  }
231  }
232  return true;
233 }
234 } // namespace table
235 } // namespace afw
236 } // namespace lsst
237 
238 #endif // !AFW_TABLE_BaseColumnView_h_INCLUDED
schema
table::Schema schema
Definition: Amplifier.cc:115
lsst::afw::table::detail::FlagExtractor
Functor to compute a flag bit, used to create an ndarray expression template for flag columns.
Definition: BaseColumnView.h:16
lsst::afw::table::ColumnViewT::ColumnViewT
ColumnViewT(ColumnViewT const &)=default
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::table::ColumnViewT::Record
RecordT Record
Definition: BaseColumnView.h:172
lsst::afw::table::ColumnViewT
Definition: BaseColumnView.h:170
base
Definition: __init__.py:1
lsst::afw::table::detail::FlagExtractor::result_type
bool result_type
Definition: BaseColumnView.h:18
std::vector
STL class.
lsst::afw::table::BaseColumnView::Impl
Definition: BaseColumnView.cc:55
lsst::afw::table::BitsColumn::getMask
IntT getMask(std::string const &name) const
Definition: BaseColumnView.h:52
lsst::afw::table::BaseColumnView::operator[]
ndarray::ArrayRef< T, 1 > const operator[](Key< T > const &key) const
Return a 1-d array corresponding to a scalar field (or subfield).
Definition: BaseColumnView.cc:71
lsst::afw::table._match.first
first
Definition: _match.py:76
lsst::afw
Definition: imageAlgorithm.dox:1
astshim.keyMap.keyMapContinued.keys
def keys(self)
Definition: keyMapContinued.py:6
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::afw::table::BaseColumnView::isRangeContiguous
static bool isRangeContiguous(std::shared_ptr< BaseTable > const &table, InputIterator first, InputIterator last)
Return true if the given record iterator range is continuous and the records all belong to the given ...
Definition: BaseColumnView.h:218
lsst::afw::table::BaseColumnView
Column-wise view into a sequence of records that have been allocated contiguously.
Definition: BaseColumnView.h:83
lsst::afw::table::detail::FlagExtractor::operator()
result_type operator()(argument_type element) const
Definition: BaseColumnView.h:20
lsst::afw::geom.transform.transformContinued.name
string name
Definition: transformContinued.py:32
lsst::afw::table::BitsColumn::getArray
ndarray::Array< IntT, 1, 1 > getArray() const
Definition: BaseColumnView.h:46
lsst::afw::table::BaseTable
Base class for all tables.
Definition: BaseTable.h:61
lsst::afw::table::BitsColumn
A packed representation of a collection of Flag field columns.
Definition: BaseColumnView.h:42
lsst::afw::table::BitsColumn::getSchemaItems
std::vector< SchemaItem< Flag > > const & getSchemaItems() const
Definition: BaseColumnView.h:54
lsst::afw::table::BitsColumn::getBit
IntT getBit(Key< Flag > const &key) const
Definition: BaseColumnView.cc:33
lsst::afw::table::ColumnViewT::operator=
ColumnViewT & operator=(ColumnViewT &&)=default
lsst::afw::table::ColumnViewT::ColumnViewT
ColumnViewT(ColumnViewT &&)=default
lsst::afw::table::ColumnViewT::~ColumnViewT
~ColumnViewT()=default
lsst::afw::table::detail::FlagExtractor::argument_type
Field< Flag >::Element argument_type
Definition: BaseColumnView.h:17
lsst::afw::table::BaseColumnView::getBits
BitsColumn getBits(std::vector< Key< Flag > > const &keys) const
Return an integer array with the given Flag fields repacked into individual bits.
Definition: BaseColumnView.cc:117
lsst::afw::table::BitsColumn::getMask
IntT getMask(Key< Flag > const &key) const
Definition: BaseColumnView.h:51
lsst::afw::table::ColumnViewT::getTable
std::shared_ptr< Table > getTable() const
Return the table that owns the records.
Definition: BaseColumnView.h:176
lsst::afw::table::BaseColumnView::getTable
std::shared_ptr< BaseTable > getTable() const
Return the table that owns the records.
Definition: BaseColumnView.cc:68
lsst::afw::table::ColumnViewT::ColumnViewT
ColumnViewT(BaseColumnView const &base)
Definition: BaseColumnView.h:193
lsst::afw::table::Key
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
lsst::afw::table::BaseColumnView::operator=
BaseColumnView & operator=(BaseColumnView const &)
lsst::afw::table::Array
Tag types used to declare specialized field types.
Definition: misc.h:32
std::int64_t
lsst::afw::table::BaseColumnView::make
static BaseColumnView make(std::shared_ptr< BaseTable > const &table, InputIterator first, InputIterator last)
Construct a BaseColumnView from an iterator range.
Definition: BaseColumnView.h:197
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
LSST_EXCEPT
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
lsst::afw::table::ColumnViewT::operator=
ColumnViewT & operator=(ColumnViewT const &)=default
lsst::afw::table::Field
A description of a field in a table.
Definition: Field.h:24
lsst::afw::table::detail::FlagExtractor::FlagExtractor
FlagExtractor(Key< Flag > const &key)
Definition: BaseColumnView.h:22
type
table::Key< int > type
Definition: Detector.cc:163
key
Key< U > key
Definition: Schema.cc:281
lsst::afw::table::ColumnViewT::Table
RecordT::Table Table
Definition: BaseColumnView.h:173
lsst::afw::table::BaseColumnView::getSchema
Schema getSchema() const
Return the schema that defines the fields.
Definition: BaseColumnView.h:89
BaseTable.h
lsst::afw::table::BaseColumnView::~BaseColumnView
~BaseColumnView()
std::size_t
lsst::afw::table::BitsColumn::IntT
std::int64_t IntT
Definition: BaseColumnView.h:44
element
double element[2]
Definition: BaseTable.cc:91
lsst::afw::table::BaseColumnView::operator=
BaseColumnView & operator=(BaseColumnView &&)
lsst::afw::table::BaseColumnView::BaseColumnView
BaseColumnView(BaseColumnView const &)
lsst::afw::table::ColumnViewT::make
static ColumnViewT make(std::shared_ptr< Table > const &table, InputIterator first, InputIterator last)
Construct a BaseColumnView from an iterator range.
Definition: BaseColumnView.h:182
lsst::afw::table::BaseColumnView::BaseColumnView
BaseColumnView(BaseColumnView &&)
lsst::afw::table::BaseColumnView::getAllBits
BitsColumn getAllBits() const
Return an integer array with all Flag fields repacked into individual bits.
Definition: BaseColumnView.cc:147
lsst::afw::table::Key< Flag >
Key specialization for Flag.
Definition: Flag.h:94
lsst::pex::exceptions::RuntimeError
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104