LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
lsst::afw::table::SortedCatalogT< RecordT > Class Template Reference

Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID. More...

#include <fwd.h>

Public Types

typedef RecordT Record
 
typedef Record::Table Table
 
typedef Base::iterator iterator
 
typedef Base::const_iterator const_iterator
 

Public Member Functions

 SortedCatalogT (SortedCatalogT const &)=default
 
 SortedCatalogT (SortedCatalogT &&)=default
 
SortedCatalogToperator= (SortedCatalogT const &)=default
 
SortedCatalogToperator= (SortedCatalogT &&)=default
 
 ~SortedCatalogT ()=default
 
bool isSorted () const
 Return true if the vector is in ascending ID order. More...
 
void sort ()
 Sort the vector in-place by ID. More...
 
iterator find (RecordId id)
 Return an iterator to the record with the given ID. More...
 
const_iterator find (RecordId id) const
 
 SortedCatalogT (std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
 Construct a vector from a table (or nothing). More...
 
 SortedCatalogT (Schema const &schema)
 Construct a vector from a schema, creating a table with Table::make(schema). More...
 
template<typename InputIterator >
 SortedCatalogT (std::shared_ptr< Table > const &table, InputIterator first, InputIterator last, bool deep=false)
 Construct a vector from a table and an iterator range. More...
 
template<typename OtherRecordT >
 SortedCatalogT (SortedCatalogT< OtherRecordT > const &other)
 Shallow copy constructor from a container containing a related record type. More...
 
SortedCatalogT< 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...
 
SortedCatalogT subset (std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const
 Shallow copy a subset of another SortedCatalog. 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 >
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
 

Static Public Member Functions

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

Protected Member Functions

 SortedCatalogT (Base const &other)
 

Detailed Description

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

Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.

For a record/table pair to be used with SortedCatalogT, the table class must provide a static getIdKey() member function that returns the key to the ID field.

Definition at line 63 of file fwd.h.

Member Typedef Documentation

◆ const_iterator

template<typename RecordT >
typedef Base::const_iterator lsst::afw::table::SortedCatalogT< RecordT >::const_iterator

Definition at line 50 of file SortedCatalog.h.

◆ iterator

template<typename RecordT >
typedef Base::iterator lsst::afw::table::SortedCatalogT< RecordT >::iterator

Definition at line 49 of file SortedCatalog.h.

◆ Record

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

Definition at line 46 of file SortedCatalog.h.

◆ Table

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

Definition at line 47 of file SortedCatalog.h.

Constructor & Destructor Documentation

◆ SortedCatalogT() [1/7]

template<typename RecordT >
lsst::afw::table::SortedCatalogT< RecordT >::SortedCatalogT ( SortedCatalogT< RecordT > const &  )
default

◆ SortedCatalogT() [2/7]

template<typename RecordT >
lsst::afw::table::SortedCatalogT< RecordT >::SortedCatalogT ( SortedCatalogT< RecordT > &&  )
default

◆ ~SortedCatalogT()

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

◆ SortedCatalogT() [3/7]

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

Construct a vector from a table (or nothing).

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

Definition at line 87 of file SortedCatalog.h.

87 : Base(table) {}

◆ SortedCatalogT() [4/7]

template<typename RecordT >
lsst::afw::table::SortedCatalogT< RecordT >::SortedCatalogT ( Schema const &  schema)
inlineexplicit

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

Definition at line 90 of file SortedCatalog.h.

90 : Base(schema) {}

◆ SortedCatalogT() [5/7]

template<typename RecordT >
template<typename InputIterator >
lsst::afw::table::SortedCatalogT< RecordT >::SortedCatalogT ( std::shared_ptr< Table > const &  table,
InputIterator  first,
InputIterator  last,
bool  deep = false 
)
inline

Construct a vector 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 103 of file SortedCatalog.h.

105  : Base(table, first, last, deep) {}

◆ SortedCatalogT() [6/7]

template<typename RecordT >
template<typename OtherRecordT >
lsst::afw::table::SortedCatalogT< RecordT >::SortedCatalogT ( SortedCatalogT< 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 114 of file SortedCatalog.h.

114 : Base(other) {}

◆ SortedCatalogT() [7/7]

template<typename RecordT >
lsst::afw::table::SortedCatalogT< RecordT >::SortedCatalogT ( Base const &  other)
inlineexplicitprotected

Definition at line 174 of file SortedCatalog.h.

174 : Base(other) {}

Member Function Documentation

◆ find() [1/4]

template<typename RecordT >
iterator lsst::afw::table::SortedCatalogT< RecordT >::find ( RecordId  id)
inline

Return an iterator to the record with the given ID.

Note
The vector must be sorted in ascending ID order before calling find (i.e. isSorted() must be true).

Returns end() if the Record cannot be found.

Definition at line 77 of file SortedCatalog.h.

77 { return this->find(id, Table::getIdKey()); }

◆ find() [2/4]

template<typename RecordT >
const_iterator lsst::afw::table::SortedCatalogT< RecordT >::find ( RecordId  id) const
inline

Definition at line 78 of file SortedCatalog.h.

78 { return this->find(id, Table::getIdKey()); }

◆ find() [3/4]

template<typename RecordT >
template<typename T >
CatalogT< RecordT >::iterator lsst::afw::table::CatalogT< RecordT >::find ( typename T  )

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.

Definition at line 616 of file Catalog.h.

757  {
758  detail::KeyExtractionFunctor<RecordT, T> f = {key};
759  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
760  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
761  // Use binary search for log n search; requires sorted table.
762  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
763  if (i.base() == end() || *i != value) return end();
764  return i.base();
765 }

◆ find() [4/4]

template<typename RecordT >
template<typename T >
CatalogT< RecordT >::const_iterator lsst::afw::table::CatalogT< RecordT >::find ( typename T  )

Definition at line 619 of file Catalog.h.

770  {
771  detail::KeyExtractionFunctor<RecordT, T> f = {key};
772  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
773  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
774  // Use binary search for log n search; requires sorted table.
775  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
776  if (i.base() == end() || *i != value) return end();
777  return i.base();
778 }

◆ isSorted() [1/3]

template<typename RecordT >
bool lsst::afw::table::SortedCatalogT< RecordT >::isSorted ( ) const
inline

Return true if the vector is in ascending ID order.

Definition at line 63 of file SortedCatalog.h.

63 { return this->isSorted(Table::getIdKey()); }

◆ isSorted() [2/3]

template<typename RecordT >
template<typename Compare >
bool lsst::afw::table::CatalogT< RecordT >::isSorted ( typename Compare  )

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

719  {
721  detail::ComparisonAdaptor<RecordT, Compare> f = {cmp};
722  if (empty()) return true;
723  const_iterator last = this->begin();
724  const_iterator i = last;
725  ++i;
726  for (; i != this->end(); ++i) {
727  if (f(i, last)) return false;
728  last = i;
729  }
730  return true;
731 }

◆ isSorted() [3/3]

template<typename RecordT >
template<typename T >
bool lsst::afw::table::CatalogT< RecordT >::isSorted ( typename T  )

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

Definition at line 578 of file Catalog.h.

742  {
743  detail::KeyComparisonFunctor<RecordT, T> f = {key};
744  return isSorted(f);
745 }

◆ operator=() [1/2]

template<typename RecordT >
SortedCatalogT& lsst::afw::table::SortedCatalogT< RecordT >::operator= ( SortedCatalogT< RecordT > &&  )
default

◆ operator=() [2/2]

template<typename RecordT >
SortedCatalogT& lsst::afw::table::SortedCatalogT< RecordT >::operator= ( SortedCatalogT< RecordT > const &  )
default

◆ readFits() [1/3]

template<typename RecordT >
static SortedCatalogT lsst::afw::table::SortedCatalogT< 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 152 of file SortedCatalog.h.

152  {
153  return io::FitsReader::apply<SortedCatalogT>(fitsfile, flags);
154  }

◆ readFits() [2/3]

template<typename RecordT >
static SortedCatalogT lsst::afw::table::SortedCatalogT< 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 140 of file SortedCatalog.h.

141  {
142  return io::FitsReader::apply<SortedCatalogT>(manager, hdu, flags);
143  }

◆ readFits() [3/3]

template<typename RecordT >
static SortedCatalogT lsst::afw::table::SortedCatalogT< 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 126 of file SortedCatalog.h.

126  {
127  return io::FitsReader::apply<SortedCatalogT>(filename, hdu, flags);
128  }

◆ sort() [1/3]

template<typename RecordT >
void lsst::afw::table::SortedCatalogT< RecordT >::sort ( )
inline

Sort the vector in-place by ID.

Definition at line 66 of file SortedCatalog.h.

66 { this->sort(Table::getIdKey()); }

◆ sort() [2/3]

template<typename RecordT >
template<typename Compare >
void lsst::afw::table::CatalogT< RecordT >::sort ( typename Compare  )

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

735  {
736  detail::ComparisonAdaptor<RecordT, Compare> f = {cmp};
737  std::stable_sort(_internal.begin(), _internal.end(), f);
738 }

◆ sort() [3/3]

template<typename RecordT >
template<typename T >
void lsst::afw::table::CatalogT< RecordT >::sort ( typename T  )

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

Definition at line 590 of file Catalog.h.

749  {
750  detail::KeyComparisonFunctor<RecordT, T> f = {key};
751  return sort(f);
752 }

◆ subset() [1/2]

template<typename RecordT >
SortedCatalogT<RecordT> lsst::afw::table::SortedCatalogT< 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 161 of file SortedCatalog.h.

161  {
163  }

◆ subset() [2/2]

template<typename RecordT >
SortedCatalogT lsst::afw::table::SortedCatalogT< RecordT >::subset ( std::ptrdiff_t  startd,
std::ptrdiff_t  stopd,
std::ptrdiff_t  step 
) const
inline

Shallow copy a subset of another SortedCatalog.

Mostly here for use from python.

Definition at line 169 of file SortedCatalog.h.

169  {
170  return SortedCatalogT(Base::subset(startd, stopd, step));
171  }

The documentation for this class was generated from the following files:
schema
table::Schema schema
Definition: Amplifier.cc:115
lsst::afw::table._match.first
first
Definition: _match.py:74
lsst::afw::table::SortedCatalogT::const_iterator
Base::const_iterator const_iterator
Definition: SortedCatalog.h:50
mask
afw::table::Key< afw::table::Array< MaskPixelT > > mask
Definition: HeavyFootprint.cc:217
end
int end
Definition: BoundedField.cc:105
lsst::afw::table::SortedCatalogT::isSorted
bool isSorted() const
Return true if the vector is in ascending ID order.
Definition: SortedCatalog.h:63
lsst::afw::table::CatalogT::subset
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.
Definition: Catalog.h:180
lsst::afw::table::SortedCatalogT::find
iterator find(RecordId id)
Return an iterator to the record with the given ID.
Definition: SortedCatalog.h:77
lsst::afw::table::SortedCatalogT::iterator
Base::iterator iterator
Definition: SortedCatalog.h:49
other
ItemVariant const * other
Definition: Schema.cc:56
step
int const step
Definition: BoundedField.cc:102
lsst::afw::table::SortedCatalogT::SortedCatalogT
SortedCatalogT(SortedCatalogT const &)=default
std::lower_bound
T lower_bound(T... args)
std::begin
T begin(T... args)
lsst::afw::table::SortedCatalogT::sort
void sort()
Sort the vector in-place by ID.
Definition: SortedCatalog.h:66
key
Key< U > key
Definition: Schema.cc:281
std::stable_sort
T stable_sort(T... args)