LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+f5613e8b4f,g1470d8bcf6+190ad2ba91,g14a832a312+311607e4ab,g2079a07aa2+86d27d4dc4,g2305ad1205+a8e3196225,g295015adf3+b67ee847e5,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+a761f810f3,g487adcacf7+17c8fdbcbd,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+65b5bd823e,g5a732f18d5+53520f316c,g64a986408d+f5613e8b4f,g6c1bc301e9+51106c2951,g858d7b2824+f5613e8b4f,g8a8a8dda67+585e252eca,g99cad8db69+6729933424,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+ef4e3a5875,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e9bba80f27,gc120e1dc64+eee469a5e5,gc28159a63d+0e5473021a,gcf0d15dbbd+a761f810f3,gdaeeff99f8+f9a426f77a,ge6526c86ff+d4c1d4bfef,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf1cff7945b+f5613e8b4f,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | 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

using Record = RecordT
 
using Table = typename Record::Table
 
using ColumnView = typename Record::ColumnView
 
using reference = RecordT &
 
using pointer = std::shared_ptr<RecordT>
 
using size_type = typename Internal::size_type
 
using difference_type = typename Internal::difference_type
 
using iterator = CatalogIterator<typename Internal::iterator>
 
using const_iterator = CatalogIterator<typename Internal::const_iterator>
 

Public Member Functions

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

Static Public Member Functions

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

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<std::shared_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 98 of file Catalog.h.

Member Typedef Documentation

◆ ColumnView

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

Definition at line 104 of file Catalog.h.

◆ const_iterator

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

Definition at line 111 of file Catalog.h.

◆ difference_type

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

Definition at line 109 of file Catalog.h.

◆ iterator

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

Definition at line 110 of file Catalog.h.

◆ pointer

Definition at line 107 of file Catalog.h.

◆ Record

template<typename RecordT >
using lsst::afw::table::CatalogT< RecordT >::Record = RecordT

Definition at line 102 of file Catalog.h.

◆ reference

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

Definition at line 106 of file Catalog.h.

◆ size_type

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

Definition at line 108 of file Catalog.h.

◆ Table

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

Definition at line 103 of file Catalog.h.

Constructor & Destructor Documentation

◆ CatalogT() [1/6]

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

Construct a catalog from a table (or nothing).

A table is always initialized with a minimal schema.

Definition at line 124 of file Catalog.h.

125 : _table(table), _internal() {
126 if(!_table) {
127 auto schema=Table::makeMinimalSchema();
128 _table=Table::make(schema);
129 }
130 }

◆ CatalogT() [2/6]

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 133 of file Catalog.h.

133: _table(Table::make(schema)), _internal() {}

◆ CatalogT() [3/6]

