lsst.afw  14.0-38-g278b05818
Catalog.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 #ifndef AFW_TABLE_Catalog_h_INCLUDED
3 #define AFW_TABLE_Catalog_h_INCLUDED
4 
5 #include <type_traits>
6 #include <vector>
7 
8 #include "boost/iterator/iterator_adaptor.hpp"
9 #include "boost/iterator/transform_iterator.hpp"
10 
11 #include "lsst/base.h"
12 #include "lsst/pex/exceptions.h"
13 #include "lsst/afw/fitsDefaults.h"
14 #include "lsst/afw/table/fwd.h"
18 
19 namespace lsst {
20 namespace afw {
21 namespace table {
22 
37 template <typename BaseT>
38 class CatalogIterator : public boost::iterator_adaptor<CatalogIterator<BaseT>, BaseT,
39  typename BaseT::value_type::element_type> {
40 public:
42 
43  template <typename OtherBaseT>
45  : CatalogIterator::iterator_adaptor_(other.base()) {}
46 
47  explicit CatalogIterator(BaseT const& base) : CatalogIterator::iterator_adaptor_(base) {}
48 
49  template <typename RecordT>
50  operator std::shared_ptr<RecordT>() const {
51  return *this->base();
52  }
53 
54  template <typename RecordT>
56  *this->base() = other;
57  return *this;
58  }
59 
60 private:
62  typename BaseT::value_type::element_type& dereference() const { return **this->base(); }
63 };
64 
96 template <typename RecordT>
97 class CatalogT {
99 
100 public:
101  typedef RecordT Record;
102  typedef typename Record::Table Table;
103  typedef typename Record::ColumnView ColumnView;
104 
105  typedef RecordT value_type;
106  typedef RecordT& reference;
108  typedef typename Internal::size_type size_type;
109  typedef typename Internal::difference_type difference_type;
112 
114  std::shared_ptr<Table> getTable() const { return _table; }
115 
117  Schema getSchema() const { return _table->getSchema(); }
118 
126  : _table(table), _internal() {}
127 
129  explicit CatalogT(Schema const& schema) : _table(Table::make(schema)), _internal() {}
130 
141  template <typename InputIterator>
142  CatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last, bool deep = false)
143  : _table(table), _internal() {
144  insert(end(), first, last, deep);
145  }
146 
148  CatalogT(CatalogT const& other) : _table(other._table), _internal(other._internal) {}
149 
156  template <typename OtherRecordT>
158  : _table(other.getTable()), _internal(other.begin().base(), other.end().base()) {}
159 
161  CatalogT& operator=(CatalogT const& other) {
162  if (&other != this) {
163  _table = other._table;
164  _internal = other._internal;
165  }
166  return *this;
167  }
168 
174  CatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
175  if (size_type(mask.size()) != size()) {
176  throw LSST_EXCEPT(
178  (boost::format("Mask array with %d elements applied to catalog with %d elements") %
179  mask.size() %
180  size()).str());
181  }
182  CatalogT<RecordT> result(getTable());
183  ndarray::Array<bool const, 1>::Iterator maskIter = mask.begin();
184  const_iterator catIter = begin();
185  for (; maskIter != mask.end(); ++maskIter, ++catIter) {
186  if (*maskIter) result.push_back(catIter);
187  }
188  return result;
189  }
190 
196  /* Python's slicing syntax is weird and wonderful.
197 
198  Both the "start" and "stop" indices can be negative, which means the
199  abs() of the index less than the size; [-1] means the last item.
200  Moreover, it's possible to have a negative index less than -len(); it
201  will get clipped. That is in fact one way to slice *backward* through
202  the array *and* include element 0;
203 
204  >>> range(10)[5:-20:-1]
205  [5, 4, 3, 2, 1, 0]
206 
207  The clipping tests in this function look more complicated than they
208  need to be, but that is partly because there are some weird edge cases.
209 
210  Also, ptrdiff_t vs size_t introduces some annoying complexity. Note
211  that the args are "startd"/"stopd" (not "start"/"stop").
212 
213  There is a fairly complete set of tests in tests/ticket2026.py; if you
214  try to simplify this function, be sure they continue to pass.
215  */
216  size_type S = size();
217  size_type start, stop = 0;
218  // Python doesn't allow step == 0
219  if (step == 0) {
220  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Step cannot be zero");
221  }
222  // Basic negative indexing rule: first add size
223  if (startd < 0) {
224  startd += S;
225  }
226  if (stopd < 0) {
227  stopd += S;
228  }
229  // Start gets clipped to zero; stop does not (yet).
230  if (startd < 0) {
231  startd = 0;
232  }
233  // Now start is non-negative, so can cast to size_t.
234  start = (size_type)startd;
235  if (start > S) {
236  start = S;
237  }
238  if (step > 0) {
239  // When stepping forward, stop gets clipped at zero,
240  // so is non-negative and can get cast to size_t.
241  if (stopd < 0) {
242  stopd = 0;
243  }
244  stop = (size_type)stopd;
245  if (stop > S) {
246  stop = S;
247  }
248  } else if (step < 0) {
249  // When stepping backward, stop gets clipped at -1 so that slices
250  // including 0 are possible.
251  if (stopd < 0) {
252  stopd = -1;
253  }
254  }
255 
256  if (((step > 0) && (start >= stop)) || ((step < 0) && ((std::ptrdiff_t)start <= stopd))) {
257  // Empty range
258  return CatalogT<RecordT>(getTable(), begin(), begin());
259  }
260 
261  if (step == 1) {
262  // Use the iterator-based constructor for this simple case
263  assert(start >= 0);
264  assert(stop > 0);
265  assert(start < S);
266  assert(stop <= S);
267  return CatalogT<RecordT>(getTable(), begin() + start, begin() + stop);
268  }
269 
270  // Build a new CatalogT and copy records into it.
271  CatalogT<RecordT> cat(getTable());
272  size_type N = 0;
273  if (step >= 0) {
274  N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
275  } else {
276  N = (size_t)((stopd - (std::ptrdiff_t)start) / step +
277  (((stopd - (std::ptrdiff_t)start) % step) ? 1 : 0));
278  }
279  cat.reserve(N);
280  if (step >= 0) {
281  for (size_type i = start; i < stop; i += step) {
282  cat.push_back(get(i));
283  }
284  } else {
285  for (std::ptrdiff_t i = (std::ptrdiff_t)start; i > stopd; i += step) {
286  cat.push_back(get(i));
287  }
288  }
289  return cat;
290  }
291 
300  void writeFits(std::string const& filename, std::string const& mode = "w", int flags = 0) const {
301  io::FitsWriter::apply(filename, mode, *this, flags);
302  }
303 
312  void writeFits(fits::MemFileManager& manager, std::string const& mode = "w", int flags = 0) const {
313  io::FitsWriter::apply(manager, mode, *this, flags);
314  }
315 
323  void writeFits(fits::Fits& fitsfile, int flags = 0) const {
324  io::FitsWriter::apply(fitsfile, *this, flags);
325  }
326 
337  static CatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU, int flags = 0) {
338  return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
339  }
340 
351  static CatalogT readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU, int flags = 0) {
352  return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
353  }
354 
362  static CatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
363  return io::FitsReader::apply<CatalogT>(fitsfile, flags);
364  }
365 
371  ColumnView getColumnView() const {
373  throw LSST_EXCEPT(
375  "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
376  "non-const views).");
377  }
378  return ColumnView::make(_table, begin(), end());
379  }
380 
382  bool isContiguous() const { return ColumnView::isRangeContiguous(_table, begin(), end()); }
383 
385 
390  iterator begin() { return iterator(_internal.begin()); }
391  iterator end() { return iterator(_internal.end()); }
392  const_iterator begin() const { return const_iterator(_internal.begin()); }
393  const_iterator end() const { return const_iterator(_internal.end()); }
394  const_iterator cbegin() const { return begin(); }
395  const_iterator cend() const { return end(); }
397 
399  bool empty() const { return _internal.empty(); }
400 
402  size_type size() const { return _internal.size(); }
403 
405  size_type max_size() const { return _internal.max_size(); }
406 
414  size_type capacity() const { return _internal.size() + _table->getBufferSize(); }
415 
422  void reserve(size_type n) {
423  if (n <= _internal.size()) return;
424  _table->preallocate(n - _internal.size());
425  }
426 
428  reference operator[](size_type i) const { return *_internal[i]; }
429 
431  reference at(size_type i) const { return *_internal.at(i); }
432 
434  reference front() const { return *_internal.front(); }
435 
437  reference back() const { return *_internal.back(); }
438 
440  std::shared_ptr<RecordT> const get(size_type i) const { return _internal[i]; }
441 
443  void set(size_type i, std::shared_ptr<RecordT> const& p) { _internal[i] = p; }
444 
450  template <typename InputIterator>
451  void assign(InputIterator first, InputIterator last, bool deep = false) {
452  clear();
453  insert(end(), first, last, deep);
454  }
455 
457  void push_back(Record const& r) {
458  std::shared_ptr<RecordT> p = _table->copyRecord(r);
459  _internal.push_back(p);
460  }
461 
463  void push_back(std::shared_ptr<RecordT> const& p) { _internal.push_back(p); }
464 
467  std::shared_ptr<RecordT> r = _table->makeRecord();
468  _internal.push_back(r);
469  return r;
470  }
471 
473  void pop_back() { _internal.pop_back(); }
474 
476  CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
477 
493  template <typename InputIterator>
494  void insert(iterator pos, InputIterator first, InputIterator last, bool deep = false) {
495  _maybeReserve(pos, first, last, deep,
497  if (deep) {
498  while (first != last) {
499  pos = insert(pos, *first);
500  ++pos;
501  ++first;
502  }
503  } else {
504  while (first != last) {
505  pos = insert(pos, first);
506  assert(pos != end());
507  ++pos;
508  ++first;
509  }
510  }
511  }
512 
514  template <typename InputIterator>
515  void insert(SchemaMapper const& mapper, iterator pos, InputIterator first, InputIterator last) {
516  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
518  "SchemaMapper's output schema does not match catalog's schema");
519  }
520  _maybeReserve(pos, first, last, true,
522  while (first != last) {
523  pos = insert(pos, _table->copyRecord(*first, mapper));
524  ++pos;
525  ++first;
526  }
527  }
528 
530  iterator insert(iterator pos, Record const& r) {
531  std::shared_ptr<RecordT> p = _table->copyRecord(r);
532  return iterator(_internal.insert(pos.base(), p));
533  }
534 
536  iterator insert(iterator pos, std::shared_ptr<RecordT> const& p) {
537  return iterator(_internal.insert(pos.base(), p));
538  }
539 
541  iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
542 
544  iterator erase(iterator first, iterator last) {
545  return iterator(_internal.erase(first.base(), last.base()));
546  }
547 
549  void swap(CatalogT& other) {
550  _table.swap(other._table);
551  _internal.swap(other._internal);
552  }
553 
555  void clear() { _internal.clear(); }
556 
558  template <typename T>
559  bool isSorted(Key<T> const& key) const;
560 
566  template <typename Compare>
567  bool isSorted(Compare cmp) const;
568 
570  template <typename T>
571  void sort(Key<T> const& key);
572 
578  template <typename Compare>
579  void sort(Compare cmp);
580 
582 
596  template <typename T>
597  iterator find(typename Field<T>::Value const& value, Key<T> const& key);
598 
599  template <typename T>
600  const_iterator find(typename Field<T>::Value const& value, Key<T> const& key) const;
602 
604 
617  template <typename T>
618  iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key);
619 
620  template <typename T>
621  const_iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
622 
623  template <typename T>
624  iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key);
625 
626  template <typename T>
627  const_iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
628 
629  template <typename T>
630  std::pair<iterator, iterator> equal_range(typename Field<T>::Value const& value, Key<T> const& key);
631 
632  template <typename T>
633  std::pair<const_iterator, const_iterator> equal_range(typename Field<T>::Value const& value,
634  Key<T> const& key) const;
636 
638 
650  Internal& getInternal() { return _internal; }
651  Internal const& getInternal() const { return _internal; }
653 
654 private:
655  template <typename InputIterator>
656  void _maybeReserve(iterator& pos, InputIterator first, InputIterator last, bool deep,
658  if (deep) _table->preallocate(last - first);
659  }
660 
661  template <typename InputIterator>
662  void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep,
664 
665  std::shared_ptr<Table> _table;
666  Internal _internal;
667 };
668 
669 namespace detail {
670 
671 template <typename RecordT, typename T>
673  bool operator()(RecordT const& a, RecordT const& b) const { return a.get(key) < b.get(key); }
674 
676 };
677 
678 template <typename RecordT, typename Adaptee>
681  return adaptee(*a, *b);
682  }
683 
684  Adaptee adaptee;
685 };
686 
687 template <typename RecordT, typename T>
689  typedef typename Field<T>::Value result_type;
690 
691  result_type operator()(RecordT const& r) const { return r.get(key); }
692 
694 };
695 
696 } // namespace detail
697 
698 template <typename RecordT>
699 template <typename Compare>
700 bool CatalogT<RecordT>::isSorted(Compare cmp) const {
703  if (empty()) return true;
704  const_iterator last = this->begin();
705  const_iterator i = last;
706  ++i;
707  for (; i != this->end(); ++i) {
708  if (f(i, last)) return false;
709  last = i;
710  }
711  return true;
712 }
713 
714 template <typename RecordT>
715 template <typename Compare>
716 void CatalogT<RecordT>::sort(Compare cmp) {
718  std::stable_sort(_internal.begin(), _internal.end(), f);
719 }
720 
721 template <typename RecordT>
722 template <typename T>
723 bool CatalogT<RecordT>::isSorted(Key<T> const& key) const {
725  return isSorted(f);
726 }
727 
728 template <typename RecordT>
729 template <typename T>
730 void CatalogT<RecordT>::sort(Key<T> const& key) {
732  return sort(f);
733 }
734 
735 template <typename RecordT>
736 template <typename T>
738  Key<T> const& key) {
740  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
741  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
742  // Use binary search for log n search; requires sorted table.
743  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
744  if (i.base() == end() || *i != value) return end();
745  return i.base();
746 }
747 
748 template <typename RecordT>
749 template <typename T>
751  Key<T> const& key) const {
753  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
754  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
755  // Use binary search for log n search; requires sorted table.
756  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
757  if (i.base() == end() || *i != value) return end();
758  return i.base();
759 }
760 
761 template <typename RecordT>
762 template <typename T>
764  Key<T> const& key) {
766  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
767  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
768  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
769  return i.base();
770 }
771 
772 template <typename RecordT>
773 template <typename T>
775  typename Field<T>::Value const& value, Key<T> const& key) const {
777  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
778  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
779  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
780  return i.base();
781 }
782 
783 template <typename RecordT>
784 template <typename T>
786  Key<T> const& key) {
788  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
789  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
790  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
791  return i.base();
792 }
793 
794 template <typename RecordT>
795 template <typename T>
797  typename Field<T>::Value const& value, Key<T> const& key) const {
799  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
800  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
801  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
802  return i.base();
803 }
804 
805 template <typename RecordT>
806 template <typename T>
808 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) {
810  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
811  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
813  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
814  return std::make_pair(i.first.base(), i.second.base());
815 }
816 
817 template <typename RecordT>
818 template <typename T>
820 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) const {
822  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
823  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
825  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
826  return std::make_pair(i.first.base(), i.second.base());
827 }
828 
830 
851 template <typename RecordT, typename Catalog, typename T>
852 std::shared_ptr<RecordT> _Catalog_find(Catalog const& catalog, T const& value, Key<T> const& key) {
853  typename Catalog::const_iterator iter = catalog.find(value, key);
854  if (iter == catalog.end()) {
855  return std::shared_ptr<RecordT>();
856  }
857  return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
858 }
859 
860 template <typename Catalog, typename T>
861 int _Catalog_lower_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
862  return catalog.lower_bound(value, key) - catalog.begin();
863 }
864 
865 template <typename Catalog, typename T>
866 int _Catalog_upper_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
867  return catalog.upper_bound(value, key) - catalog.begin();
868 }
869 
870 template <typename Catalog, typename T>
871 std::pair<int, int> _Catalog_equal_range(Catalog const& catalog, T const& value, Key<T> const& key) {
873  catalog.equal_range(value, key);
874  return std::pair<int, int>(p.first - catalog.begin(), p.second - catalog.begin());
875 }
876 
878 }
879 }
880 } // namespace lsst::afw::table
881 
882 #endif // !AFW_TABLE_Catalog_h_INCLUDED
CatalogT(CatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Catalog.h:157
void push_back(std::shared_ptr< RecordT > const &p)
Add the given record to the end of the catalog without copying.
Definition: Catalog.h:463
Defines the fields and offsets for a table.
Definition: Schema.h:47
std::shared_ptr< RecordT > _Catalog_find(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:852
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition: Catalog.h:536
T stable_sort(T... args)
Internal::difference_type difference_type
Definition: Catalog.h:109
afw::table::Key< afw::table::Array< MaskPixelT > > mask
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:174
CatalogT & operator=(CatalogT const &other)
Shallow assigment.
Definition: Catalog.h:161
CatalogIterator(CatalogIterator< OtherBaseT > const &other)
Definition: Catalog.h:44
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
afw::table::Schema schema
Definition: GaussianPsf.cc:43
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition: Catalog.h:723
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:114
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
Definition: SchemaMapper.h:27
T upper_bound(T... args)
size_type max_size() const
Return the maximum number of elements allowed in a catalog.
Definition: Catalog.h:405
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:730
static CatalogT readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU, int flags=0)
Read a FITS binary table from a RAM file.
Definition: Catalog.h:351
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:650
reference back() const
Return the last record.
Definition: Catalog.h:437
void pop_back()
Remove the last record in the catalog.
Definition: Catalog.h:473
bool operator()(std::shared_ptr< RecordT > const &a, std::shared_ptr< RecordT > const &b) const
Definition: Catalog.h:680
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:861
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition: Catalog.h:763
Schema getSchema() const
Return the schema associated with the catalog&#39;s table.
Definition: Catalog.h:117
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:494
T lower_bound(T... args)
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:280
result_type operator()(RecordT const &r) const
Definition: Catalog.h:691
CatalogT(std::shared_ptr< Table > const &table, InputIterator first, InputIterator last, bool deep=false)
Construct a catalog from a table and an iterator range.
Definition: Catalog.h:142
std::pair< int, int > _Catalog_equal_range(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:871
CatalogIterator & operator=(std::shared_ptr< RecordT > const &other) const
Definition: Catalog.h:55
Internal const & getInternal() const
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:651
int const step
Definition: BoundedField.cc:97
STL class.
static CatalogT readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU, int flags=0)
Read a FITS binary table from a regular file.
Definition: Catalog.h:337
CatalogT(CatalogT const &other)
Shallow copy constructor.
Definition: Catalog.h:148
const_iterator cend() const
Iterator access.
Definition: Catalog.h:395
int _Catalog_upper_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:866
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.
Definition: Catalog.h:195
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:457
A base class for image defects.
void clear()
Remove all records from the catalog.
Definition: Catalog.h:555
reference front() const
Return the first record.
Definition: Catalog.h:434
int end
Internal::size_type size_type
Definition: Catalog.h:108
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:102
iterator end()
Iterator access.
Definition: Catalog.h:391
CatalogT(Schema const &schema)
Construct a catalog from a schema, creating a table with Table::make(schema).
Definition: Catalog.h:129
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Definition: Catalog.h:541
Iterator class for CatalogT.
Definition: Catalog.h:38
size_type capacity() const
Return the capacity of the catalog.
Definition: Catalog.h:414
table::Key< int > b
Record::ColumnView ColumnView
Definition: Catalog.h:103
T make_pair(T... args)
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
Definition: Catalog.h:544
CatalogIterator(BaseT const &base)
Definition: Catalog.h:47
CatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition: Catalog.h:125
bool empty() const
Return true if the catalog has no records.
Definition: Catalog.h:399
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Catalog.h:323
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:111
void swap(CatalogT &other)
Shallow swap of two catalogs.
Definition: Catalog.h:549
void writeFits(std::string const &filename, std::string const &mode="w", int flags=0) const
Write a FITS binary table to a regular file.
Definition: Catalog.h:300
const_iterator begin() const
Iterator access.
Definition: Catalog.h:392
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition: Catalog.h:422
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
Definition: Catalog.h:530
#define LSST_EXCEPT(type,...)
STL class.
bool isContiguous() const
Return true if all records are contiguous.
Definition: Catalog.h:382
Record::Table Table
Definition: Catalog.h:102
void assign(InputIterator first, InputIterator last, bool deep=false)
Replace the contents of the table with an iterator range.
Definition: Catalog.h:451
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
T Value
the type returned by BaseRecord::get
Definition: FieldBase.h:45
const_iterator cbegin() const
Iterator access.
Definition: Catalog.h:394
iterator find(typename Field< T >::Value const &value, Key< T > const &key)
Return an iterator to the record with the given value.
Definition: Catalog.h:737
ColumnView getColumnView() const
Return a ColumnView of this catalog&#39;s records.
Definition: Catalog.h:371
reference operator[](size_type i) const
Return the record at index i.
Definition: Catalog.h:428
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:37
bool operator()(RecordT const &a, RecordT const &b) const
Definition: Catalog.h:673
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.
Definition: Catalog.h:515
table::Key< int > a
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:402
const_iterator end() const
Iterator access.
Definition: Catalog.h:393
iterator begin()
Iterator access.
Definition: Catalog.h:390
std::pair< iterator, iterator > equal_range(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
reference at(size_type i) const
Return the record at index i (throws std::out_of_range).
Definition: Catalog.h:431
static CatalogT readFits(fits::Fits &fitsfile, int flags=0)
Read a FITS binary table from a file object already at the correct extension.
Definition: Catalog.h:362
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition: Catalog.h:785
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition: Catalog.h:476
void writeFits(fits::MemFileManager &manager, std::string const &mode="w", int flags=0) const
Write a FITS binary table to a RAM file.
Definition: Catalog.h:312
Table of amplifier information (AmpInfoRecord records)
Definition: AmpInfo.h:168
T equal_range(T... args)
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:110
std::shared_ptr< RecordT > pointer
Definition: Catalog.h:107
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition: Catalog.h:466
friend class boost::iterator_core_access
Definition: Catalog.h:61