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 Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
lsst::afw::table::CatalogT< RecordT > Class Template Reference

A custom container class for records, based on std::vector. More...

#include <Catalog.h>

Inheritance diagram for lsst::afw::table::CatalogT< RecordT >:
lsst::afw::table::SortedCatalogT< RecordT > lsst::afw::table::ExposureCatalogT< RecordT >

Public Types

typedef RecordT Record
 
typedef Record::Table Table
 
typedef Record::ColumnView ColumnView
 
typedef RecordT value_type
 
typedef RecordT & reference
 
typedef boost::shared_ptr
< RecordT > 
pointer
 
typedef Internal::size_type size_type
 
typedef Internal::difference_type difference_type
 
typedef CatalogIterator
< typename Internal::iterator > 
iterator
 
typedef CatalogIterator
< typename
Internal::const_iterator > 
const_iterator
 

Public Member Functions

boost::shared_ptr< TablegetTable () const
 Return the table associated with the catalog. More...
 
Schema getSchema () const
 Return the schema associated with the catalog's table. More...
 
 CatalogT (boost::shared_ptr< Table > const &table=boost::shared_ptr< Table >())
 Construct a catalog from a table (or nothing). More...
 
 CatalogT (Schema const &schema)
 Construct a catalog from a schema, creating a table with Table::make(schema). More...
 
template<typename InputIterator >
 CatalogT (boost::shared_ptr< Table > const &table, InputIterator first, InputIterator last, bool deep=false)
 Construct a catalog from a table and an iterator range. More...
 
 CatalogT (CatalogT const &other)
 Shallow copy constructor. More...
 
template<typename OtherRecordT >
 CatalogT (CatalogT< OtherRecordT > const &other)
 Shallow copy constructor from a container containing a related record type. More...
 
CatalogToperator= (CatalogT const &other)
 Shallow assigment. More...
 
CatalogT< RecordT > subset (ndarray::Array< bool const, 1 > const &mask) const
 Return the subset of a catalog corresponding to the True values of the given mask array. More...
 