template<typename RecordT >
template<typename InputIterator >
lsst::afw::table::CatalogT< RecordT >::CatalogT ( std::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 146 of file Catalog.h.

147 : _table(table), _internal() {
148 insert(end(), first, last, deep);
149 }
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition Catalog.h:517

◆ CatalogT() [4/6]

template<typename RecordT >
lsst::afw::table::CatalogT< RecordT >::CatalogT ( CatalogT< RecordT > const & other)
inline

Shallow copy constructor.

Definition at line 152 of file Catalog.h.

152: _table(other._table), _internal(other._internal) {}

◆ CatalogT() [5/6]

template<typename RecordT >
lsst::afw::table::CatalogT< RecordT >::CatalogT ( CatalogT< RecordT > && other)
inline

Definition at line 154 of file Catalog.h.

154: CatalogT(other) {}
CatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition Catalog.h:124

◆ ~CatalogT()

template<typename RecordT >
lsst::afw::table::CatalogT< RecordT >::~CatalogT ( )
default

◆ CatalogT() [6/6]

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 165 of file Catalog.h.

166 : _table(other.getTable()), _internal(other.begin().base(), other.end().base()) {}

Member Function Documentation

◆ addNew()

template<typename RecordT >
std::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 489 of file Catalog.h.

489 {
490 std::shared_ptr<RecordT> r = _table->makeRecord();
491 _internal.push_back(r);
492 return r;
493 }
T push_back(T... args)

◆ assign()

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 474 of file Catalog.h.

474 {
475 clear();
476 insert(end(), first, last, deep);
477 }
void clear()
Remove all records from the catalog.
Definition Catalog.h:578

◆ at()

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 454 of file Catalog.h.

454{ return *_internal.at(i); }
T at(T... args)

◆ back()

template<typename RecordT >
reference lsst::afw::table::CatalogT< RecordT >::back ( ) const
inline

Return the last record.

Definition at line 460 of file Catalog.h.

460{ return *_internal.back(); }
T back(T... args)

◆ begin() [1/2]

template<typename RecordT >
iterator lsst::afw::table::CatalogT< RecordT >::begin ( )
inline

Iterator access.

See also
CatalogIterator

Definition at line 400 of file Catalog.h.

400{ return iterator(_internal.begin()); }
T begin(T... args)
CatalogIterator< typename Internal::iterator > iterator
Definition Catalog.h:110

◆ begin() [2/2]

template<typename RecordT >
const_iterator lsst::afw::table::CatalogT< RecordT >::begin ( ) const
inline

Definition at line 402 of file Catalog.h.

402{ return const_iterator(_internal.begin()); }
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition Catalog.h:111

◆ capacity()

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 424 of file Catalog.h.

424{ return _internal.size() + _table->getBufferSize(); }
T size(T... args)

◆ cbegin()

template<typename RecordT >
const_iterator lsst::afw::table::CatalogT< RecordT >::cbegin ( ) const
inline

Definition at line 404 of file Catalog.h.

404{ return begin(); }
iterator begin()
Iterator access.
Definition Catalog.h:400

◆ cend()

template<typename RecordT >
const_iterator lsst::afw::table::CatalogT< RecordT >::cend ( ) const
inline

Definition at line 405 of file Catalog.h.

405{ return end(); }

◆ clear()

template<typename RecordT >
void lsst::afw::table::CatalogT< RecordT >::clear ( )
inline

Remove all records from the catalog.

Definition at line 578 of file Catalog.h.

578{ _internal.clear(); }
T clear(T... args)

◆ copy()

template<typename RecordT >
CatalogT lsst::afw::table::CatalogT< RecordT >::copy ( ) const
inline

Deep-copy the catalog using a cloned table.

Definition at line 499 of file Catalog.h.

499{ return CatalogT(getTable()->clone(), begin(), end(), true); }
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition Catalog.h:114

◆ empty()

template<typename RecordT >
bool lsst::afw::table::CatalogT< RecordT >::empty ( ) const
inline

Return true if the catalog has no records.

Definition at line 409 of file Catalog.h.

409{ return _internal.empty(); }
T empty(T... args)

◆ end() [1/2]

template<typename RecordT >
iterator lsst::afw::table::CatalogT< RecordT >::end ( )
inline

Definition at line 401 of file Catalog.h.

401{ return iterator(_internal.end()); }
T end(T... args)

◆ end() [2/2]

template<typename RecordT >
const_iterator lsst::afw::table::CatalogT< RecordT >::end ( ) const
inline

Definition at line 403 of file Catalog.h.

403{ return const_iterator(_internal.end()); }

◆ equal_range() [1/4]

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 )

◆ equal_range() [2/4]

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 849 of file Catalog.h.

849 {
850 detail::KeyExtractionFunctor<RecordT, T> f = {key};
851 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
852 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
854 std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
855 return std::make_pair(i.first.base(), i.second.base());
856}
T equal_range(T... args)
T make_pair(T... args)

◆ equal_range() [3/4]

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

◆ equal_range() [4/4]

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 861 of file Catalog.h.

861 {
862 detail::KeyExtractionFunctor<RecordT, T> f = {key};
863 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
864 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
866 std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
867 return std::make_pair(i.first.base(), i.second.base());
868}

◆ erase() [1/2]

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 567 of file Catalog.h.

567 {
568 return iterator(_internal.erase(first.base(), last.base()));
569 }
T erase(T... args)

◆ erase() [2/2]

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 564 of file Catalog.h.

564{ return iterator(_internal.erase(pos.base())); }

◆ find() [1/2]

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 )

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) for maximal efficiency. If the value searched for is not found, it assumes that the catalog is unsorted and performs a brute-force search instead of failing immediately.

