LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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
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
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>
141
149 template <typename InputIterator>
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:
176 using Table = typename RecordT::Table;
177
180 return std::static_pointer_cast<Table>(BaseColumnView::getTable());
181 }
182
184 template <typename InputIterator>
188
189 ColumnViewT(ColumnViewT const&) = default;
193 ~ColumnViewT() = default;
194
195protected:
196 explicit ColumnViewT(BaseColumnView const& base) : BaseColumnView(base) {}
197};
198
199template <typename InputIterator>
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>
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
double element[2]
Definition BaseTable.cc:90
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
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