LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
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 #include "lsst/log/Log.h"
19 
20 namespace lsst {
21 namespace afw {
22 namespace table {
23 
38 template <typename BaseT>
39 class CatalogIterator : public boost::iterator_adaptor<CatalogIterator<BaseT>, BaseT,
40  typename BaseT::value_type::element_type> {
41 public:
43 
44  template <typename OtherBaseT>
46  : CatalogIterator::iterator_adaptor_(other.base()) {}
47 
48  explicit CatalogIterator(BaseT const& base) : CatalogIterator::iterator_adaptor_(base) {}
49 
50  template <typename RecordT>
51  operator std::shared_ptr<RecordT>() const {
52  return *this->base();
53  }
54 
55  template <typename RecordT>
57  *this->base() = other;
58  return *this;
59  }
60 
61 private:
63  typename BaseT::value_type::element_type& dereference() const { return **this->base(); }
64 };
65 
97 template <typename RecordT>
98 class CatalogT {
100 
101 public:
102  using Record = RecordT;
103  using Table = typename Record::Table;
104  using ColumnView = typename Record::ColumnView;
105 
106  using value_type = RecordT;
107  using reference = RecordT &;
109  using size_type = typename Internal::size_type;
110  using difference_type = typename Internal::difference_type;
113 
115  std::shared_ptr<Table> getTable() const { return _table; }
116 
118  Schema getSchema() const { return _table->getSchema(); }
119 
126  : _table(table), _internal() {
127  if(!_table) {
128  auto schema=Table::makeMinimalSchema();
129  _table=Table::make(schema);
130  }
131  }
132 
134  explicit CatalogT(Schema const& schema) : _table(Table::make(schema)), _internal() {}
135 
146  template <typename InputIterator>
147  CatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last, bool deep = false)
148  : _table(table), _internal() {
149  insert(end(), first, last, deep);
150  }
151 
153  CatalogT(CatalogT const& other) : _table(other._table), _internal(other._internal) {}
154  // Delegate to copy constructor for backward compatibility
155  CatalogT(CatalogT&& other) : CatalogT(other) {}
156 
157  ~CatalogT() = default;
158 
165  template <typename OtherRecordT>
167  : _table(other.getTable()), _internal(other.begin().base(), other.end().base()) {}
168 
170  CatalogT& operator=(CatalogT const& other) {
171  if (&other != this) {
172  _table = other._table;
173  _internal = other._internal;
174  }
175  return *this;
176  }
177  // Delegate to copy assignment for backward compatibility
178  CatalogT& operator=(CatalogT&& other) { return *this = other; }
179 
185  CatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
186  if (size_type(mask.size()) != size()) {
187  throw LSST_EXCEPT(
189  (boost::format("Mask array with %d elements applied to catalog with %d elements") %
190  mask.size() % size())
191  .str());
192  }
195  const_iterator catIter = begin();
196  for (; maskIter != mask.end(); ++maskIter, ++catIter) {
197  if (*maskIter) result.push_back(catIter);
198  }
199  return result;
200  }
201 
207  /* Python's slicing syntax is weird and wonderful.
208 
209  Both the "start" and "stop" indices can be negative, which means the
210  abs() of the index less than the size; [-1] means the last item.
211  Moreover, it's possible to have a negative index less than -len(); it
212  will get clipped. That is in fact one way to slice *backward* through
213  the array *and* include element 0;
214 
215  >>> range(10)[5:-20:-1]
216  [5, 4, 3, 2, 1, 0]
217 
218  The clipping tests in this function look more complicated than they
219  need to be, but that is partly because there are some weird edge cases.
220 
221  Also, ptrdiff_t vs size_t introduces some annoying complexity. Note
222  that the args are "startd"/"stopd" (not "start"/"stop").
223 
224  There is a fairly complete set of tests in tests/ticket2026.py; if you
225  try to simplify this function, be sure they continue to pass.
226  */
227  size_type S = size();
228  size_type start, stop = 0;
229  // Python doesn't allow step == 0
230  if (step == 0) {
231  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Step cannot be zero");
232  }
233  // Basic negative indexing rule: first add size
234  if (startd < 0) {
235  startd += S;
236  }
237  if (stopd < 0) {
238  stopd += S;
239  }
240  // Start gets clipped to zero; stop does not (yet).
241  if (startd < 0) {
242  startd = 0;
243  }
244  // Now start is non-negative, so can cast to size_t.
245  start = (size_type)startd;
246  if (start > S) {
247  start = S;
248  }
249  if (step > 0) {
250  // When stepping forward, stop gets clipped at zero,
251  // so is non-negative and can get cast to size_t.
252  if (stopd < 0) {
253  stopd = 0;
254  }
255  stop = (size_type)stopd;
256  if (stop > S) {
257  stop = S;
258  }
259  } else if (step < 0) {
260  // When stepping backward, stop gets clipped at -1 so that slices
261  // including 0 are possible.
262  if (stopd < 0) {
263  stopd = -1;
264  }
265  }
266 
267  if (((step > 0) && (start >= stop)) || ((step < 0) && ((std::ptrdiff_t)start <= stopd))) {
268  // Empty range
269  return CatalogT<RecordT>(getTable(), begin(), begin());
270  }
271 
272  if (step == 1) {
273  // Use the iterator-based constructor for this simple case
274  assert(start >= 0);
275  assert(stop > 0);
276  assert(start < S);
277  assert(stop <= S);
278  return CatalogT<RecordT>(getTable(), begin() + start, begin() + stop);
279  }
280 
281  // Build a new CatalogT and copy records into it.
283  size_type N = 0;
284  if (step >= 0) {
285  N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
286  } else {
287  N = (size_t)((stopd - (std::ptrdiff_t)start) / step +
288  (((stopd - (std::ptrdiff_t)start) % step) ? 1 : 0));
289  }
290  cat.reserve(N);
291  if (step >= 0) {
292  for (size_type i = start; i < stop; i += step) {
293  cat.push_back(get(i));
294  }
295  } else {
296  for (std::ptrdiff_t i = (std::ptrdiff_t)start; i > stopd; i += step) {
297  cat.push_back(get(i));
298  }
299  }
300  return cat;
301  }
302 
311  void writeFits(std::string const& filename, std::string const& mode = "w", int flags = 0) const {
312  io::FitsWriter::apply(filename, mode, *this, flags);
313  }
314 
323  void writeFits(fits::MemFileManager& manager, std::string const& mode = "w", int flags = 0) const {
324  io::FitsWriter::apply(manager, mode, *this, flags);
325  }
326 
334  void writeFits(fits::Fits& fitsfile, int flags = 0) const {
335  io::FitsWriter::apply(fitsfile, *this, flags);
336  }
337 
348  static CatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU, int flags = 0) {
349  return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
350  }
351 
362  static CatalogT readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU, int flags = 0) {
363  return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
364  }
365 
373  static CatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
374  return io::FitsReader::apply<CatalogT>(fitsfile, flags);
375  }
376 
384  throw LSST_EXCEPT(
386  "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
387  "non-const views).");
388  }
389  return ColumnView::make(_table, begin(), end());
390  }
391 
393  bool isContiguous() const { return ColumnView::isRangeContiguous(_table, begin(), end()); }
394 
396 
401  iterator begin() { return iterator(_internal.begin()); }
402  iterator end() { return iterator(_internal.end()); }
403  const_iterator begin() const { return const_iterator(_internal.begin()); }
404  const_iterator end() const { return const_iterator(_internal.end()); }
405  const_iterator cbegin() const { return begin(); }
406  const_iterator cend() const { return end(); }
408 
410  bool empty() const { return _internal.empty(); }
411 
413  size_type size() const { return _internal.size(); }
414 
416  size_type max_size() const { return _internal.max_size(); }
417 
425  size_type capacity() const { return _internal.size() + _table->getBufferSize(); }
426 
433  void reserve(size_type n) {
434  if (n <= _internal.size()) return;
435  _table->preallocate(n - _internal.size());
436  _internal.reserve(n);
437  }
438 
440  void resize(size_type n) {
441  size_type old = size();
442  _internal.resize(n);
443  if (old < n) {
444  _table->preallocate(n - old);
445  for (size_type i = old; i != n; ++i) {
446  _internal[i] = _table->makeRecord();
447  }
448  }
449  }
450 
452  reference operator[](size_type i) const { return *_internal[i]; }
453 
455  reference at(size_type i) const { return *_internal.at(i); }
456 
458  reference front() const { return *_internal.front(); }
459 
461  reference back() const { return *_internal.back(); }
462 
464  std::shared_ptr<RecordT> const get(size_type i) const { return _internal[i]; }
465 
467  void set(size_type i, std::shared_ptr<RecordT> const& p) { _internal[i] = p; }
468 
474  template <typename InputIterator>
475  void assign(InputIterator first, InputIterator last, bool deep = false) {
476  clear();
477  insert(end(), first, last, deep);
478  }
479 
481  void push_back(Record const& r) {
482  std::shared_ptr<RecordT> p = _table->copyRecord(r);
483  _internal.push_back(p);
484  }
485 
487  void push_back(std::shared_ptr<RecordT> const& p) { _internal.push_back(p); }
488 
491  std::shared_ptr<RecordT> r = _table->makeRecord();
492  _internal.push_back(r);
493  return r;
494  }
495 
497  void pop_back() { _internal.pop_back(); }
498 
500  CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
501 
517  template <typename InputIterator>
518  void insert(iterator pos, InputIterator first, InputIterator last, bool deep = false) {
519  _maybeReserve(pos, first, last, deep,
521  if (deep) {
522  while (first != last) {
523  pos = insert(pos, *first);
524  ++pos;
525  ++first;
526  }
527  } else {
528  while (first != last) {
529  pos = insert(pos, first);
530  assert(pos != end());
531  ++pos;
532  ++first;
533  }
534  }
535  }
536 
538  template <typename InputIterator>
539  void insert(SchemaMapper const& mapper, iterator pos, InputIterator first, InputIterator last) {
540  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
542  "SchemaMapper's output schema does not match catalog's schema");
543  }
544  _maybeReserve(pos, first, last, true,
546  while (first != last) {
547  pos = insert(pos, _table->copyRecord(*first, mapper));
548  ++pos;
549  ++first;
550  }
551  }
552 
554  iterator insert(iterator pos, Record const& r) {
555  std::shared_ptr<RecordT> p = _table->copyRecord(r);
556  return iterator(_internal.insert(pos.base(), p));
557  }
558 
561  return iterator(_internal.insert(pos.base(), p));
562  }
563 
565  iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
566 
569  return iterator(_internal.erase(first.base(), last.base()));
570  }
571 
573  void swap(CatalogT& other) noexcept {
574  _table.swap(other._table);
575  _internal.swap(other._internal);
576  }
577 
579  void clear() { _internal.clear(); }
580 
582  template <typename T>
583  bool isSorted(Key<T> const& key) const;
584 
590  template <typename Compare>
591  bool isSorted(Compare cmp) const;
592 
594  template <typename T>
595  void sort(Key<T> const& key);
596 
602  template <typename Compare>
603  void sort(Compare cmp);
604 
606 
622  template <typename T>
623  iterator find(typename Field<T>::Value const& value, Key<T> const& key);
624 
625  template <typename T>
626  const_iterator find(typename Field<T>::Value const& value, Key<T> const& key) const;
628 
630 
643  template <typename T>
644  iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key);
645 
646  template <typename T>
647  const_iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
648 
649  template <typename T>
650  iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key);
651 
652  template <typename T>
653  const_iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
654 
655  template <typename T>
657 
658  template <typename T>
660  Key<T> const& key) const;
662 
664 
676  Internal& getInternal() { return _internal; }
677  Internal const& getInternal() const { return _internal; }
679 
680 private:
681  template <typename InputIterator>
682  void _maybeReserve(iterator& pos, InputIterator first, InputIterator last, bool deep,
684  if (deep) _table->preallocate(last - first);
685  }
686 
687  template <typename InputIterator>
688  void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep,
690 
691  std::shared_ptr<Table> _table;
692  Internal _internal;
693 };
694 
695 namespace detail {
696 
697 template <typename RecordT, typename T>
699  bool operator()(RecordT const& a, RecordT const& b) const { return a.get(key) < b.get(key); }
700 
702 };
703 
704 template <typename RecordT, typename Adaptee>
707  return adaptee(*a, *b);
708  }
709 
710  Adaptee adaptee;
711 };
712 
713 template <typename RecordT, typename T>
715  using result_type = typename Field<T>::Value;
716 
717  result_type operator()(RecordT const& r) const { return r.get(key); }
718 
720 };
721 
722 } // namespace detail
723 
724 template <typename RecordT>
725 template <typename Compare>
726 bool CatalogT<RecordT>::isSorted(Compare cmp) const {
729  if (empty()) return true;
730  const_iterator last = this->begin();
731  const_iterator i = last;
732  ++i;
733  for (; i != this->end(); ++i) {
734  if (f(i, last)) return false;
735  last = i;
736  }
737  return true;
738 }
739 
740 template <typename RecordT>
741 template <typename Compare>
742 void CatalogT<RecordT>::sort(Compare cmp) {
744  std::stable_sort(_internal.begin(), _internal.end(), f);
745 }
746 
747 template <typename RecordT>
748 template <typename T>
749 bool CatalogT<RecordT>::isSorted(Key<T> const& key) const {
751  return isSorted(f);
752 }
753 
754 template <typename RecordT>
755 template <typename T>
756 void CatalogT<RecordT>::sort(Key<T> const& key) {
758  return sort(f);
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  using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
768  /* Try binary search for log n search assuming the table is sorted.
769  * If the search is unsuccessful, try a brute-force search before quitting.
770  */
771  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
772  if (i.base() == end() || *i != value) {
773  i = std::find(SearchIter(begin(), f), SearchIter(end(), f), value);
774  if (i.base() == end()) {
775  return end();
776  }
777  LOGL_DEBUG("lsst.afw.table.Catalog", "Catalog is not sorted by the key. Finding a record may be slow.");
778  }
779  return i.base();
780 }
781 
782 template <typename RecordT>
783 template <typename T>
785  Key<T> const& key) const {
787  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
788  using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
789  /* Try binary search for log n search assuming the table is sorted.
790  * If the search is unsuccessful, try a brute-force search before quitting.
791  */
792  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
793  if (i.base() == end() || *i != value) {
794  i = std::find(SearchIter(begin(), f), SearchIter(end(), f), value);
795  if (i.base() == end()) {
796  return end();
797  }
798  LOGL_DEBUG("lsst.afw.table.Catalog", "Catalog is not sorted by the key. Finding a record may be slow.");
799  }
800  return i.base();
801 }
802 
803 template <typename RecordT>
804 template <typename T>
806  Key<T> const& key) {
808  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
809  using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
810  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
811  return i.base();
812 }
813 
814 template <typename RecordT>
815 template <typename T>
817  typename Field<T>::Value const& value, Key<T> const& key) const {
819  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
820  using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
821  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
822  return i.base();
823 }
824 
825 template <typename RecordT>
826 template <typename T>
828  Key<T> const& key) {
830  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
831  using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
832  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
833  return i.base();
834 }
835 
836 template <typename RecordT>
837 template <typename T>
839  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  using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
843  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
844  return i.base();
845 }
846 
847 template <typename RecordT>
848 template <typename T>
850 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) {
852  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
853  using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
855  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
856  return std::make_pair(i.first.base(), i.second.base());
857 }
858 
859 template <typename RecordT>
860 template <typename T>
862 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) const {
864  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
865  using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
867  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
868  return std::make_pair(i.first.base(), i.second.base());
869 }
870 
872 
893 template <typename RecordT, typename Catalog, typename T>
894 std::shared_ptr<RecordT> _Catalog_find(Catalog const& catalog, T const& value, Key<T> const& key) {
895  typename Catalog::const_iterator iter = catalog.find(value, key);
896  if (iter == catalog.end()) {
897  return std::shared_ptr<RecordT>();
898  }
899  return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
900 }
901 
902 template <typename Catalog, typename T>
903 int _Catalog_lower_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
904  return catalog.lower_bound(value, key) - catalog.begin();
905 }
906 
907 template <typename Catalog, typename T>
908 int _Catalog_upper_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
909  return catalog.upper_bound(value, key) - catalog.begin();
910 }
911 
912 template <typename Catalog, typename T>
913 std::pair<int, int> _Catalog_equal_range(Catalog const& catalog, T const& value, Key<T> const& key) {
915  catalog.equal_range(value, key);
916  return std::pair<int, int>(p.first - catalog.begin(), p.second - catalog.begin());
917 }
918 
920 } // namespace table
921 } // namespace afw
922 } // namespace lsst
923 
924 #endif // !AFW_TABLE_Catalog_h_INCLUDED
py::object result
Definition: _schema.cc:429
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
LSST DM logging module built on log4cxx.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:515
SchemaMapper * mapper
Definition: SchemaMapper.cc:71
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:40
CatalogIterator(BaseT const &base)
Definition: Catalog.h:48
friend class boost::iterator_core_access
Definition: Catalog.h:62
CatalogIterator(CatalogIterator< OtherBaseT > const &other)
Definition: Catalog.h:45
CatalogIterator & operator=(std::shared_ptr< RecordT > const &other) const
Definition: Catalog.h:56
A custom container class for records, based on std::vector.
Definition: Catalog.h:98
void clear()
Remove all records from the catalog.
Definition: Catalog.h:579
size_type capacity() const
Return the capacity of the catalog.
Definition: Catalog.h:425
CatalogT(CatalogT const &other)
Shallow copy constructor.
Definition: Catalog.h:153
const_iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key) const
Definition: Catalog.h:816
ColumnView getColumnView() const
Return a ColumnView of this catalog's records.
Definition: Catalog.h:382
void pop_back()
Remove the last record in the catalog.
Definition: Catalog.h:497
void push_back(std::shared_ptr< RecordT > const &p)
Add the given record to the end of the catalog without copying.
Definition: Catalog.h:487
reference at(size_type i) const
Return the record at index i (throws std::out_of_range).
Definition: Catalog.h:455
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:490
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:348
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
Definition: Catalog.h:568
void set(size_type i, std::shared_ptr< RecordT > const &p)
Set the record at index i to a pointer.
Definition: Catalog.h:467
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
Definition: Catalog.h:554
typename Record::ColumnView ColumnView
Definition: Catalog.h:104
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:676
const_iterator end() const
Definition: Catalog.h:404
const_iterator cend() const
Definition: Catalog.h:406
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:413
bool empty() const
Return true if the catalog has no records.
Definition: Catalog.h:410
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:362
void assign(InputIterator first, InputIterator last, bool deep=false)
Replace the contents of the table with an iterator range.
Definition: Catalog.h:475
bool isContiguous() const
Return true if all records are contiguous.
Definition: Catalog.h:393
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:763
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Definition: Catalog.h:827
CatalogT(Schema const &schema)
Construct a catalog from a schema, creating a table with Table::make(schema).
Definition: Catalog.h:134
reference back() const
Return the last record.
Definition: Catalog.h:461
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition: Catalog.h:560
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:206
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:111
CatalogT & operator=(CatalogT &&other)
Definition: Catalog.h:178
CatalogT(CatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Catalog.h:166
iterator begin()
Iterator access.
Definition: Catalog.h:401
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Definition: Catalog.h:565
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:185
CatalogT(CatalogT &&other)
Definition: Catalog.h:155
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:112
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition: Catalog.h:433
reference operator[](size_type i) const
Return the record at index i.
Definition: Catalog.h:452
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition: Catalog.h:805
typename Record::Table Table
Definition: Catalog.h:103
typename Internal::size_type size_type
Definition: Catalog.h:109
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:458
const_iterator begin() const
Definition: Catalog.h:403
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:756
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:440
size_type max_size() const
Return the maximum number of elements allowed in a catalog.
Definition: Catalog.h:416
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition: Catalog.h:500
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:115
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:323
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Catalog.h:334
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:518
CatalogT & operator=(CatalogT const &other)
Shallow assigment.
Definition: Catalog.h:170
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:373
const_iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key) const
Definition: Catalog.h:838
Schema getSchema() const
Return the schema associated with the catalog's table.
Definition: Catalog.h:118
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:311
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:464
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:147
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition: Catalog.h:749
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:539
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:573
Internal const & getInternal() const
Definition: Catalog.h:677
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:481
const_iterator cbegin() const
Definition: Catalog.h:405
typename Internal::difference_type difference_type
Definition: Catalog.h:110
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:51
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 find(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:908
std::shared_ptr< RecordT > _Catalog_find(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:894
std::pair< int, int > _Catalog_equal_range(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:913
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:903
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:42
bool operator()(std::shared_ptr< RecordT > const &a, std::shared_ptr< RecordT > const &b) const
Definition: Catalog.h:706
bool operator()(RecordT const &a, RecordT const &b) const
Definition: Catalog.h:699
result_type operator()(RecordT const &r) const
Definition: Catalog.h:717
typename Field< T >::Value result_type
Definition: Catalog.h:715
T swap(T... args)
T upper_bound(T... args)