LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
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
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
157protected:
158 BaseColumnView(std::shared_ptr<BaseTable> const& table, std::size_t recordCount, void* buf,
159 ndarray::Manager::Ptr const& manager);
160
161private:
162 friend class BaseTable;
163
164 struct Impl;
165
167};
168
169template <typename RecordT>
171public:
172 using Record = RecordT;
173 using Table = typename RecordT::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;
190 ~ColumnViewT() = default;
191
192protected:
193 explicit ColumnViewT(BaseColumnView const& base) : BaseColumnView(base) {}
194};
195
196template <typename InputIterator>
198 InputIterator last) {
199 if (first == last) {
200 return BaseColumnView(table, 0, nullptr, 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
217template <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
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.
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.
Key specialization for Flag.
Definition: Flag.h:94
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
A base class for image defects.
A description of a field in a table.
Definition: Field.h:24
Functor to compute a flag bit, used to create an ndarray expression template for flag columns.
result_type operator()(argument_type element) const
FlagExtractor(Key< Flag > const &key)