Returns end() if the Record cannot be found.

Definition at line 762 of file Catalog.h.

763 {
764 detail::KeyExtractionFunctor<RecordT, T> f = {key};
765 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
766 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
767 /* Try binary search for log n search assuming the table is sorted.
768 * If the search is unsuccessful, try a brute-force search before quitting.
769 */
770 SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
771 if (i.base() == end() || *i != value) {
772 i = std::find(SearchIter(begin(), f), SearchIter(end(), f), value);
773 if (i.base() == end()) {
774 return end();
775 }
776 LOGL_DEBUG("lsst.afw.table.Catalog", "Catalog is not sorted by the key. Finding a record may be slow.");
777 }
778 return i.base();
779}
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition Log.h:515
T find(T... args)
T lower_bound(T... args)

◆ find() [2/2]

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 783 of file Catalog.h.

784 {
785 detail::KeyExtractionFunctor<RecordT, T> f = {key};
786 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
787 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
788 /* Try binary search for log n search assuming the table is sorted.
789 * If the search is unsuccessful, try a brute-force search before quitting.
790 */
791 SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
792 if (i.base() == end() || *i != value) {
793 i = std::find(SearchIter(begin(), f), SearchIter(end(), f), value);
794 if (i.base() == end()) {
795 return end();
796 }
797 LOGL_DEBUG("lsst.afw.table.Catalog", "Catalog is not sorted by the key. Finding a record may be slow.");
798 }
799 return i.base();
800}

◆ front()

template<typename RecordT >
reference lsst::afw::table::CatalogT< RecordT >::front ( ) const
inline

Return the first record.

Definition at line 457 of file Catalog.h.

457{ return *_internal.front(); }
T front(T... args)

◆ get()

template<typename RecordT >
std::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 463 of file Catalog.h.

463{ return _internal[i]; }

◆ getColumnView()

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 381 of file Catalog.h.

381 {
383 throw LSST_EXCEPT(
384 pex::exceptions::LogicError,
385 "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
386 "non-const views).");
387 }
388 return ColumnView::make(_table, begin(), end());
389 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48

◆ getInternal() [1/2]

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 675 of file Catalog.h.

675{ return _internal; }

◆ getInternal() [2/2]

template<typename RecordT >
Internal const & lsst::afw::table::CatalogT< RecordT >::getInternal ( ) const
inline

Definition at line 676 of file Catalog.h.

676{ return _internal; }

◆ getSchema()

template<typename RecordT >
Schema lsst::afw::table::CatalogT< RecordT >::getSchema ( ) const
inline

Return the schema associated with the catalog's table.

Definition at line 117 of file Catalog.h.

117{ return _table->getSchema(); }

◆ getTable()

template<typename RecordT >
std::shared_ptr< Table > lsst::afw::table::CatalogT< RecordT >::getTable ( ) const
inline

Return the table associated with the catalog.

Definition at line 114 of file Catalog.h.

114{ return _table; }

◆ insert() [1/4]

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 517 of file Catalog.h.

517 {
518 _maybeReserve(pos, first, last, deep,
520 if (deep) {
521 while (first != last) {
522 pos = insert(pos, *first);
523 ++pos;
524 ++first;
525 }
526 } else {
527 while (first != last) {
528 pos = insert(pos, first);
529 assert(pos != end());
530 ++pos;
531 ++first;
532 }
533 }
534 }

◆ insert() [2/4]

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 553 of file Catalog.h.

553 {
554 std::shared_ptr<RecordT> p = _table->copyRecord(r);
555 return iterator(_internal.insert(pos.base(), p));
556 }
T insert(T... args)

◆ insert() [3/4]

template<typename RecordT >
iterator lsst::afw::table::CatalogT< RecordT >::insert ( iterator pos,
std::shared_ptr< RecordT > const & p )
inline

Insert the given record at the given position without copying.

Definition at line 559 of file Catalog.h.

559 {
560 return iterator(_internal.insert(pos.base(), p));
561 }

◆ insert() [4/4]

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 538 of file Catalog.h.

538 {
539 if (!_table->getSchema().contains(mapper.getOutputSchema())) {
540 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
541 "SchemaMapper's output schema does not match catalog's schema");
542 }
543 _maybeReserve(pos, first, last, true,
545 while (first != last) {
546 pos = insert(pos, _table->copyRecord(*first, mapper));
547 ++pos;
548 ++first;
549 }
550 }
SchemaMapper * mapper

◆ isContiguous()

template<typename RecordT >
bool lsst::afw::table::CatalogT< RecordT >::isContiguous ( ) const
inline

Return true if all records are contiguous.

Definition at line 392 of file Catalog.h.

392{ return ColumnView::isRangeContiguous(_table, begin(), end()); }

◆ isSorted() [1/2]

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 725 of file Catalog.h.

725 {
727 detail::ComparisonAdaptor<RecordT, Compare> f = {cmp};
728 if (empty()) return true;
729 const_iterator last = this->begin();
730 const_iterator i = last;
731 ++i;
732 for (; i != this->end(); ++i) {
733 if (f(i, last)) return false;
734 last = i;
735 }
736 return true;
737}
bool empty() const
Return true if the catalog has no records.
Definition Catalog.h:409

◆ isSorted() [2/2]

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 748 of file Catalog.h.

748 {
749 detail::KeyComparisonFunctor<RecordT, T> f = {key};
750 return isSorted(f);
751}
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition Catalog.h:748

◆ lower_bound() [1/2]

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 )

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).

Definition at line 804 of file Catalog.h.

805 {
806 detail::KeyExtractionFunctor<RecordT, T> f = {key};
807 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
808 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
809 SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
810 return i.base();
811}

◆ lower_bound() [2/2]

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 815 of file Catalog.h.

816 {
817 detail::KeyExtractionFunctor<RecordT, T> f = {key};
818 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
819 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
820 SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
821 return i.base();
822}

◆ max_size()

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 415 of file Catalog.h.

415{ return _internal.max_size(); }
T max_size(T... args)

◆ operator=() [1/2]

template<typename RecordT >
CatalogT & lsst::afw::table::CatalogT< RecordT >::operator= ( CatalogT< RecordT > && other)
inline

Definition at line 177 of file Catalog.h.

177{ return *this = other; }

◆ operator=() [2/2]

template<typename RecordT >
CatalogT & lsst::afw::table::CatalogT< RecordT >::operator= ( CatalogT< RecordT > const & other)
inline

Shallow assigment.

Definition at line 169 of file Catalog.h.

169 {
170 if (&other != this) {
171 _table = other._table;
172 _internal = other._internal;
173 }
174 return *this;
175 }

◆ operator[]()

template<typename RecordT >
reference lsst::afw::table::CatalogT< RecordT >::operator[] ( size_type i) const
inline

Return the record at index i.

Definition at line 451 of file Catalog.h.

451{ return *_internal[i]; }

◆ pop_back()

template<typename RecordT >
void lsst::afw::table::CatalogT< RecordT >::pop_back ( )
inline

Remove the last record in the catalog.

Definition at line 496 of file Catalog.h.

496{ _internal.pop_back(); }
T pop_back(T... args)

◆ push_back() [1/2]

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 480 of file Catalog.h.

480 {
481 std::shared_ptr<RecordT> p = _table->copyRecord(r);
482 _internal.push_back(p);
483 }

◆ push_back() [2/2]

template<typename RecordT >
void lsst::afw::table::CatalogT< RecordT >::push_back ( std::shared_ptr< RecordT > const & p)
inline

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

Definition at line 486 of file Catalog.h.

486{ _internal.push_back(p); }

◆ readFits() [1/3]

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 372 of file Catalog.h.

372 {
373 return io::FitsReader::apply<CatalogT>(fitsfile, flags);
374 }

◆ readFits() [2/3]

template<typename RecordT >
static CatalogT lsst::afw::table::CatalogT< RecordT >::readFits ( fits::MemFileManager & manager,
int hdu = fits::DEFAULT_HDU,
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 0 is the Primary HDU). The default value of afw::fits::DEFAULT_HDU 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 361 of file Catalog.h.

361 {
362 return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
363 }

◆ readFits() [3/3]

