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
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 { namespace afw { namespace table {
30 
31 #ifndef SWIG
32 
40 template <typename RecordT>
41 class SortedCatalogT : public CatalogT<RecordT> {
43 public:
44 
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(PTR(Table) const & table = PTR(Table)()) : Base(table) {}
81 
83  explicit SortedCatalogT(Schema const & schema) : Base(schema) {}
84 
95  template <typename InputIterator>
96  SortedCatalogT(PTR(Table) const & table, InputIterator first, InputIterator last, bool deep=false) :
97  Base(table, first, last, deep)
98  {}
99 
106  template <typename OtherRecordT>
108 
118  static SortedCatalogT readFits(std::string const & filename, int hdu=0, int flags=0) {
119  return io::FitsReader::apply<SortedCatalogT>(filename, hdu, flags);
120  }
121 
131  static SortedCatalogT readFits(fits::MemFileManager & manager, int hdu=0, 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 
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 #endif // !SWIG
168 
169 }}} // namespace lsst::afw::table
170 
171 #endif // !AFW_TABLE_SortedCatalog_h_INCLUDED
Defines the fields and offsets for a table.
Definition: Schema.h:46
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:738
static SortedCatalogT readFits(fits::MemFileManager &manager, int hdu=0, int flags=0)
Read a FITS binary table from a RAM file.
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
afw::table::Schema schema
Definition: GaussianPsf.cc:41
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:745
SortedCatalogT(Schema const &schema)
Construct a vector from a schema, creating a table with Table::make(schema).
Definition: SortedCatalog.h:83
#define PTR(...)
Definition: base.h:41
void sort()
Sort the vector in-place by ID.
Definition: SortedCatalog.h:59
SortedCatalogT(boost::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
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:194
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:55
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:106
static SortedCatalogT readFits(std::string const &filename, int hdu=0, int flags=0)
Read a FITS binary table from a regular file.
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:172
Iterator class for CatalogT.
Definition: Catalog.h:34
SortedCatalogT subset(std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const
Shallow copy a subset of another SortedCatalog. Mostly here for use from python.
bool isSorted() const
Return true if the vector is in ascending ID order.
Definition: SortedCatalog.h:56
A multidimensional strided array.
Definition: Array.h:47
Record::Table Table
Definition: Catalog.h:99
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.
SortedCatalogT(boost::shared_ptr< Table > const &table=boost::shared_ptr< Table >())
Construct a vector from a table (or nothing).
Definition: SortedCatalog.h:80
boost::int64_t RecordId
Type used for unique IDs for records.
Definition: misc.h:21
iterator find(RecordId id)
Return an iterator to the record with the given ID.
Definition: SortedCatalog.h:70