LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
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  // Delegate to copy constructor for backward compatibility
151 
152  ~CatalogT() = default;
153 
160  template <typename OtherRecordT>
162  : _table(other.getTable()), _internal(other.begin().base(), other.end().base()) {}
163 
166  if (&other != this) {
167  _table = other._table;
168  _internal = other._internal;
169  }
170  return *this;
171  }
172  // Delegate to copy assignment for backward compatibility
173  CatalogT& operator=(CatalogT&& other) { return *this = other; }
174 
180  CatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
181  if (size_type(mask.size()) != size()) {
182  throw LSST_EXCEPT(
184  (boost::format("Mask array with %d elements applied to catalog with %d elements") %
185  mask.size() % size())
186  .str());
187  }
190  const_iterator catIter = begin();
191  for (; maskIter != mask.end(); ++maskIter, ++catIter) {
192  if (*maskIter) result.push_back(catIter);
193  }
194  return result;
195  }
196 
202  /* Python's slicing syntax is weird and wonderful.
203 
204  Both the "start" and "stop" indices can be negative, which means the
205  abs() of the index less than the size; [-1] means the last item.
206  Moreover, it's possible to have a negative index less than -len(); it
207  will get clipped. That is in fact one way to slice *backward* through
208  the array *and* include element 0;
209 
210  >>> range(10)[5:-20:-1]
211  [5, 4, 3, 2, 1, 0]
212 
213  The clipping tests in this function look more complicated than they
214  need to be, but that is partly because there are some weird edge cases.
215 
216  Also, ptrdiff_t vs size_t introduces some annoying complexity. Note
217  that the args are "startd"/"stopd" (not "start"/"stop").
218 
219  There is a fairly complete set of tests in tests/ticket2026.py; if you
220  try to simplify this function, be sure they continue to pass.
221  */
222  size_type S = size();
223  size_type start, stop = 0;
224  // Python doesn't allow step == 0
225  if (step == 0) {
226  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Step cannot be zero");
227  }
228  // Basic negative indexing rule: first add size
229  if (startd < 0) {
230  startd += S;
231  }
232  if (stopd < 0) {
233  stopd += S;
234  }
235  // Start gets clipped to zero; stop does not (yet).
236  if (startd < 0) {
237  startd = 0;
238  }
239  // Now start is non-negative, so can cast to size_t.
240  start = (size_type)startd;
241  if (start > S) {
242  start = S;
243  }
244  if (step > 0) {
245  // When stepping forward, stop gets clipped at zero,
246  // so is non-negative and can get cast to size_t.
247  if (stopd < 0) {
248  stopd = 0;
249  }
250  stop = (size_type)stopd;
251  if (stop > S) {
252  stop = S;
253  }
254  } else if (step < 0) {
255  // When stepping backward, stop gets clipped at -1 so that slices
256  // including 0 are possible.
257  if (stopd < 0) {
258  stopd = -1;
259  }
260  }
261 
262  if (((step > 0) && (start >= stop)) || ((step < 0) && ((std::ptrdiff_t)start <= stopd))) {
263  // Empty range
264  return CatalogT<RecordT>(getTable(), begin(), begin());
265  }
266 
267  if (step == 1) {
268  // Use the iterator-based constructor for this simple case
269  assert(start >= 0);
270  assert(stop > 0);
271  assert(start < S);
272  assert(stop <= S);
273  return CatalogT<RecordT>(getTable(), begin() + start, begin() + stop);
274  }
275 
276  // Build a new CatalogT and copy records into it.
278  size_type N = 0;
279  if (step >= 0) {
280  N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
281  } else {
282  N = (size_t)((stopd - (std::ptrdiff_t)start) / step +
283  (((stopd - (std::ptrdiff_t)start) % step) ? 1 : 0));
284  }
285  cat.reserve(N);
286  if (step >= 0) {
287  for (size_type i = start; i < stop; i += step) {
288  cat.push_back(get(i));
289  }
290  } else {
291  for (std::ptrdiff_t i = (std::ptrdiff_t)start; i > stopd; i += step) {
292  cat.push_back(get(i));
293  }
294  }
295  return cat;
296  }
297 
306  void writeFits(std::string const& filename, std::string const& mode = "w", int flags = 0) const {
307  io::FitsWriter::apply(filename, mode, *this, flags);
308  }
309 
318  void writeFits(fits::MemFileManager& manager, std::string const& mode = "w", int flags = 0) const {
319  io::FitsWriter::apply(manager, mode, *this, flags);
320  }
321 
329  void writeFits(fits::Fits& fitsfile, int flags = 0) const {
330  io::FitsWriter::apply(fitsfile, *this, flags);
331  }
332 
343  static CatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU, int flags = 0) {
344  return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
345  }
346 
357  static CatalogT readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU, int flags = 0) {
358  return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
359  }
360 
368  static CatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
369  return io::FitsReader::apply<CatalogT>(fitsfile, flags);
370  }
371 
379  throw LSST_EXCEPT(
381  "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
382  "non-const views).");
383  }
384  return ColumnView::make(_table, begin(), end());
385  }
386 
388  bool isContiguous() const { return ColumnView::isRangeContiguous(_table, begin(), end()); }
389 
391 
396  iterator begin() { return iterator(_internal.begin()); }
397  iterator end() { return iterator(_internal.end()); }
398  const_iterator begin() const { return const_iterator(_internal.begin()); }
399  const_iterator end() const { return const_iterator(_internal.end()); }
400  const_iterator cbegin() const { return begin(); }
401  const_iterator cend() const { return end(); }
403 
405  bool empty() const { return _internal.empty(); }
406 
408  size_type size() const { return _internal.size(); }
409 
411  size_type max_size() const { return _internal.max_size(); }
412 
420  size_type capacity() const { return _internal.size() + _table->getBufferSize(); }
421 
428  void reserve(size_type n) {
429  if (n <= _internal.size()) return;
430  _table->preallocate(n - _internal.size());
431  _internal.reserve(n);
432  }
433 
435  void resize(size_type n) {
436  size_type old = size();
437  _internal.resize(n);
438  if (old < n) {
439  _table->preallocate(n - old);
440  for (size_type i = old; i != n; ++i) {
441  _internal[i] = _table->makeRecord();
442  }
443  }
444  }
445 
447  reference operator[](size_type i) const { return *_internal[i]; }
448 
450  reference at(size_type i) const { return *_internal.at(i); }
451 
453  reference front() const { return *_internal.front(); }
454 
456  reference back() const { return *_internal.back(); }
457 
459  std::shared_ptr<RecordT> const get(size_type i) const { return _internal[i]; }
460 
462  void set(size_type i, std::shared_ptr<RecordT> const& p) { _internal[i] = p; }
463 
469  template <typename InputIterator>
470  void assign(InputIterator first, InputIterator last, bool deep = false) {
471  clear();
472  insert(end(), first, last, deep);
473  }
474 
476  void push_back(Record const& r) {
477  std::shared_ptr<RecordT> p = _table->copyRecord(r);
478  _internal.push_back(p);
479  }
480 
482  void push_back(std::shared_ptr<RecordT> const& p) { _internal.push_back(p); }
483 
486  std::shared_ptr<RecordT> r = _table->makeRecord();
487  _internal.push_back(r);
488  return r;
489  }
490 
492  void pop_back() { _internal.pop_back(); }
493 
495  CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
496 
512  template <typename InputIterator>
513  void insert(iterator pos, InputIterator first, InputIterator last, bool deep = false) {
514  _maybeReserve(pos, first, last, deep,
516  if (deep) {
517  while (first != last) {
518  pos = insert(pos, *first);
519  ++pos;
520  ++first;
521  }
522  } else {
523  while (first != last) {
524  pos = insert(pos, first);
525  assert(pos != end());
526  ++pos;
527  ++first;
528  }
529  }
530  }
531 
533  template <typename InputIterator>
534  void insert(SchemaMapper const& mapper, iterator pos, InputIterator first, InputIterator last) {
535  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
537  "SchemaMapper's output schema does not match catalog's schema");
538  }
539  _maybeReserve(pos, first, last, true,
541  while (first != last) {
542  pos = insert(pos, _table->copyRecord(*first, mapper));
543  ++pos;
544  ++first;
545  }
546  }
547 
549  iterator insert(iterator pos, Record const& r) {
550  std::shared_ptr<RecordT> p = _table->copyRecord(r);
551  return iterator(_internal.insert(pos.base(), p));
552  }
553 
556  return iterator(_internal.insert(pos.base(), p));
557  }
558 
560  iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
561 
564  return iterator(_internal.erase(first.base(), last.base()));
565  }
566 
568  void swap(CatalogT& other) noexcept {
569  _table.swap(other._table);
570  _internal.swap(other._internal);
571  }
572 
574  void clear() { _internal.clear(); }
575 
577  template <typename T>
578  bool isSorted(Key<T> const& key) const;
579 
585  template <typename Compare>
586  bool isSorted(Compare cmp) const;
587 
589  template <typename T>
590  void sort(Key<T> const& key);
591 
597  template <typename Compare>
598  void sort(Compare cmp);
599 
601 
615  template <typename T>
616  iterator find(typename Field<T>::Value const& value, Key<T> const& key);
617 
618  template <typename T>
619  const_iterator find(typename Field<T>::Value const& value, Key<T> const& key) const;
621 
623 
636  template <typename T>
637  iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key);
638 
639  template <typename T>
640  const_iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
641 
642  template <typename T>
643  iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key);
644 
645  template <typename T>
646  const_iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
647 
648  template <typename T>
650 
651  template <typename T>
653  Key<T> const& key) const;
655 
657 
669  Internal& getInternal() { return _internal; }
670  Internal const& getInternal() const { return _internal; }
672 
673 private:
674  template <typename InputIterator>
675  void _maybeReserve(iterator& pos, InputIterator first, InputIterator last, bool deep,
677  if (deep) _table->preallocate(last - first);
678  }
679 
680  template <typename InputIterator>
681  void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep,
683 
684  std::shared_ptr<Table> _table;
685  Internal _internal;
686 };
687 
688 namespace detail {
689 
690 template <typename RecordT, typename T>
692  bool operator()(RecordT const& a, RecordT const& b) const { return a.get(key) < b.get(key); }
693 
695 };
696 
697 template <typename RecordT, typename Adaptee>
700  return adaptee(*a, *b);
701  }
702 
703  Adaptee adaptee;
704 };
705 
706 template <typename RecordT, typename T>
708  typedef typename Field<T>::Value result_type;
709 
710  result_type operator()(RecordT const& r) const { return r.get(key); }
711 
713 };
714 
715 } // namespace detail
716 
717 template <typename RecordT>
718 template <typename Compare>
719 bool CatalogT<RecordT>::isSorted(Compare cmp) const {
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 }
732 
733 template <typename RecordT>
734 template <typename Compare>
735 void CatalogT<RecordT>::sort(Compare cmp) {
737  std::stable_sort(_internal.begin(), _internal.end(), f);
738 }
739 
740 template <typename RecordT>
741 template <typename T>
744  return isSorted(f);
745 }
746 
747 template <typename RecordT>
748 template <typename T>
751  return sort(f);
752 }
753 
754 template <typename RecordT>
755 template <typename T>
757  Key<T> const& 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 }
766 
767 template <typename RecordT>
768 template <typename T>
770  Key<T> const& key) const {
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 }
779 
780 template <typename RecordT>
781 template <typename T>
783  Key<T> const& key) {
785  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
786  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
787  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
788  return i.base();
789 }
790 
791 template <typename RecordT>
792 template <typename T>
794  typename Field<T>::Value const& value, Key<T> const& key) const {
796  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
797  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
798  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
799  return i.base();
800 }
801 
802 template <typename RecordT>
803 template <typename T>
805  Key<T> const& key) {
807  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
808  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
809  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
810  return i.base();
811 }
812 
813 template <typename RecordT>
814 template <typename T>
816  typename Field<T>::Value const& value, Key<T> const& key) const {
818  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
819  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
820  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
821  return i.base();
822 }
823 
824 template <typename RecordT>
825 template <typename T>
829  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
830  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
832  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
833  return std::make_pair(i.first.base(), i.second.base());
834 }
835 
836 template <typename RecordT>
837 template <typename T>
839 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) const {
841  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
842  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
844  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
845  return std::make_pair(i.first.base(), i.second.base());
846 }
847 
849 
870 template <typename RecordT, typename Catalog, typename T>
871 std::shared_ptr<RecordT> _Catalog_find(Catalog const& catalog, T const& value, Key<T> const& key) {
872  typename Catalog::const_iterator iter = catalog.find(value, key);
873  if (iter == catalog.end()) {
874  return std::shared_ptr<RecordT>();
875  }
876  return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
877 }
878 
879 template <typename Catalog, typename T>
880 int _Catalog_lower_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
881  return catalog.lower_bound(value, key) - catalog.begin();
882 }
883 
884 template <typename Catalog, typename T>
885 int _Catalog_upper_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
886  return catalog.upper_bound(value, key) - catalog.begin();
887 }
888 
889 template <typename Catalog, typename T>
890 std::pair<int, int> _Catalog_equal_range(Catalog const& catalog, T const& value, Key<T> const& key) {
892  catalog.equal_range(value, key);
893  return std::pair<int, int>(p.first - catalog.begin(), p.second - catalog.begin());
894 }
895 
897 } // namespace table
898 } // namespace afw
899 } // namespace lsst
900 
901 #endif // !AFW_TABLE_Catalog_h_INCLUDED
py::object result
Definition: _schema.cc:430
int const step
int end
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
afw::table::Key< afw::table::Array< MaskPixelT > > mask
ItemVariant const * other
Definition: Schema.cc:56
Key< U > key
Definition: Schema.cc:281
SchemaMapper * mapper
Definition: SchemaMapper.cc:78
table::Key< int > b
table::Key< int > a
table::Schema schema
Definition: python.h:134
T at(T... args)
T back(T... args)
Basic LSST definitions.
T begin(T... args)
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:297
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:121
Iterator class for CatalogT.
Definition: Catalog.h:39
CatalogIterator(BaseT const &base)
Definition: Catalog.h:47
friend class boost::iterator_core_access
Definition: Catalog.h:61
CatalogIterator(CatalogIterator< OtherBaseT > const &other)
Definition: Catalog.h:44
CatalogIterator & operator=(std::shared_ptr< RecordT > const &other) const
Definition: Catalog.h:55
A custom container class for records, based on std::vector.
Definition: Catalog.h:97
void clear()
Remove all records from the catalog.
Definition: Catalog.h:574
size_type capacity() const
Return the capacity of the catalog.
Definition: Catalog.h:420
std::shared_ptr< RecordT > pointer
Definition: Catalog.h:107
CatalogT(CatalogT const &other)
Shallow copy constructor.
Definition: Catalog.h:148
const_iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key) const
Definition: Catalog.h:793
ColumnView getColumnView() const
Return a ColumnView of this catalog's records.
Definition: Catalog.h:377
void pop_back()
Remove the last record in the catalog.
Definition: Catalog.h:492
void push_back(std::shared_ptr< RecordT > const &p)
Add the given record to the end of the catalog without copying.
Definition: Catalog.h:482
reference at(size_type i) const
Return the record at index i (throws std::out_of_range).
Definition: Catalog.h:450
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:485
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:343
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
Definition: Catalog.h:563
void set(size_type i, std::shared_ptr< RecordT > const &p)
Set the record at index i to a pointer.
Definition: Catalog.h:462
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
Definition: Catalog.h:549
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:669
const_iterator end() const
Definition: Catalog.h:399
const_iterator cend() const
Definition: Catalog.h:401
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:408
bool empty() const
Return true if the catalog has no records.
Definition: Catalog.h:405
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:357
void assign(InputIterator first, InputIterator last, bool deep=false)
Replace the contents of the table with an iterator range.
Definition: Catalog.h:470
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:111
bool isContiguous() const
Return true if all records are contiguous.
Definition: Catalog.h:388
Internal::size_type size_type
Definition: Catalog.h:108
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:756
Record::ColumnView ColumnView
Definition: Catalog.h:103
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Definition: Catalog.h:804
CatalogT(Schema const &schema)
Construct a catalog from a schema, creating a table with Table::make(schema).
Definition: Catalog.h:129
reference back() const
Return the last record.
Definition: Catalog.h:456
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition: Catalog.h:555
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:201
Record::Table Table
Definition: Catalog.h:102
CatalogT & operator=(CatalogT &&other)
Definition: Catalog.h:173
CatalogT(CatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Catalog.h:161
iterator begin()
Iterator access.
Definition: Catalog.h:396
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Definition: Catalog.h:560
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
CatalogT(CatalogT &&other)
Definition: Catalog.h:150
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition: Catalog.h:428
reference operator[](size_type i) const
Return the record at index i.
Definition: Catalog.h:447
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition: Catalog.h:782
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:110
CatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition: Catalog.h:125
reference front() const
Return the first record.
Definition: Catalog.h:453
const_iterator begin() const
Definition: Catalog.h:398
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:749
std::pair< const_iterator, const_iterator > equal_range(typename Field< T >::Value const &value, Key< T > const &key) const
void resize(size_type n)
Change the size of the catalog, removing or adding empty records as needed.
Definition: Catalog.h:435
size_type max_size() const
Return the maximum number of elements allowed in a catalog.
Definition: Catalog.h:411
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition: Catalog.h:495
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:114
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:318
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Catalog.h:329
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:513
CatalogT & operator=(CatalogT const &other)
Shallow assigment.
Definition: Catalog.h:165
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:368
const_iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key) const
Definition: Catalog.h:815
Schema getSchema() const
Return the schema associated with the catalog's table.
Definition: Catalog.h:117
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:306
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:459
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
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition: Catalog.h:742
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:534
std::pair< iterator, iterator > equal_range(typename Field< T >::Value const &value, Key< T > const &key)
void swap(CatalogT &other) noexcept
Shallow swap of two catalogs.
Definition: Catalog.h:568
Internal::difference_type difference_type
Definition: Catalog.h:109
Internal const & getInternal() const
Definition: Catalog.h:670
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:476
const_iterator cbegin() const
Definition: Catalog.h:400
A class used as a handle to a particular field in a table.
Definition: Key.h:53
Defines the fields and offsets for a table.
Definition: Schema.h:50
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:37
Reports invalid arguments.
Definition: Runtime.h:66
Reports attempts to exceed implementation-defined length limits for some classes.
Definition: Runtime.h:76
Reports errors in the logical structure of the program.
Definition: Runtime.h:46
T clear(T... args)
T empty(T... args)
T end(T... args)
T equal_range(T... args)
T erase(T... args)
T front(T... args)
T insert(T... args)
T lower_bound(T... args)
T make_pair(T... args)
T max_size(T... args)
const int DEFAULT_HDU
Specify that the default HDU should be read.
Definition: fitsDefaults.h:18
int _Catalog_upper_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:885
std::shared_ptr< RecordT > _Catalog_find(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:871
std::pair< int, int > _Catalog_equal_range(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:890
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:880
FastFinder::Iterator Iterator
Definition: FastFinder.cc:178
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
A base class for image defects.
T pop_back(T... args)
T push_back(T... args)
T reserve(T... args)
T resize(T... args)
T size(T... args)
T stable_sort(T... args)
T Value
the type returned by BaseRecord::get
Definition: FieldBase.h:44
bool operator()(std::shared_ptr< RecordT > const &a, std::shared_ptr< RecordT > const &b) const
Definition: Catalog.h:699
bool operator()(RecordT const &a, RecordT const &b) const
Definition: Catalog.h:692
result_type operator()(RecordT const &r) const
Definition: Catalog.h:710
T swap(T... args)
T upper_bound(T... args)