template<typename RecordT >
static CatalogT lsst::afw::table::CatalogT< RecordT >::readFits ( std::string const & filename,
int hdu = fits::DEFAULT_HDU,
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 0 is the Primary HDU). The default value of afw::fits::DEFAULT_HDU 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 347 of file Catalog.h.

347 {
348 return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
349 }

◆ reserve()

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 432 of file Catalog.h.

432 {
433 if (n <= _internal.size()) return;
434 _table->preallocate(n - _internal.size());
435 _internal.reserve(n);
436 }
T reserve(T... args)

◆ resize()

template<typename RecordT >
void lsst::afw::table::CatalogT< RecordT >::resize ( size_type n)
inline

Change the size of the catalog, removing or adding empty records as needed.

Definition at line 439 of file Catalog.h.

439 {
440 size_type old = size();
441 _internal.resize(n);
442 if (old < n) {
443 _table->preallocate(n - old);
444 for (size_type i = old; i != n; ++i) {
445 _internal[i] = _table->makeRecord();
446 }
447 }
448 }
size_type size() const
Return the number of elements in the catalog.
Definition Catalog.h:412
typename Internal::size_type size_type
Definition Catalog.h:108
T resize(T... args)

◆ set()

template<typename RecordT >
void lsst::afw::table::CatalogT< RecordT >::set ( size_type i,
std::shared_ptr< RecordT > const & p )
inline

Set the record at index i to a pointer.

Definition at line 466 of file Catalog.h.

466{ _internal[i] = p; }

◆ size()

template<typename RecordT >
size_type lsst::afw::table::CatalogT< RecordT >::size ( ) const
inline

Return the number of elements in the catalog.

Definition at line 412 of file Catalog.h.

412{ return _internal.size(); }

◆ sort() [1/2]

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 741 of file Catalog.h.

741 {
742 detail::ComparisonAdaptor<RecordT, Compare> f = {cmp};
743 std::stable_sort(_internal.begin(), _internal.end(), f);
744}
T stable_sort(T... args)

◆ sort() [2/2]

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 755 of file Catalog.h.

755 {
756 detail::KeyComparisonFunctor<RecordT, T> f = {key};
757 return sort(f);
758}
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition Catalog.h:755

◆ subset() [1/2]

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 184 of file Catalog.h.

184 {
185 if (size_type(mask.size()) != size()) {
186 throw LSST_EXCEPT(
187 pex::exceptions::LengthError,
188 (boost::format("Mask array with %d elements applied to catalog with %d elements") %
189 mask.size() % size())
190 .str());
191 }
192 CatalogT<RecordT> result(getTable());
193 ndarray::Array<bool const, 1>::Iterator maskIter = mask.begin();
194 const_iterator catIter = begin();
195 for (; maskIter != mask.end(); ++maskIter, ++catIter) {
196 if (*maskIter) result.push_back(catIter);
197 }
198 return result;
199 }
py::object result
Definition _schema.cc:429
afw::table::Key< afw::table::Array< MaskPixelT > > mask

◆ subset() [2/2]

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 205 of file Catalog.h.

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

◆ swap()

template<typename RecordT >
void lsst::afw::table::CatalogT< RecordT >::swap ( CatalogT< RecordT > & other)
inlinenoexcept

Shallow swap of two catalogs.

Definition at line 572 of file Catalog.h.

572 {
573 _table.swap(other._table);
574 _internal.swap(other._internal);
575 }
T swap(T... args)

◆ upper_bound() [1/2]

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 826 of file Catalog.h.

827 {
828 detail::KeyExtractionFunctor<RecordT, T> f = {key};
829 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
830 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
831 SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
832 return i.base();
833}
T upper_bound(T... args)

◆ upper_bound() [2/2]

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 837 of file Catalog.h.

838 {
839 detail::KeyExtractionFunctor<RecordT, T> f = {key};
840 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
841 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
842 SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
843 return i.base();
844}

◆ writeFits() [1/3]

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 333 of file Catalog.h.

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

◆ writeFits() [2/3]

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 322 of file Catalog.h.

322 {
323 io::FitsWriter::apply(manager, mode, *this, flags);
324 }

◆ writeFits() [3/3]

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 310 of file Catalog.h.

310 {
311 io::FitsWriter::apply(filename, mode, *this, flags);
312 }

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