CatalogT< RecordT > subset (std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const
 Returns a shallow copy of a subset of this Catalog. The arguments correspond to python's slice() syntax. More...
 
void writeFits (std::string const &filename, std::string const &mode="w", int flags=0) const
 Write a FITS binary table to a regular file. More...
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w", int flags=0) const
 Write a FITS binary table to a RAM file. More...
 
void writeFits (fits::Fits &fitsfile, int flags=0) const
 Write a FITS binary table to an open file object. More...
 
ColumnView getColumnView () const
 Return a ColumnView of this catalog's records. More...
 
bool isContiguous () const
 Return true if all records are contiguous. More...
 
bool empty () const
 Return true if the catalog has no records. More...
 
size_type size () const
 Return the number of elements in the catalog. More...
 
size_type max_size () const
 Return the maximum number of elements allowed in a catalog. More...
 
size_type capacity () const
 Return the capacity of the catalog. More...
 
void reserve (size_type n)
 Increase the capacity of the catalog to the given size. More...
 
reference operator[] (size_type i) const
 Return the record at index i. More...
 
reference at (size_type i) const
 Return the record at index i (throws std::out_of_range). More...
 
reference front () const
 Return the first record. More...
 
reference back () const
 Return the last record. More...
 
boost::shared_ptr< RecordT > const get (size_type i) const
 Return a pointer to the record at index i. More...
 
void set (size_type i, boost::shared_ptr< RecordT > const &p)
 Set the record at index i to a pointer. More...
 
template<typename InputIterator >
void assign (InputIterator first, InputIterator last, bool deep=false)
 Replace the contents of the table with an iterator range. More...
 
void push_back (Record const &r)
 Add a copy of the given record to the end of the catalog. More...
 
void push_back (boost::shared_ptr< RecordT > const &p)
 Add the given record to the end of the catalog without copying. More...
 
boost::shared_ptr< RecordT > addNew ()
 Create a new record, add it to the end of the catalog, and return a pointer to it. More...
 
void pop_back ()
 Remove the last record in the catalog. More...
 
CatalogT copy () const
 Deep-copy the catalog using a cloned table. More...
 
template<typename InputIterator >
void insert (iterator pos, InputIterator first, InputIterator last, bool deep=false)
 Insert an iterator range into the table. More...
 
template<typename InputIterator >
void insert (SchemaMapper const &mapper, iterator pos, InputIterator first, InputIterator last)
 Insert a range of records into the catalog by copying them with a SchemaMapper. More...
 
iterator insert (iterator pos, Record const &r)
 Insert a copy of the given record at the given position. More...
 
iterator insert (iterator pos, boost::shared_ptr< RecordT > const &p)
 Insert the given record at the given position without copying. More...
 
iterator erase (iterator pos)
 Erase the record pointed to by pos, and return an iterator the next record. More...
 
iterator erase (iterator first, iterator last)
 Erase the records in the range [first, last). More...
 
void swap (CatalogT &other)
 Shallow swap of two catalogs. More...
 
void clear ()
 Remove all records from the catalog. More...
 
template<typename T >
bool isSorted (Key< T > const &key) const
 Return true if the catalog is in ascending order according to the given key. More...
 
template<typename Compare >
bool isSorted (Compare cmp) const
 Return true if the catalog is in ascending order according to the given predicate. More...
 
template<typename T >
void sort (Key< T > const &key)
 Sort the catalog in-place by the field with the given key. More...
 
template<typename Compare >
void sort (Compare cmp)
 Sort the catalog in-place by the field with the given predicate. More...
 
template<typename T >
CatalogT< RecordT >::iterator find (typename Field< T >::Value const &value, Key< T > const &key)
 
template<typename T >
CatalogT< RecordT >::const_iterator find (typename Field< T >::Value const &value, Key< T > const &key) const
 
template<typename T >
CatalogT< RecordT >::iterator lower_bound (typename Field< T >::Value const &value, Key< T > const &key)
 
template<typename T >
CatalogT< RecordT >::const_iterator lower_bound (typename Field< T >::Value const &value, Key< T > const &key) const
 
template<typename T >
CatalogT< RecordT >::iterator upper_bound (typename Field< T >::Value const &value, Key< T > const &key)
 
template<typename T >
CatalogT< RecordT >::const_iterator upper_bound (typename Field< T >::Value const &value, Key< T > const &key) const
 
template<typename T >
std::pair< typename CatalogT
< RecordT >::iterator,
typename CatalogT< RecordT >
::iterator
equal_range (typename Field< T >::Value const &value, Key< T > const &key)
 
template<typename T >
std::pair< typename CatalogT
< RecordT >::const_iterator,
typename CatalogT< RecordT >
::const_iterator
equal_range (typename Field< T >::Value const &value, Key< T > const &key) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
template<typename T >
iterator find (typename Field< T >::Value const &value, Key< T > const &key)
 Return an iterator to the record with the given value. More...
 
template<typename T >
const_iterator find (typename Field< T >::Value const &value, Key< T > const &key) const
 Return an iterator to the record with the given value. More...
 
template<typename T >
iterator lower_bound (typename Field< T >::Value const &value, Key< T > const &key)
 Performed binary searches on sorted fields. More...
 
template<typename T >
const_iterator lower_bound (typename Field< T >::Value const &value, Key< T > const &key) const
 Performed binary searches on sorted fields. More...
 
template<typename T >
iterator upper_bound (typename Field< T >::Value const &value, Key< T > const &key)
 Performed binary searches on sorted fields. More...
 
template<typename T >
const_iterator upper_bound (typename Field< T >::Value const &value, Key< T > const &key) const
 Performed binary searches on sorted fields. More...
 
template<typename T >
std::pair< iterator, iteratorequal_range (typename Field< T >::Value const &value, Key< T > const &key)
 Performed binary searches on sorted fields. More...
 
template<typename T >
std::pair< const_iterator,
const_iterator
equal_range (typename Field< T >::Value const &value, Key< T > const &key) const
 Performed binary searches on sorted fields. More...
 
InternalgetInternal ()
 Return a reference to the internal vector-of-shared_ptr. More...
 
Internal const & getInternal () const
 Return a reference to the internal vector-of-shared_ptr. More...
 

Static Public Member Functions

static CatalogT readFits (std::string const &filename, int hdu=0, int flags=0)
 Read a FITS binary table from a regular file. More...
 
static CatalogT readFits (fits::MemFileManager &manager, int hdu=0, int flags=0)
 Read a FITS binary table from a RAM file. More...
 
static CatalogT readFits (fits::Fits &fitsfile, int flags=0)
 Read a FITS binary table from a file object already at the correct extension. More...
 

Private Types

typedef std::vector
< boost::shared_ptr< RecordT > > 
Internal
 

Private Member Functions

template<typename InputIterator >
void _maybeReserve (iterator &pos, InputIterator first, InputIterator last, bool deep, std::random_access_iterator_tag *)
 
template<typename InputIterator >
void _maybeReserve (iterator pos, InputIterator first, InputIterator last, bool deep, std::input_iterator_tag *)
 

Private Attributes

boost::shared_ptr< Table_table
 
Internal _internal
 

Detailed Description

template<typename RecordT>
class lsst::afw::table::CatalogT< RecordT >

A custom container class for records, based on std::vector.

CatalogT wraps a std::vector<PTR(RecordT)> in an interface that looks more like a std::vector<RecordT>; its iterators and accessors return references or const references, rather than pointers, making them easier to use. It also holds a table, which is used to allocate new records and determine the schema, but no checking is done to ensure that records added to the catalog use the same table or indeed have the same schema.

Because a CatalogT is holds shared_ptrs internally, many of its operations can be either shallow or deep, with new deep copies allocated by the catalog's table object. New records can be also be inserted by pointer (shallow) or by value (deep).

The constness of records is determined by the constness of the first template parameter to CatalogT; a container instance is always either const or non-const in that respect (like smart pointers). Also like smart pointers, const member functions (and by extension, const_iterators) do not allow the underlying pointers to be changed, while non-const member functions and iterators do.

CatalogT does not permit empty (null) pointers as elements. As a result, CatalogT has no resize member function.

CatalogT has a very different interface in Python; it mimics Python's list instead of C++'s std::vector. It is also considerably simpler, because it doesn't need to deal with iterator ranges or the distinction between references and shared_ptrs to records. See the Python docstring for more information.

Definition at line 94 of file Catalog.h.

Member Typedef Documentation

template<typename RecordT>
typedef Record::ColumnView lsst::afw::table::CatalogT< RecordT >::ColumnView

Definition at line 100 of file Catalog.h.

template<typename RecordT>
typedef CatalogIterator<typename Internal::const_iterator> lsst::afw::table::CatalogT< RecordT >::const_iterator

Definition at line 108 of file Catalog.h.

template<typename RecordT>
typedef Internal::difference_type lsst::afw::table::CatalogT< RecordT >::difference_type

Definition at line 106 of file Catalog.h.

template<typename RecordT>
typedef std::vector<boost::shared_ptr< RecordT > > lsst::afw::table::CatalogT< RecordT >::Internal
private

Definition at line 95 of file Catalog.h.

template<typename RecordT>
typedef CatalogIterator<typename Internal::iterator> lsst::afw::table::CatalogT< RecordT >::iterator

Definition at line 107 of file Catalog.h.

template<typename RecordT>
typedef boost::shared_ptr< RecordT > lsst::afw::table::CatalogT< RecordT >::pointer

Definition at line 104 of file Catalog.h.

template<typename RecordT>
typedef RecordT lsst::afw::table::CatalogT< RecordT >::Record

Definition at line 98 of file Catalog.h.

template<typename RecordT>
typedef RecordT& lsst::afw::table::CatalogT< RecordT >::reference

Definition at line 103 of file Catalog.h.

template<typename RecordT>
typedef Internal::size_type lsst::afw::table::CatalogT< RecordT >::size_type

Definition at line 105 of file Catalog.h.

template<typename RecordT>
typedef Record::Table lsst::afw::table::CatalogT< RecordT >::Table

Definition at line 99 of file Catalog.h.

template<typename RecordT>
typedef RecordT lsst::afw::table::CatalogT< RecordT >::value_type

Definition at line 102 of file Catalog.h.

Constructor & Destructor Documentation

template<typename RecordT>
lsst::afw::table::CatalogT< RecordT >::CatalogT ( boost::shared_ptr< Table > const &  table = boost::shared_ptr< Table >())
inlineexplicit

Construct a catalog from a table (or nothing).

A catalog with no table is considered invalid; a valid table must be assigned to it before it can be used.

Definition at line 122 of file Catalog.h.

122 : _table(table), _internal() {}
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
lsst::afw::table::CatalogT< RecordT >::CatalogT ( Schema const &  schema)
inlineexplicit

Construct a catalog from a schema, creating a table with Table::make(schema).

Definition at line 125 of file Catalog.h.

125 : _table(Table::make(schema)), _internal() {}
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
afw::table::Schema schema
Definition: GaussianPsf.cc:41
template<typename RecordT>
template<typename InputIterator >
lsst::afw::table::CatalogT< RecordT >::CatalogT ( boost::shared_ptr< Table > const &  table,
InputIterator  first,
InputIterator  last,
bool  deep = false 
)
inline

Construct a catalog from a table and an iterator range.

If deep is true, new records will be created using table->copyRecord before being inserted. If deep is false, records will be not be copied, but they must already be associated with the given table. The table itself is never deep-copied.

The iterator must dereference to a record reference or const reference rather than a pointer, but should be implicitly convertible to a record pointer as well (see CatalogIterator).

Definition at line 138 of file Catalog.h.

138  :
139  _table(table), _internal()
140  {
141  insert(end(), first, last, deep);
142  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:497
template<typename RecordT>
lsst::afw::table::CatalogT< RecordT >::CatalogT ( CatalogT< RecordT > const &  other)
inline

Shallow copy constructor.

Definition at line 145 of file Catalog.h.

145 : _table(other._table), _internal(other._internal) {}
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
template<typename OtherRecordT >
lsst::afw::table::CatalogT< RecordT >::CatalogT ( CatalogT< OtherRecordT > const &  other)
inline

Shallow copy constructor from a container containing a related record type.

This conversion only succeeds if OtherRecordT is convertible to RecordT and OtherTable is convertible to Table.

Definition at line 154 of file Catalog.h.

154  :
155  _table(other.getTable()), _internal(other.begin().base(), other.end().base())
156  {}
boost::shared_ptr< Table > _table
Definition: Catalog.h:678

Member Function Documentation

template<typename RecordT>
template<typename InputIterator >
void lsst::afw::table::CatalogT< RecordT >::_maybeReserve ( iterator pos,
InputIterator  first,
InputIterator  last,
bool  deep,
std::random_access_iterator_tag *   
)
inlineprivate

Definition at line 665 of file Catalog.h.

668  {
669  if (deep) _table->preallocate(last - first);
670  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
template<typename InputIterator >
void lsst::afw::table::CatalogT< RecordT >::_maybeReserve ( iterator  pos,
InputIterator  first,
InputIterator  last,
bool  deep,
std::input_iterator_tag *   
)
inlineprivate

Definition at line 673 of file Catalog.h.

676  {}
template<typename RecordT>
boost::shared_ptr< RecordT > lsst::afw::table::CatalogT< RecordT >::addNew ( )
inline

Create a new record, add it to the end of the catalog, and return a pointer to it.

Definition at line 469 of file Catalog.h.

469  {
470  PTR(RecordT) r = _table->makeRecord();
471  _internal.push_back(r);
472  return r;
473  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
#define PTR(...)
Definition: base.h:41
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:458
template<typename RecordT>
template<typename InputIterator >
void lsst::afw::table::CatalogT< RecordT >::assign ( InputIterator  first,
InputIterator  last,
bool  deep = false 
)
inline

Replace the contents of the table with an iterator range.

Delegates to insert(); look there for more information.

Definition at line 452 of file Catalog.h.

452  {
453  clear();
454  insert(end(), first, last, deep);
455  }
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:497
void clear()
Remove all records from the catalog.
Definition: Catalog.h:562
template<typename RecordT>
reference lsst::afw::table::CatalogT< RecordT >::at ( size_type  i) const
inline

Return the record at index i (throws std::out_of_range).

Definition at line 430 of file Catalog.h.

430 { return *_internal.at(i); }
template<typename RecordT>
reference lsst::afw::table::CatalogT< RecordT >::back ( ) const
inline

Return the last record.

Definition at line 436 of file Catalog.h.

436 { return *_internal.back(); }
template<typename RecordT>
iterator lsst::afw::table::CatalogT< RecordT >::begin ( )
inline

Iterator access.

See Also
CatalogIterator

Definition at line 391 of file Catalog.h.

391 { return iterator(_internal.begin()); }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
const_iterator lsst::afw::table::CatalogT< RecordT >::begin ( ) const
inline

Iterator access.

See Also
CatalogIterator

Definition at line 393 of file Catalog.h.

393 { return const_iterator(_internal.begin()); }
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:108
template<typename RecordT>
size_type lsst::afw::table::CatalogT< RecordT >::capacity ( ) const
inline

Return the capacity of the catalog.

This is computed as the sum of the current size and the unallocated space in the table. It does not reflect the size of the internal vector, and hence cannot be used to judge when iterators may be invalidated.

Definition at line 413 of file Catalog.h.

413 { return _internal.size() + _table->getBufferSize(); }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::clear ( )
inline

Remove all records from the catalog.

Definition at line 562 of file Catalog.h.

562 { _internal.clear(); }
template<typename RecordT>
CatalogT lsst::afw::table::CatalogT< RecordT >::copy ( ) const
inline

Deep-copy the catalog using a cloned table.

Definition at line 479 of file Catalog.h.

479 { return CatalogT(getTable()->clone(), begin(), end(), true); }
boost::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:111
CatalogT(boost::shared_ptr< Table > const &table=boost::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition: Catalog.h:122
template<typename RecordT>
bool lsst::afw::table::CatalogT< RecordT >::empty ( ) const
inline

Return true if the catalog has no records.

Definition at line 398 of file Catalog.h.

398 { return _internal.empty(); }
template<typename RecordT>
iterator lsst::afw::table::CatalogT< RecordT >::end ( )
inline

Iterator access.

See Also
CatalogIterator

Definition at line 392 of file Catalog.h.

392 { return iterator(_internal.end()); }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
const_iterator lsst::afw::table::CatalogT< RecordT >::end ( ) const
inline

Iterator access.

See Also
CatalogIterator

Definition at line 394 of file Catalog.h.

394 { return const_iterator(_internal.end()); }
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:108
template<typename RecordT>
template<typename T >
std::pair<iterator,iterator> lsst::afw::table::CatalogT< RecordT >::equal_range ( typename Field< T >::Value const &  value,
Key< T > const &  key 
)

Performed binary searches on sorted fields.

These methods perform binary searches analogous to the STL algorithms of the same name; they simply create a comparison functor using the given value and Key.

In Python, the lower_bound and upper_bound methods return the position of the result record in the catalog, and equal_range returns a Python slice object that defines the range.

Note
The catalog must be sorted in ascending order according to the given key before calling any of the search methods (i.e. isSorted(key) must be true).
template<typename RecordT>
template<typename T >
std::pair<const_iterator,const_iterator> lsst::afw::table::CatalogT< RecordT >::equal_range ( typename Field< T >::Value const &  value,
Key< T > const &  key 
) const

Performed binary searches on sorted fields.

These methods perform binary searches analogous to the STL algorithms of the same name; they simply create a comparison functor using the given value and Key.

In Python, the lower_bound and upper_bound methods return the position of the result record in the catalog, and equal_range returns a Python slice object that defines the range.

Note
The catalog must be sorted in ascending order according to the given key before calling any of the search methods (i.e. isSorted(key) must be true).
template<typename RecordT>
template<typename T >
std::pair<typename CatalogT<RecordT>::iterator,typename CatalogT<RecordT>::iterator> lsst::afw::table::CatalogT< RecordT >::equal_range ( typename Field< T >::Value const &  value,
Key< T > const &  key 
)

Definition at line 823 of file Catalog.h.

823  {
824  detail::KeyExtractionFunctor<RecordT,T> f = { key };
825  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
826  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,iterator> SearchIter;
827  std::pair<SearchIter,SearchIter> i
828  = std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
829  return std::make_pair(i.first.base(), i.second.base());
830 
831 }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
template<typename T >
std::pair<typename CatalogT<RecordT>::const_iterator,typename CatalogT<RecordT>::const_iterator> lsst::afw::table::CatalogT< RecordT >::equal_range ( typename Field< T >::Value const &  value,
Key< T > const &  key 
) const

Definition at line 836 of file Catalog.h.

836  {
837  detail::KeyExtractionFunctor<RecordT,T> f = { key };
838  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
839  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,const_iterator> SearchIter;
840  std::pair<SearchIter,SearchIter> i
841  = std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
842  return std::make_pair(i.first.base(), i.second.base());
843 }
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:108
template<typename RecordT>
iterator lsst::afw::table::CatalogT< RecordT >::erase ( iterator  pos)
inline

Erase the record pointed to by pos, and return an iterator the next record.

Definition at line 548 of file Catalog.h.

548 { return iterator(_internal.erase(pos.base())); }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
iterator lsst::afw::table::CatalogT< RecordT >::erase ( iterator  first,
iterator  last 
)
inline

Erase the records in the range [first, last).

Definition at line 551 of file Catalog.h.

551  {
552  return iterator(_internal.erase(first.base(), last.base()));
553  }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
template<typename T >
iterator lsst::afw::table::CatalogT< RecordT >::find ( typename Field< T >::Value const &  value,
Key< T > const &  key 
)

Return an iterator to the record with the given value.

When the field being searched is not unique, which matching record will be returned is not defined. In these cases, lower_bound, upper_bound, or equal_range should be used instead.

In Python, this method returns a Record, not an iterator.

Note
The catalog must be sorted in ascending order according to the given key before calling find (i.e. isSorted(key) must be true).

Returns end() if the Record cannot be found.

template<typename RecordT>
template<typename T >
const_iterator lsst::afw::table::CatalogT< RecordT >::find ( typename Field< T >::Value const &  value,
Key< T > const &  key 
) const

Return an iterator to the record with the given value.

When the field being searched is not unique, which matching record will be returned is not defined. In these cases, lower_bound, upper_bound, or equal_range should be used instead.

In Python, this method returns a Record, not an iterator.

Note
The catalog must be sorted in ascending order according to the given key before calling find (i.e. isSorted(key) must be true).

Returns end() if the Record cannot be found.

template<typename RecordT>
template<typename T >
CatalogT<RecordT>::iterator lsst::afw::table::CatalogT< RecordT >::find ( typename Field< T >::Value const &  value,
Key< T > const &  key 
)

Definition at line 753 of file Catalog.h.

753  {
754  detail::KeyExtractionFunctor<RecordT,T> f = { key };
755  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
756  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,iterator> SearchIter;
757  // Use binary search for log n search; requires sorted table.
758  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
759  if (i.base() == end() || *i != value) return end();
760  return i.base();
761 }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
template<typename T >
CatalogT<RecordT>::const_iterator lsst::afw::table::CatalogT< RecordT >::find ( typename Field< T >::Value const &  value,
Key< T > const &  key 
) const

Definition at line 766 of file Catalog.h.

766  {
767  detail::KeyExtractionFunctor<RecordT,T> f = { key };
768  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
769  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,const_iterator> SearchIter;
770  // Use binary search for log n search; requires sorted table.
771  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
772  if (i.base() == end() || *i != value) return end();
773  return i.base();
774 }
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:108
template<typename RecordT>
reference lsst::afw::table::CatalogT< RecordT >::front ( ) const
inline

Return the first record.

Definition at line 433 of file Catalog.h.

433 { return *_internal.front(); }
template<typename RecordT>
boost::shared_ptr< RecordT > const lsst::afw::table::CatalogT< RecordT >::get ( size_type  i) const
inline

Return a pointer to the record at index i.

Definition at line 439 of file Catalog.h.

439 { return _internal[i]; }
template<typename RecordT>
ColumnView lsst::afw::table::CatalogT< RecordT >::getColumnView ( ) const
inline

Return a ColumnView of this catalog's records.

Will throw RuntimeError if records are not contiguous.

Definition at line 371 of file Catalog.h.

371  {
372  if (boost::is_const<RecordT>::value) {
373  throw LSST_EXCEPT(
374  pex::exceptions::LogicError,
375  "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
376  "non-const views)."
377  );
378  }
379  return ColumnView::make(_table, begin(), end());
380  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename RecordT>
Internal& lsst::afw::table::CatalogT< RecordT >::getInternal ( )
inline

Return a reference to the internal vector-of-shared_ptr.

While in most cases it is more convenient to use the Catalog's iterators, which dereference directly to Record objects (and hence allow iter->method() rather than (**iter).method()), direct access to the underlying vector-of-shared_ptr is provided here to allow complete use of the C++ STL. In particular, in order to use a mutating STL algorithm on a Catalog in such a way that Records are shallow-copied (i.e. shared_ptr::operator= is invoked instead of Record::operator=), those algorithms should be called on the iterators of these internal containers. When an algorithm should be called in such a way that records are deep-copied, the regular Catalog iterators should be used.

Definition at line 658 of file Catalog.h.

658 { return _internal; }
template<typename RecordT>
Internal const& lsst::afw::table::CatalogT< RecordT >::getInternal ( ) const
inline

Return a reference to the internal vector-of-shared_ptr.

While in most cases it is more convenient to use the Catalog's iterators, which dereference directly to Record objects (and hence allow iter->method() rather than (**iter).method()), direct access to the underlying vector-of-shared_ptr is provided here to allow complete use of the C++ STL. In particular, in order to use a mutating STL algorithm on a Catalog in such a way that Records are shallow-copied (i.e. shared_ptr::operator= is invoked instead of Record::operator=), those algorithms should be called on the iterators of these internal containers. When an algorithm should be called in such a way that records are deep-copied, the regular Catalog iterators should be used.

Definition at line 659 of file Catalog.h.

659 { return _internal; }
template<typename RecordT>
Schema lsst::afw::table::CatalogT< RecordT >::getSchema ( ) const
inline

Return the schema associated with the catalog's table.

Definition at line 114 of file Catalog.h.

114 { return _table->getSchema(); }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
boost::shared_ptr< Table > lsst::afw::table::CatalogT< RecordT >::getTable ( ) const
inline

Return the table associated with the catalog.

Definition at line 111 of file Catalog.h.

111 { return _table; }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
template<typename InputIterator >
void lsst::afw::table::CatalogT< RecordT >::insert ( iterator  pos,
InputIterator  first,
InputIterator  last,
bool  deep = false 
)
inline

Insert an iterator range into the table.

InputIterator must dereference to a record reference that is convertible to the record type held by the catalog, and must be implicitly convertible to a shared_ptr to a record.

If deep is true, new records will be created by calling copyRecord on the catalog's table. If deep is false, the new records will not be copied, but they must have been created with the catalog's table (note that a table may be shared by multiple catalogs).

If InputIterator models RandomAccessIterator (according to std::iterator_traits) and deep is true, table->preallocate will be used to ensure that the resulting records are contiguous in memory and can be used with ColumnView. To ensure this is the case for other iterator types, the user must preallocate the table manually.

Definition at line 497 of file Catalog.h.

497  {
499  pos, first, last, deep, (typename std::iterator_traits<InputIterator>::iterator_category*)0
500  );
501  if (deep) {
502  while (first != last) {
503  pos = insert(pos, *first);
504  ++pos;
505  ++first;
506  }
507  } else {
508  while (first != last) {
509  pos = insert(pos, first);
510  assert(pos != end());
511  ++pos;
512  ++first;
513  }
514  }
515  }
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:497
void _maybeReserve(iterator &pos, InputIterator first, InputIterator last, bool deep, std::random_access_iterator_tag *)
Definition: Catalog.h:665
template<typename RecordT>
template<typename InputIterator >
void lsst::afw::table::CatalogT< RecordT >::insert ( SchemaMapper const &  mapper,
iterator  pos,
InputIterator  first,
InputIterator  last 
)
inline

Insert a range of records into the catalog by copying them with a SchemaMapper.

Definition at line 519 of file Catalog.h.

519  {
520  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
521  throw LSST_EXCEPT(
522  pex::exceptions::InvalidParameterError,
523  "SchemaMapper's output schema does not match catalog's schema"
524  );
525  }
527  pos, first, last, true, (typename std::iterator_traits<InputIterator>::iterator_category*)0
528  );
529  while (first != last) {
530  pos = insert(pos, _table->copyRecord(*first, mapper));
531  ++pos;
532  ++first;
533  }
534  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:497
void _maybeReserve(iterator &pos, InputIterator first, InputIterator last, bool deep, std::random_access_iterator_tag *)
Definition: Catalog.h:665
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
template<typename RecordT>
iterator lsst::afw::table::CatalogT< RecordT >::insert ( iterator  pos,
Record const &  r 
)
inline

Insert a copy of the given record at the given position.

Definition at line 537 of file Catalog.h.

537  {
538  PTR(RecordT) p = _table->copyRecord(r);
539  return iterator(_internal.insert(pos.base(), p));
540  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
#define PTR(...)
Definition: base.h:41
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:497
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
iterator lsst::afw::table::CatalogT< RecordT >::insert ( iterator  pos,
boost::shared_ptr< RecordT > const &  p 
)
inline

Insert the given record at the given position without copying.

Definition at line 543 of file Catalog.h.

543  {
544  return iterator(_internal.insert(pos.base(), p));
545  }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
bool lsst::afw::table::CatalogT< RecordT >::isContiguous ( ) const
inline

Return true if all records are contiguous.

Definition at line 383 of file Catalog.h.

383 { return ColumnView::isRangeContiguous(_table, begin(), end()); }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT >
template<typename T >
bool lsst::afw::table::CatalogT< RecordT >::isSorted ( Key< T > const &  key) const

Return true if the catalog is in ascending order according to the given key.

Definition at line 738 of file Catalog.h.

738  {
739  detail::KeyComparisonFunctor<RecordT,T> f = { key };
740  return isSorted(f);
741 }
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition: Catalog.h:738
template<typename RecordT >
template<typename Compare >
bool lsst::afw::table::CatalogT< RecordT >::isSorted ( Compare  cmp) const

Return true if the catalog is in ascending order according to the given predicate.

cmp(a, b) should return true if record a is less than record b, and false otherwise.

TODO: C++11 has an is_sorted function we should use when available.

Definition at line 716 of file Catalog.h.

716  {
718  detail::ComparisonAdaptor<RecordT,Compare> f = { cmp };
719  if (empty()) return true;
720  const_iterator last = this->begin();
721  const_iterator i = last; ++i;
722  for (; i != this->end(); ++i) {
723  if (f(i, last)) return false;
724  last = i;
725  }
726  return true;
727 }
bool empty() const
Return true if the catalog has no records.
Definition: Catalog.h:398
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:108
template<typename RecordT>
template<typename T >
iterator lsst::afw::table::CatalogT< RecordT >::lower_bound ( typename Field< T >::Value const &  value,
Key< T > const &  key 
)

Performed binary searches on sorted fields.

These methods perform binary searches analogous to the STL algorithms of the same name; they simply create a comparison functor using the given value and Key.

In Python, the lower_bound and upper_bound methods return the position of the result record in the catalog, and equal_range returns a Python slice object that defines the range.

Note
The catalog must be sorted in ascending order according to the given key before calling any of the search methods (i.e. isSorted(key) must be true).
template<typename RecordT>
template<typename T >
const_iterator lsst::afw::table::CatalogT< RecordT >::lower_bound ( typename Field< T >::Value const &  value,
Key< T > const &  key 
) const

Performed binary searches on sorted fields.

These methods perform binary searches analogous to the STL algorithms of the same name; they simply create a comparison functor using the given value and Key.

In Python, the lower_bound and upper_bound methods return the position of the result record in the catalog, and equal_range returns a Python slice object that defines the range.

Note
The catalog must be sorted in ascending order according to the given key before calling any of the search methods (i.e. isSorted(key) must be true).
template<typename RecordT>
template<typename T >
CatalogT<RecordT>::iterator lsst::afw::table::CatalogT< RecordT >::lower_bound ( typename Field< T >::Value const &  value,
Key< T > const &  key 
)

Definition at line 779 of file Catalog.h.

779  {
780  detail::KeyExtractionFunctor<RecordT,T> f = { key };
781  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
782  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,iterator> SearchIter;
783  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
784  return i.base();
785 }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
template<typename T >
CatalogT<RecordT>::const_iterator lsst::afw::table::CatalogT< RecordT >::lower_bound ( typename Field< T >::Value const &  value,
Key< T > const &  key 
) const

Definition at line 790 of file Catalog.h.

790  {
791  detail::KeyExtractionFunctor<RecordT,T> f = { key };
792  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
793  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,const_iterator> SearchIter;
794  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
795  return i.base();
796 }
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:108
template<typename RecordT>
size_type lsst::afw::table::CatalogT< RecordT >::max_size ( ) const
inline

Return the maximum number of elements allowed in a catalog.

Definition at line 404 of file Catalog.h.

404 { return _internal.max_size(); }
template<typename RecordT>
CatalogT& lsst::afw::table::CatalogT< RecordT >::operator= ( CatalogT< RecordT > const &  other)
inline

Shallow assigment.

Definition at line 159 of file Catalog.h.

159  {
160  if (&other != this) {
161  _table = other._table;
162  _internal = other._internal;
163  }
164  return *this;
165  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
reference lsst::afw::table::CatalogT< RecordT >::operator[] ( size_type  i) const
inline

Return the record at index i.

Definition at line 427 of file Catalog.h.

427 { return *_internal[i]; }
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::pop_back ( )
inline

Remove the last record in the catalog.

Definition at line 476 of file Catalog.h.

476 { _internal.pop_back(); }
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::push_back ( Record const &  r)
inline

Add a copy of the given record to the end of the catalog.

Definition at line 458 of file Catalog.h.

458  {
459  PTR(RecordT) p = _table->copyRecord(r);
460  _internal.push_back(p);
461  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
#define PTR(...)
Definition: base.h:41
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:458
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::push_back ( boost::shared_ptr< RecordT > const &  p)
inline

Add the given record to the end of the catalog without copying.

Definition at line 464 of file Catalog.h.

464  {
465  _internal.push_back(p);
466  }
template<typename RecordT>
static CatalogT lsst::afw::table::CatalogT< RecordT >::readFits ( std::string const &  filename,
int  hdu = 0,
int  flags = 0 
)
inlinestatic

Read a FITS binary table from a regular file.

Parameters
[in]filenameName of the file to read.
[in]hduNumber of the "header-data unit" to read (where 1 is the Primary HDU). The default value of 0 is interpreted as "the first HDU with NAXIS != 0".
[in]flagsTable-subclass-dependent bitflags that control the details of how to read the catalog. See e.g. SourceFitsFlags.

Definition at line 338 of file Catalog.h.

338  {
339  return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
340  }
template<typename RecordT>
static CatalogT lsst::afw::table::CatalogT< RecordT >::readFits ( fits::MemFileManager manager,
int  hdu = 0,
int  flags = 0 
)
inlinestatic

Read a FITS binary table from a RAM file.

Parameters
[in]managerObject that manages the memory to be read.
[in]hduNumber of the "header-data unit" to read (where 1 is the Primary HDU). The default value of 0 is interpreted as "the first HDU with NAXIS != 0".
[in]flagsTable-subclass-dependent bitflags that control the details of how to read the catalog. See e.g. SourceFitsFlags.

Definition at line 351 of file Catalog.h.

351  {
352  return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
353  }
template<typename RecordT>
static CatalogT lsst::afw::table::CatalogT< RecordT >::readFits ( fits::Fits fitsfile,
int  flags = 0 
)
inlinestatic

Read a FITS binary table from a file object already at the correct extension.

Parameters
[in]fitsfileFits file object to read from.
[in]flagsTable-subclass-dependent bitflags that control the details of how to read the catalog. See e.g. SourceFitsFlags.

Definition at line 362 of file Catalog.h.

362  {
363  return io::FitsReader::apply<CatalogT>(fitsfile, flags);
364  }
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::reserve ( size_type  n)
inline

Increase the capacity of the catalog to the given size.

This can be used to guarantee that the catalog will be contiguous, but it only affects records constructed after reserve().

Definition at line 421 of file Catalog.h.

421  {
422  if (n <= _internal.size()) return;
423  _table->preallocate(n - _internal.size());
424  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::set ( size_type  i,
boost::shared_ptr< RecordT > const &  p 
)
inline

Set the record at index i to a pointer.

Definition at line 442 of file Catalog.h.

442  {
443  _internal[i] = p;
444  }
template<typename RecordT>
size_type lsst::afw::table::CatalogT< RecordT >::size ( ) const
inline

Return the number of elements in the catalog.

Definition at line 401 of file Catalog.h.

401 { return _internal.size(); }
template<typename RecordT >
template<typename T >
void lsst::afw::table::CatalogT< RecordT >::sort ( Key< T > const &  key)

Sort the catalog in-place by the field with the given key.

Definition at line 745 of file Catalog.h.

745  {
746  detail::KeyComparisonFunctor<RecordT,T> f = { key };
747  return sort(f);
748 }
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:745
template<typename RecordT >
template<typename Compare >
void lsst::afw::table::CatalogT< RecordT >::sort ( Compare  cmp)

Sort the catalog in-place by the field with the given predicate.

cmp(a, b) should return true if record a is less than record b, and false otherwise.

Definition at line 731 of file Catalog.h.

731  {
732  detail::ComparisonAdaptor<RecordT,Compare> f = { cmp };
733  std::stable_sort(_internal.begin(), _internal.end(), f);
734 }
template<typename RecordT>
CatalogT<RecordT> lsst::afw::table::CatalogT< RecordT >::subset ( ndarray::Array< bool const, 1 > const &  mask) const
inline

Return the subset of a catalog corresponding to the True values of the given mask array.

The returned array's records are shallow copies, and hence will not in general be contiguous.

Definition at line 172 of file Catalog.h.

172  {
173  if (size_type(mask.size()) != size()) {
174  throw LSST_EXCEPT(
175  pex::exceptions::LengthError,
176  (boost::format("Mask array with %d elements applied to catalog with %d elements")
177  % mask.size() % size()).str()
178  );
179  }
180  CatalogT<RecordT> result(getTable());
182  const_iterator catIter = begin();
183  for (; maskIter != mask.end(); ++maskIter, ++catIter) {
184  if (*maskIter) result.push_back(catIter);
185  }
186  return result;
187  }
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:401
Internal::size_type size_type
Definition: Catalog.h:105
size_type size() const
Return the size of the first dimension.
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:108
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Iterator end() const
Return an Iterator to one past the end of the array.
Definition: ArrayBase.h:108
boost::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:111
ExpressionTraits< Derived >::Iterator Iterator
Nested expression or element iterator.
Iterator begin() const
Return an Iterator to the beginning of the array.
Definition: ArrayBase.h:99
template<typename RecordT>
CatalogT<RecordT> lsst::afw::table::CatalogT< RecordT >::subset ( std::ptrdiff_t  startd,
std::ptrdiff_t  stopd,
std::ptrdiff_t  step 
) const
inline

Returns a shallow copy of a subset of this Catalog. The arguments correspond to python's slice() syntax.

Definition at line 193 of file Catalog.h.

193  {
194  /* Python's slicing syntax is weird and wonderful.
195 
196  Both the "start" and "stop" indices can be negative, which means the
197  abs() of the index less than the size; [-1] means the last item.
198  Moreover, it's possible to have a negative index less than -len(); it
199  will get clipped. That is in fact one way to slice *backward* through
200  the array *and* include element 0;
201 
202  >>> range(10)[5:-20:-1]
203  [5, 4, 3, 2, 1, 0]
204 
205  The clipping tests in this function look more complicated than they
206  need to be, but that is partly because there are some weird edge cases.
207 
208  Also, ptrdiff_t vs size_t introduces some annoying complexity. Note
209  that the args are "startd"/"stopd" (not "start"/"stop").
210 
211  There is a fairly complete set of tests in tests/ticket2026.py; if you
212  try to simplify this function, be sure they continue to pass.
213  */
214  size_type S = size();
215  size_type start, stop = 0;
216  // Python doesn't allow step == 0
217  if (step == 0) {
218  throw LSST_EXCEPT(
219  pex::exceptions::InvalidParameterError,
220  "Step cannot be zero"
221  );
222  }
223  // Basic negative indexing rule: first add size
224  if (startd < 0) {
225  startd += S;
226  }
227  if (stopd < 0) {
228  stopd += S;
229  }
230  // Start gets clipped to zero; stop does not (yet).
231  if (startd < 0) {
232  startd = 0;
233  }
234  // Now start is non-negative, so can cast to size_t.
235  start = (size_type)startd;
236  if (start > S) {
237  start = S;
238  }
239  if (step > 0) {
240  // When stepping forward, stop gets clipped at zero,
241  // so is non-negative and can get cast to size_t.
242  if (stopd < 0) {
243  stopd = 0;
244  }
245  stop = (size_type)stopd;
246  if (stop > S) {
247  stop = S;
248  }
249  } else if (step < 0) {
250  // When stepping backward, stop gets clipped at -1 so that slices
251  // including 0 are possible.
252  if (stopd < 0) {
253  stopd = -1;
254  }
255  }
256 
257  if (((step > 0) && (start >= stop)) ||
258  ((step < 0) && ((std::ptrdiff_t)start <= stopd))) {
259  // Empty range
260  return CatalogT<RecordT>(getTable(), begin(), begin());
261  }
262 
263  if (step == 1) {
264  // Use the iterator-based constructor for this simple case
265  assert(start >= 0);
266  assert(stop > 0);
267  assert(start < S);
268  assert(stop <= S);
269  return CatalogT<RecordT>(getTable(), begin()+start, begin()+stop);
270  }
271 
272  // Build a new CatalogT and copy records into it.
273  CatalogT<RecordT> cat(getTable());
274  size_type N = 0;
275  if (step >= 0) {
276  N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
277  } else {
278  N = (size_t)((stopd - (std::ptrdiff_t)start) / step +
279  (((stopd - (std::ptrdiff_t)start) % step) ? 1 : 0));
280  }
281  cat.reserve(N);
282  if (step >= 0) {
283  for (size_type i=start; i<stop; i+=step) {
284  cat.push_back(get(i));
285  }
286  } else {
287  for (std::ptrdiff_t i=(std::ptrdiff_t)start; i>stopd; i+=step) {
288  cat.push_back(get(i));
289  }
290  }
291  return cat;
292  }
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:401
Internal::size_type size_type
Definition: Catalog.h:105
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:111
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::swap ( CatalogT< RecordT > &  other)
inline

Shallow swap of two catalogs.

Definition at line 556 of file Catalog.h.

556  {
557  _table.swap(other._table);
558  _internal.swap(other._internal);
559  }
boost::shared_ptr< Table > _table
Definition: Catalog.h:678
template<typename RecordT>
template<typename T >
iterator lsst::afw::table::CatalogT< RecordT >::upper_bound ( typename Field< T >::Value const &  value,
Key< T > const &  key 
)

Performed binary searches on sorted fields.

These methods perform binary searches analogous to the STL algorithms of the same name; they simply create a comparison functor using the given value and Key.

In Python, the lower_bound and upper_bound methods return the position of the result record in the catalog, and equal_range returns a Python slice object that defines the range.

Note
The catalog must be sorted in ascending order according to the given key before calling any of the search methods (i.e. isSorted(key) must be true).
template<typename RecordT>
template<typename T >
const_iterator lsst::afw::table::CatalogT< RecordT >::upper_bound ( typename Field< T >::Value const &  value,
Key< T > const &  key 
) const

Performed binary searches on sorted fields.

These methods perform binary searches analogous to the STL algorithms of the same name; they simply create a comparison functor using the given value and Key.

In Python, the lower_bound and upper_bound methods return the position of the result record in the catalog, and equal_range returns a Python slice object that defines the range.

Note
The catalog must be sorted in ascending order according to the given key before calling any of the search methods (i.e. isSorted(key) must be true).
template<typename RecordT>
template<typename T >
CatalogT<RecordT>::iterator lsst::afw::table::CatalogT< RecordT >::upper_bound ( typename Field< T >::Value const &  value,
Key< T > const &  key 
)

Definition at line 801 of file Catalog.h.

801  {
802  detail::KeyExtractionFunctor<RecordT,T> f = { key };
803  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
804  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,iterator> SearchIter;
805  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
806  return i.base();
807 }
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:107
template<typename RecordT>
template<typename T >
CatalogT<RecordT>::const_iterator lsst::afw::table::CatalogT< RecordT >::upper_bound ( typename Field< T >::Value const &  value,
Key< T > const &  key 
) const

Definition at line 812 of file Catalog.h.

812  {
813  detail::KeyExtractionFunctor<RecordT,T> f = { key };
814  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
815  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,const_iterator> SearchIter;
816  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
817  return i.base();
818 }
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:108
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::writeFits ( std::string const &  filename,
std::string const &  mode = "w",
int  flags = 0 
) const
inline

Write a FITS binary table to a regular file.

Parameters
[in]filenameName of the file to write.
[in]mode"a" to append a new HDU, "w" to overwrite any existing file.
[in]flagsTable-subclass-dependent bitflags that control the details of how to read the catalogs. See e.g. SourceFitsFlags.

Definition at line 302 of file Catalog.h.

302  {
303  io::FitsWriter::apply(filename, mode, *this, flags);
304  }
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:35
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::writeFits ( fits::MemFileManager manager,
std::string const &  mode = "w",
int  flags = 0 
) const
inline

Write a FITS binary table to a RAM file.

Parameters
[in,out]managerObject that manages the memory to write to.
[in]mode"a" to append a new HDU, "w" to overwrite any existing file.
[in]flagsTable-subclass-dependent bitflags that control the details of how to read the catalogs. See e.g. SourceFitsFlags.

Definition at line 314 of file Catalog.h.

314  {
315  io::FitsWriter::apply(manager, mode, *this, flags);
316  }
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:35
template<typename RecordT>
void lsst::afw::table::CatalogT< RecordT >::writeFits ( fits::Fits fitsfile,
int  flags = 0 
) const
inline

Write a FITS binary table to an open file object.

Parameters
[in,out]fitsfileFits file object to write to.
[in]flagsTable-subclass-dependent bitflags that control the details of how to read the catalogs. See e.g. SourceFitsFlags.

Definition at line 325 of file Catalog.h.

325  {
326  io::FitsWriter::apply(fitsfile, *this, flags);
327  }
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:35

Member Data Documentation

template<typename RecordT>
Internal lsst::afw::table::CatalogT< RecordT >::_internal
private

Definition at line 679 of file Catalog.h.

template<typename RecordT>
boost::shared_ptr< Table > lsst::afw::table::CatalogT< RecordT >::_table
private

Definition at line 678 of file Catalog.h.


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