LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Friends | List of all members
lsst::afw::table::BaseColumnView Class Reference

Column-wise view into a sequence of records that have been allocated contiguously. More...

#include <BaseColumnView.h>

Inheritance diagram for lsst::afw::table::BaseColumnView:
lsst::afw::table::ColumnViewT< RecordT > lsst::afw::table::SourceColumnViewT< RecordT >

Public Member Functions

boost::shared_ptr< BaseTablegetTable () const
 Return the table that owns the records. More...
 
Schema getSchema () const
 Return the schema that defines the fields. More...
 
template<typename T >
ndarray::ArrayRef< T, 1 > const operator[] (Key< T > const &key) const
 Return a 1-d array corresponding to a scalar field (or subfield). More...
 
template<typename T >
ndarray::ArrayRef< T, 2, 1 > const operator[] (Key< Array< T > > const &key) const
 Return a 2-d array corresponding to an array field. More...
 
ndarray::result_of::vectorize
< detail::FlagExtractor,
ndarray::Array< Field< Flag >
::Element const, 1 > >::type 
operator[] (Key< Flag > const &key) const
 Return a 1-d array expression corresponding to a flag bit. More...
 
BitsColumn getBits (std::vector< Key< Flag > > const &keys) const
 Return an integer array with the given Flag fields repacked into individual bits. More...
 
BitsColumn getAllBits () const
 Return an integer array with all Flag fields repacked into individual bits. More...
 
 ~BaseColumnView ()
 

Static Public Member Functions

template<typename InputIterator >
static BaseColumnView make (boost::shared_ptr< BaseTable > const &table, InputIterator first, InputIterator last)
 Construct a BaseColumnView from an iterator range. More...
 
