LSST Applications 26.0.0,g0265f82a02+6660c170cc,g07994bdeae+30b05a742e,g0a0026dc87+17526d298f,g0a60f58ba1+17526d298f,g0e4bf8285c+96dd2c2ea9,g0ecae5effc+c266a536c8,g1e7d6db67d+6f7cb1f4bb,g26482f50c6+6346c0633c,g2bbee38e9b+6660c170cc,g2cc88a2952+0a4e78cd49,g3273194fdb+f6908454ef,g337abbeb29+6660c170cc,g337c41fc51+9a8f8f0815,g37c6e7c3d5+7bbafe9d37,g44018dc512+6660c170cc,g4a941329ef+4f7594a38e,g4c90b7bd52+5145c320d2,g58be5f913a+bea990ba40,g635b316a6c+8d6b3a3e56,g67924a670a+bfead8c487,g6ae5381d9b+81bc2a20b4,g93c4d6e787+26b17396bd,g98cecbdb62+ed2cb6d659,g98ffbb4407+81bc2a20b4,g9ddcbc5298+7f7571301f,ga1e77700b3+99e9273977,gae46bcf261+6660c170cc,gb2715bf1a1+17526d298f,gc86a011abf+17526d298f,gcf0d15dbbd+96dd2c2ea9,gdaeeff99f8+0d8dbea60f,gdb4ec4c597+6660c170cc,ge23793e450+96dd2c2ea9,gf041782ebf+171108ac67
LSST Data Management Base Package
Loading...
Searching...
No Matches
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
9namespace lsst {
10namespace afw {
11namespace table {
12
13namespace detail {
14
18 using result_type = bool;
19
21
22 explicit FlagExtractor(Key<Flag> const& key) : _mask(argument_type(1) << key.getBit()) {}
23
24private:
25 argument_type _mask;
26};
27
28} // namespace detail
29
30class BaseTable;
31
32class BaseColumnView;
33
42class BitsColumn final {
43public:
45
46 ndarray::Array<SizeT, 1, 1> getArray() const { return _array; }
47
48 SizeT getBit(Key<Flag> const& key) const;
49 SizeT getBit(std::string const& name) const;
50
51 SizeT getMask(Key<Flag> const& key) const { return SizeT(1) << getBit(key); }
52 SizeT getMask(std::string const& name) const { return SizeT(1) << getBit(name); }
53
54 std::vector<SchemaItem<Flag> > const& getSchemaItems() const { return _items; }
55
56private:
57 friend class BaseColumnView;
58
59 explicit BitsColumn(std::size_t size);
60
61 ndarray::Array<SizeT, 1, 1> _array;
63};
64
84public:
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
110 ndarray::Array<double, 1> const get_radians_array(Key<Angle> const & key) const;
111
120 BitsColumn getBits(std::vector<Key<Flag> > const& keys) const;
121
130 BitsColumn getAllBits() const;
131
138 template <typename InputIterator>
139 static BaseColumnView make(std::shared_ptr<BaseTable> const& table, InputIterator first,
140 InputIterator last);
141
149 template <typename InputIterator>
150 static bool isRangeContiguous(std::shared_ptr<BaseTable> const& table, InputIterator first,
151 InputIterator last);
152
157
159
160protected:
161 BaseColumnView(std::shared_ptr<BaseTable> const& table, std::size_t recordCount, void* buf,
162 ndarray::Manager::Ptr const& manager);
163
164private:
165 friend class BaseTable;
166
167 struct Impl;
168
170};
171
172template <typename RecordT>
174public:
175 using Record = RecordT;
176 using Table = typename RecordT::Table;
177
180 return std::static_pointer_cast<Table>(BaseColumnView::getTable());
181 }
182
184 template <typename InputIterator>
185 static ColumnViewT make(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last) {
186 return ColumnViewT(BaseColumnView::make(table, first, last));
187 }
188
189 ColumnViewT(ColumnViewT const&) = default;
193 ~ColumnViewT() = default;
194
195protected:
196 explicit ColumnViewT(BaseColumnView const& base) : BaseColumnView(base) {}
197};
198
199template <typename InputIterator>
201 InputIterator last) {
202 if (first == last) {
203 return BaseColumnView(table, 0, nullptr, ndarray::Manager::Ptr());
204 }
205 Schema schema = table->getSchema();
206 std::size_t recordSize = schema.getRecordSize();
207 std::size_t recordCount = 1;
208 void* buf = first->_data;
209 ndarray::Manager::Ptr manager = first->_manager;
210 char* expected = reinterpret_cast<char*>(buf) + recordSize;
211 for (++first; first != last; ++first, ++recordCount, expected += recordSize) {
212 if (first->_data != expected || first->_manager != manager) {
214 "Record data is not contiguous in memory.");
215 }
216 }
217 return BaseColumnView(table, recordCount, buf, manager);
218}
219
220template <typename InputIterator>
222 InputIterator last) {
223 if (first == last) return true;
224 Schema schema = table->getSchema();
225 std::size_t recordSize = schema.getRecordSize();
226 std::size_t recordCount = 1;
227 void* buf = first->_data;
228 ndarray::Manager::Ptr manager = first->_manager;
229 char* expected = reinterpret_cast<char*>(buf) + recordSize;
230 for (++first; first != last; ++first, ++recordCount, expected += recordSize) {
231 if (first->_data != expected || first->_manager != manager) {
232 return false;
233 }
234 }
235 return true;
236}
237} // namespace table
238} // namespace afw
239} // namespace lsst
240
241#endif // !AFW_TABLE_BaseColumnView_h_INCLUDED
table::Key< std::string > name
Definition Amplifier.cc:116
double element[2]
Definition BaseTable.cc:90
table::Key< int > type
Definition Detector.cc:163
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
table::Schema schema
Definition python.h:134
Tag types used to declare specialized field types.
Definition misc.h:31
Column-wise view into a sequence of records that have been allocated contiguously.
BaseColumnView & operator=(BaseColumnView const &)
BitsColumn getBits(std::vector< Key< Flag > > const &keys) const
Return an integer array with the given Flag fields repacked into individual bits.
Schema getSchema() const
Return the schema that defines the fields.
BaseColumnView & operator=(BaseColumnView &&)
BaseColumnView(BaseColumnView const &)
BaseColumnView(BaseColumnView &&)
static BaseColumnView make(std::shared_ptr< BaseTable > const &table, InputIterator first, InputIterator last)
Construct a BaseColumnView from an iterator range.
BitsColumn getAllBits() const
Return an integer array with all Flag fields repacked into individual bits.
ndarray::Array< double, 1 > const get_radians_array(Key< Angle > const &key) const
Return an array column as a double array in radians.
std::shared_ptr< BaseTable > getTable() const
Return the table that owns the records.
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 ...
ndarray::ArrayRef< T, 1 > const operator[](Key< T > const &key) const
Return a 1-d array corresponding to a scalar field (or subfield).
Base class for all tables.
Definition BaseTable.h:61
A packed representation of a collection of Flag field columns.
std::vector< SchemaItem< Flag > > const & getSchemaItems() const
SizeT getMask(Key< Flag > const &key) const
SizeT getBit(Key< Flag > const &key) const
ndarray::Array< SizeT, 1, 1 > getArray() const
SizeT getMask(std::string const &name) const
typename RecordT::Table Table
std::shared_ptr< Table > getTable() const
Return the table that owns the records.
ColumnViewT(ColumnViewT const &)=default
ColumnViewT(ColumnViewT &&)=default
ColumnViewT(BaseColumnView const &base)
ColumnViewT & operator=(ColumnViewT const &)=default
ColumnViewT & operator=(ColumnViewT &&)=default
static ColumnViewT make(std::shared_ptr< Table > const &table, InputIterator first, InputIterator last)
Construct a BaseColumnView from an iterator range.
A class used as a handle to a particular field in a table.
Definition Key.h:53
Defines the fields and offsets for a table.
Definition Schema.h:51
Reports errors that are due to events beyond the control of the program.
Definition Runtime.h:104
typename FieldBase< T >::Element Element
Type used to store field data in the table (a field may have multiple elements).
Definition Field.h:26
Functor to compute a flag bit, used to create an ndarray expression template for flag columns.
result_type operator()(argument_type element) const