lsst.afw  13.0-91-g2a3e2ee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SortedCatalog.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008, 2009, 2010, 2011 LSST Corporation.
5  *
6  * This product includes software developed by the
7  * LSST Project (http://www.lsst.org/).
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the LSST License Statement and
20  * the GNU General Public License along with this program. If not,
21  * see <http://www.lsstcorp.org/LegalNotices/>.
22  */
23 #ifndef AFW_TABLE_SortedCatalog_h_INCLUDED
24 #define AFW_TABLE_SortedCatalog_h_INCLUDED
25 
26 #include "lsst/afw/table/fwd.h"
27 #include "lsst/afw/table/Catalog.h"
28 
29 namespace lsst {
30 namespace afw {
31 namespace table {
32 
40 template <typename RecordT>
41 class SortedCatalogT : public CatalogT<RecordT> {
42  typedef CatalogT<RecordT> Base;
43 
44 public:
45  typedef RecordT Record;
46  typedef typename Record::Table Table;
47 
48  typedef typename Base::iterator iterator;
50 
51  using Base::isSorted;
52  using Base::sort;
53  using Base::find;
54 
56  bool isSorted() const { return this->isSorted(Table::getIdKey()); }
57 
59  void sort() { this->sort(Table::getIdKey()); }
60 
62 
70  iterator find(RecordId id) { return this->find(id, Table::getIdKey()); }
71  const_iterator find(RecordId id) const { return this->find(id, Table::getIdKey()); }
73 
80  explicit SortedCatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>()) : Base(table) {}
81 
83  explicit SortedCatalogT(Schema const& schema) : Base(schema) {}
84 
95  template <typename InputIterator>
96  SortedCatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last,
97  bool deep = false)
98  : Base(table, first, last, deep) {}
99 
106  template <typename OtherRecordT>
108 
118  static SortedCatalogT readFits(std::string const& filename, int hdu = INT_MIN, int flags = 0) {
119  return io::FitsReader::apply<SortedCatalogT>(filename, hdu, flags);
120  }
121 
131  static SortedCatalogT readFits(fits::MemFileManager& manager, int hdu = INT_MIN, int flags = 0) {
132  return io::FitsReader::apply<SortedCatalogT>(manager, hdu, flags);
133  }
134 
142  static SortedCatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
143  return io::FitsReader::apply<SortedCatalogT>(fitsfile, flags);
144  }
145 
151  SortedCatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
152  return SortedCatalogT(Base::subset(mask));
153  }
154 
159  SortedCatalogT subset(std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const {
160  return SortedCatalogT(Base::subset(startd, stopd, step));
161  }
162 
163 protected:
164  explicit SortedCatalogT(Base const& other) : Base(other) {}
165 };
166 }
167 }
168 } // namespace lsst::afw::table
169 
170 #endif // !AFW_TABLE_SortedCatalog_h_INCLUDED
std::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:22
Defines the fields and offsets for a table.
Definition: Schema.h:46
SortedCatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: SortedCatalog.h:80
SortedCatalogT(SortedCatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
const_iterator find(RecordId id) const
Return an iterator to the record with the given ID.
Definition: SortedCatalog.h:71
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition: Catalog.h:720
A custom container class for records, based on std::vector.
Definition: Catalog.h:96
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:727
SortedCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: SortedCatalog.h:83
static SortedCatalogT readFits(std::string const &filename, int hdu=INT_MIN, int flags=0)
Read a FITS binary table from a regular file.
void sort()
Sort the vector in-place by ID.
Definition: SortedCatalog.h:59
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:199
SortedCatalogT(std::shared_ptr< Table > const &table, InputIterator first, InputIterator last, bool deep=false)
Construct a vector from a table and an iterator range.
Definition: SortedCatalog.h:96
SortedCatalogT(Base const &other)
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...
static SortedCatalogT readFits(fits::Fits &fitsfile, int flags=0)
Read a FITS binary table from a file object already at the correct extension.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:63
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:100
int const step
Definition: BoundedField.cc:97
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:173
Iterator class for CatalogT.
Definition: Catalog.h:37
static SortedCatalogT readFits(fits::MemFileManager &manager, int hdu=INT_MIN, int flags=0)
Read a FITS binary table from a RAM file.
SortedCatalogT subset(std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const
Shallow copy a subset of another SortedCatalog.
bool isSorted() const
Return true if the vector is in ascending ID order.
Definition: SortedCatalog.h:56
afw::table::Key< afw::table::Array< MaskPixelT > > mask
Base::const_iterator const_iterator
Definition: SortedCatalog.h:49
iterator find(typename Field< T >::Value const &value, Key< T > const &key)
Return an iterator to the record with the given value.
iterator find(RecordId id)
Return an iterator to the record with the given ID.
Definition: SortedCatalog.h:70
afw::table::Schema schema
Definition: GaussianPsf.cc:43