template<typename InputIterator >
static bool isRangeContiguous (boost::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 table. More...
 

Protected Member Functions

 BaseColumnView (boost::shared_ptr< BaseTable > const &table, int recordCount, void *buf, ndarray::Manager::Ptr const &manager)
 

Private Attributes

boost::shared_ptr< Impl > _impl
 

Friends

class BaseTable
 

Detailed Description

Column-wise view into a sequence of records that have been allocated contiguously.

A BaseColumnView can be created from any iterator range that dereferences to records, as long as those records' field data is contiguous in memory. In practice, that means they must have been created from the same table, and be in the same order they were created (with no deletions). It also requires that those records be allocated in the same block, which can be guaranteed with BaseTable::preallocate().

Geometric (point and shape) fields cannot be accessed through a BaseColumnView, but their scalar components can be.

BaseColumnView and its subclasses are always non-const views into a catalog, and so cannot be obtained from a catalog-of-const (trying this results in an exception, not a compilation error). As a result, all its accessors return arrays of non-const elements, even though they are themselves const member functions. This is no different from a shared_ptr<T>'s get() member function returning a non-const T*, even though get() is a const member function.

Definition at line 83 of file BaseColumnView.h.

Constructor & Destructor Documentation

lsst::afw::table::BaseColumnView::~BaseColumnView ( )
lsst::afw::table::BaseColumnView::BaseColumnView ( boost::shared_ptr< BaseTable > const &  table,
int  recordCount,
void *  buf,
ndarray::Manager::Ptr const &  manager 
)
protected

Member Function Documentation

BitsColumn lsst::afw::table::BaseColumnView::getAllBits ( ) const

Return an integer array with all Flag fields repacked into individual bits.

The returned object contains both the int64 array and accessors to obtain a mask given a Key or field name.

Exceptions
pex::exceptions::LengthErrorif the schema has more than 64 Flag fields.
BitsColumn lsst::afw::table::BaseColumnView::getBits ( std::vector< Key< Flag > > const &  keys) const

Return an integer array with the given Flag fields repacked into individual bits.

The returned object contains both the int64 array and accessors to obtain a mask given a Key or field name.

Exceptions
pex::exceptions::LengthErrorif keys.size() > 64
Schema lsst::afw::table::BaseColumnView::getSchema ( ) const
inline

Return the schema that defines the fields.

Definition at line 90 of file BaseColumnView.h.

90 { return getTable()->getSchema(); }
boost::shared_ptr< BaseTable > getTable() const
Return the table that owns the records.
boost::shared_ptr< BaseTable > lsst::afw::table::BaseColumnView::getTable ( ) const

Return the table that owns the records.

template<typename InputIterator >
bool lsst::afw::table::BaseColumnView::isRangeContiguous ( boost::shared_ptr< BaseTable > const &  table,
InputIterator  first,
InputIterator  last 
)
static

Return true if the given record iterator range is continuous and the records all belong to the given table.

This tests exactly the same requiremetns needed to construct a column view, so if this test succeeds, BaseColumnView::make should as well.

Definition at line 212 of file BaseColumnView.h.

214  {
215  if (first == last) return true;
216  Schema schema = table->getSchema();
217  std::size_t recordSize = schema.getRecordSize();
218  std::size_t recordCount = 1;
219  void * buf = first->_data;
220  ndarray::Manager::Ptr manager = first->_manager;
221  char * expected = reinterpret_cast<char*>(buf) + recordSize;
222  for (++first; first != last; ++first, ++recordCount, expected += recordSize) {
223  if (first->_data != expected || first->_manager != manager) {
224  return false;
225  }
226  }
227  return true;
228 }
afw::table::Schema schema
Definition: GaussianPsf.cc:41
boost::intrusive_ptr< Manager > Ptr
Definition: Manager.h:42
template<typename InputIterator >
BaseColumnView lsst::afw::table::BaseColumnView::make ( boost::shared_ptr< BaseTable > const &  table,
InputIterator  first,
InputIterator  last 
)
static

Construct a BaseColumnView from an iterator range.

The iterators must dereference to a reference or const reference to a record. If the record data is not contiguous in memory, throws lsst::pex::exceptions::RuntimeError.

Definition at line 190 of file BaseColumnView.h.

190  {
191  if (first == last) {
192  return BaseColumnView(table, 0, 0, ndarray::Manager::Ptr());
193  }
194  Schema schema = table->getSchema();
195  std::size_t recordSize = schema.getRecordSize();
196  std::size_t recordCount = 1;
197  void * buf = first->_data;
198  ndarray::Manager::Ptr manager = first->_manager;
199  char * expected = reinterpret_cast<char*>(buf) + recordSize;
200  for (++first; first != last; ++first, ++recordCount, expected += recordSize) {
201  if (first->_data != expected || first->_manager != manager) {
202  throw LSST_EXCEPT(
203  lsst::pex::exceptions::RuntimeError,
204  "Record data is not contiguous in memory."
205  );
206  }
207  }
208  return BaseColumnView(table, recordCount, buf, manager);
209 }
afw::table::Schema schema
Definition: GaussianPsf.cc:41
BaseColumnView(boost::shared_ptr< BaseTable > const &table, int recordCount, void *buf, ndarray::Manager::Ptr const &manager)
boost::intrusive_ptr< Manager > Ptr
Definition: Manager.h:42
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename T >
ndarray::ArrayRef<T,1> const lsst::afw::table::BaseColumnView::operator[] ( Key< T > const &  key) const

Return a 1-d array corresponding to a scalar field (or subfield).

template<typename T >
ndarray::ArrayRef<T,2,1> const lsst::afw::table::BaseColumnView::operator[] ( Key< Array< T > > const &  key) const

Return a 2-d array corresponding to an array field.

ndarray::result_of::vectorize< detail::FlagExtractor, ndarray::Array< Field<Flag>::Element const,1> >::type lsst::afw::table::BaseColumnView::operator[] ( Key< Flag > const &  key) const

Return a 1-d array expression corresponding to a flag bit.

In C++, the return value is a lazy ndarray expression template that performs the bitwise & operation on every element when that element is requested. In Python, the result will be copied into a bool NumPy array.

Friends And Related Function Documentation

friend class BaseTable
friend

Definition at line 160 of file BaseColumnView.h.

Member Data Documentation

boost::shared_ptr<Impl> lsst::afw::table::BaseColumnView::_impl
private

Definition at line 162 of file BaseColumnView.h.


The documentation for this class was generated from the following file: