LSST Applications g180d380827+6621f76652,g2079a07aa2+86d27d4dc4,g2305ad1205+f5a9e323a1,g2bbee38e9b+c6a8a0fb72,g337abbeb29+c6a8a0fb72,g33d1c0ed96+c6a8a0fb72,g3a166c0a6a+c6a8a0fb72,g3ddfee87b4+9a10e1fe7b,g48712c4677+c9a099281a,g487adcacf7+f2e03ea30b,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+aead732c78,g64a986408d+eddffb812c,g858d7b2824+eddffb812c,g864b0138d7+aa38e45daa,g974c55ee3d+f37bf00e57,g99cad8db69+119519a52d,g9c22b2923f+e2510deafe,g9ddcbc5298+9a081db1e4,ga1e77700b3+03d07e1c1f,gb0e22166c9+60f28cb32d,gb23b769143+eddffb812c,gba4ed39666+c2a2e4ac27,gbb8dafda3b+27317ec8e9,gbd998247f1+585e252eca,gc120e1dc64+5817c176a8,gc28159a63d+c6a8a0fb72,gc3e9b769f7+6707aea8b4,gcf0d15dbbd+9a10e1fe7b,gdaeeff99f8+f9a426f77a,ge6526c86ff+6a2e01d432,ge79ae78c31+c6a8a0fb72,gee10cc3b42+585e252eca,gff1a9f87cc+eddffb812c,v27.0.0.rc1
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