lsst.afw  21.0.0-35-g4939cbb3d+fb0e51fe34
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  typedef RecordT Record;
103  typedef typename Record::Table Table;
104  typedef typename Record::ColumnView ColumnView;
105 
106  typedef RecordT value_type;
107  typedef RecordT& reference;
109  typedef typename Internal::size_type size_type;
110  typedef typename Internal::difference_type difference_type;
113 
115  std::shared_ptr<Table> getTable() const { return _table; }
116 
118  Schema getSchema() const { return _table->getSchema(); }
119 
127  : _table(table), _internal() {}
128 
130  explicit CatalogT(Schema const& schema) : _table(Table::make(schema)), _internal() {}
131 
142  template <typename InputIterator>
143  CatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last, bool deep = false)
144  : _table(table), _internal() {
145  insert(end(), first, last, deep);
146  }
147 
149  CatalogT(CatalogT const& other) : _table(other._table), _internal(other._internal) {}
150  // Delegate to copy constructor for backward compatibility
151  CatalogT(CatalogT&& other) : CatalogT(other) {}
152 
153  ~CatalogT() = default;
154 
161  template <typename OtherRecordT>
163  : _table(other.getTable()), _internal(other.begin().base(), other.end().base()) {}
164 
166  CatalogT& operator=(CatalogT const& other) {
167  if (&other != this) {
168  _table = other._table;
169  _internal = other._internal;
170  }
171  return *this;
172  }
173  // Delegate to copy assignment for backward compatibility
174  CatalogT& operator=(CatalogT&& other) { return *this = other; }
175 
181  CatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
182  if (size_type(mask.size()) != size()) {
183  throw LSST_EXCEPT(
185  (boost::format("Mask array with %d elements applied to catalog with %d elements") %
186  mask.size() % size())
187  .str());
188  }
189  CatalogT<RecordT> result(getTable());
190  ndarray::Array<bool const, 1>::Iterator maskIter = mask.begin();
191  const_iterator catIter = begin();
192  for (; maskIter != mask.end(); ++maskIter, ++catIter) {
193  if (*maskIter) result.push_back(catIter);
194  }
195  return result;
196  }
197 
203  /* Python's slicing syntax is weird and wonderful.
204 
205  Both the "start" and "stop" indices can be negative, which means the
206  abs() of the index less than the size; [-1] means the last item.
207  Moreover, it's possible to have a negative index less than -len(); it
208  will get clipped. That is in fact one way to slice *backward* through
209  the array *and* include element 0;
210 
211  >>> range(10)[5:-20:-1]
212  [5, 4, 3, 2, 1, 0]
213 
214  The clipping tests in this function look more complicated than they
215  need to be, but that is partly because there are some weird edge cases.
216 
217  Also, ptrdiff_t vs size_t introduces some annoying complexity. Note
218  that the args are "startd"/"stopd" (not "start"/"stop").
219 
220  There is a fairly complete set of tests in tests/ticket2026.py; if you
221  try to simplify this function, be sure they continue to pass.
222  */
223  size_type S = size();
224  size_type start, stop = 0;
225  // Python doesn't allow step == 0
226  if (step == 0) {
227  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Step cannot be zero");
228  }
229  // Basic negative indexing rule: first add size
230  if (startd < 0) {
231  startd += S;
232  }
233  if (stopd < 0) {
234  stopd += S;
235  }
236  // Start gets clipped to zero; stop does not (yet).
237  if (startd < 0) {
238  startd = 0;
239  }
240  // Now start is non-negative, so can cast to size_t.
241  start = (size_type)startd;
242  if (start > S) {
243  start = S;
244  }
245  if (step > 0) {
246  // When stepping forward, stop gets clipped at zero,
247  // so is non-negative and can get cast to size_t.
248  if (stopd < 0) {
249  stopd = 0;
250  }
251  stop = (size_type)stopd;
252  if (stop > S) {
253  stop = S;
254  }
255  } else if (step < 0) {
256  // When stepping backward, stop gets clipped at -1 so that slices
257  // including 0 are possible.
258  if (stopd < 0) {
259  stopd = -1;
260  }
261  }
262 
263  if (((step > 0) && (start >= stop)) || ((step < 0) && ((std::ptrdiff_t)start <= stopd))) {
264  // Empty range
265  return CatalogT<RecordT>(getTable(), begin(), begin());
266  }
267 
268  if (step == 1) {
269  // Use the iterator-based constructor for this simple case
270  assert(start >= 0);
271  assert(stop > 0);
272  assert(start < S);
273  assert(stop <= S);
274  return CatalogT<RecordT>(getTable(), begin() + start, begin() + stop);
275  }
276 
277  // Build a new CatalogT and copy records into it.
279  size_type N = 0;
280  if (step >= 0) {
281  N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
282  } else {
283  N = (size_t)((stopd - (std::ptrdiff_t)start) / step +
284  (((stopd - (std::ptrdiff_t)start) % step) ? 1 : 0));
285  }
286  cat.reserve(N);
287  if (step >= 0) {
288  for (size_type i = start; i < stop; i += step) {
289  cat.push_back(get(i));
290  }
291  } else {
292  for (std::ptrdiff_t i = (std::ptrdiff_t)start; i > stopd; i += step) {
293  cat.push_back(get(i));
294  }
295  }
296  return cat;
297  }
298 
307  void writeFits(std::string const& filename, std::string const& mode = "w", int flags = 0) const {
308  io::FitsWriter::apply(filename, mode, *this, flags);
309  }
310 
319  void writeFits(fits::MemFileManager& manager, std::string const& mode = "w", int flags = 0) const {
320  io::FitsWriter::apply(manager, mode, *this, flags);
321  }
322 
330  void writeFits(fits::Fits& fitsfile, int flags = 0) const {
331  io::FitsWriter::apply(fitsfile, *this, flags);
332  }
333 
344  static CatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU, int flags = 0) {
345  return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
346  }
347 
358  static CatalogT readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU, int flags = 0) {
359  return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
360  }
361 
369  static CatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
370  return io::FitsReader::apply<CatalogT>(fitsfile, flags);
371  }
372 
380  throw LSST_EXCEPT(
382  "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
383  "non-const views).");
384  }
385  return ColumnView::make(_table, begin(), end());
386  }
387 
389  bool isContiguous() const { return ColumnView::isRangeContiguous(_table, begin(), end()); }
390 
392 
397  iterator begin() { return iterator(_internal.begin()); }
398  iterator end() { return iterator(_internal.end()); }
399  const_iterator begin() const { return const_iterator(_internal.begin()); }
400  const_iterator end() const { return const_iterator(_internal.end()); }
401  const_iterator cbegin() const { return begin(); }
402  const_iterator cend() const { return end(); }
404 
406  bool empty() const { return _internal.empty(); }
407 
409  size_type size() const { return _internal.size(); }
410 
412  size_type max_size() const { return _internal.max_size(); }
413 
421  size_type capacity() const { return _internal.size() + _table->getBufferSize(); }
422 
429  void reserve(size_type n) {
430  if (n <= _internal.size()) return;
431  _table->preallocate(n - _internal.size());
432  _internal.reserve(n);
433  }
434 
436  void resize(size_type n) {
437  size_type old = size();
438  _internal.resize(n);
439  if (old < n) {
440  _table->preallocate(n - old);
441  for (size_type i = old; i != n; ++i) {
442  _internal[i] = _table->makeRecord();
443  }
444  }
445  }
446 
448  reference operator[](size_type i) const { return *_internal[i]; }
449 
451  reference at(size_type i) const { return *_internal.at(i); }
452 
454  reference front() const { return *_internal.front(); }
455 
457  reference back() const { return *_internal.back(); }
458 
460  std::shared_ptr<RecordT> const get(size_type i) const { return _internal[i]; }
461 
463  void set(size_type i, std::shared_ptr<RecordT> const& p) { _internal[i] = p; }
464 
470  template <typename InputIterator>
471  void assign(InputIterator first, InputIterator last, bool deep = false) {
472  clear();
473  insert(end(), first, last, deep);
474  }
475 
477  void push_back(Record const& r) {
478  std::shared_ptr<RecordT> p = _table->copyRecord(r);
479  _internal.push_back(p);
480  }
481 
483  void push_back(std::shared_ptr<RecordT> const& p) { _internal.push_back(p); }
484 
487  std::shared_ptr<RecordT> r = _table->makeRecord();
488  _internal.push_back(r);
489  return r;
490  }
491 
493  void pop_back() { _internal.pop_back(); }
494 
496  CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
497 
513  template <typename InputIterator>
514  void insert(iterator pos, InputIterator first, InputIterator last, bool deep = false) {
515  _maybeReserve(pos, first, last, deep,
517  if (deep) {
518  while (first != last) {
519  pos = insert(pos, *first);
520  ++pos;
521  ++first;
522  }
523  } else {
524  while (first != last) {
525  pos = insert(pos, first);
526  assert(pos != end());
527  ++pos;
528  ++first;
529  }
530  }
531  }
532 
534  template <typename InputIterator>
535  void insert(SchemaMapper const& mapper, iterator pos, InputIterator first, InputIterator last) {
536  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
538  "SchemaMapper's output schema does not match catalog's schema");
539  }
540  _maybeReserve(pos, first, last, true,
542  while (first != last) {
543  pos = insert(pos, _table->copyRecord(*first, mapper));
544  ++pos;
545  ++first;
546  }
547  }
548 
550  iterator insert(iterator pos, Record const& r) {
551  std::shared_ptr<RecordT> p = _table->copyRecord(r);
552  return iterator(_internal.insert(pos.base(), p));
553  }
554 
557  return iterator(_internal.insert(pos.base(), p));
558  }
559 
561  iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
562 
565  return iterator(_internal.erase(first.base(), last.base()));
566  }
567 
569  void swap(CatalogT& other) noexcept {
570  _table.swap(other._table);
571  _internal.swap(other._internal);
572  }
573 
575  void clear() { _internal.clear(); }
576 
578  template <typename T>
579  bool isSorted(Key<T> const& key) const;
580 
586  template <typename Compare>
587  bool isSorted(Compare cmp) const;
588 
590  template <typename T>
591  void sort(Key<T> const& key);
592 
598  template <typename Compare>
599  void sort(Compare cmp);
600 
602 
618  template <typename T>
619  iterator find(typename Field<T>::Value const& value, Key<T> const& key);
620 
621  template <typename T>
622  const_iterator find(typename Field<T>::Value const& value, Key<T> const& key) const;
624 
626 
639  template <typename T>
640  iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key);
641 
642  template <typename T>
643  const_iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
644 
645  template <typename T>
646  iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key);
647 
648  template <typename T>
649  const_iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
650 
651  template <typename T>
653 
654  template <typename T>
656  Key<T> const& key) const;
658 
660 
672  Internal& getInternal() { return _internal; }
673  Internal const& getInternal() const { return _internal; }
675 
676 private:
677  template <typename InputIterator>
678  void _maybeReserve(iterator& pos, InputIterator first, InputIterator last, bool deep,
680  if (deep) _table->preallocate(last - first);
681  }
682 
683  template <typename InputIterator>
684  void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep,
686 
687  std::shared_ptr<Table> _table;
688  Internal _internal;
689 };
690 
691 namespace detail {
692 
693 template <typename RecordT, typename T>
695  bool operator()(RecordT const& a, RecordT const& b) const { return a.get(key) < b.get(key); }
696 
698 };
699 
700 template <typename RecordT, typename Adaptee>
703  return adaptee(*a, *b);
704  }
705 
706  Adaptee adaptee;
707 };
708 
709 template <typename RecordT, typename T>
711  typedef typename Field<T>::Value result_type;
712 
713  result_type operator()(RecordT const& r) const { return r.get(key); }
714 
716 };
717 
718 } // namespace detail
719 
720 template <typename RecordT>
721 template <typename Compare>
722 bool CatalogT<RecordT>::isSorted(Compare cmp) const {
725  if (empty()) return true;
726  const_iterator last = this->begin();
727  const_iterator i = last;
728  ++i;
729  for (; i != this->end(); ++i) {
730  if (f(i, last)) return false;
731  last = i;
732  }
733  return true;
734 }
735 
736 template <typename RecordT>
737 template <typename Compare>
738 void CatalogT<RecordT>::sort(Compare cmp) {
740  std::stable_sort(_internal.begin(), _internal.end(), f);
741 }
742 
743 template <typename RecordT>
744 template <typename T>
745 bool CatalogT<RecordT>::isSorted(Key<T> const& key) const {
747  return isSorted(f);
748 }
749 
750 template <typename RecordT>
751 template <typename T>
752 void CatalogT<RecordT>::sort(Key<T> const& key) {
754  return sort(f);
755 }
756 
757 template <typename RecordT>
758 template <typename T>
760  Key<T> const& key) {
762  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
763  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
764  /* Try binary search for log n search assuming the table is sorted.
765  * If the search is unsuccessful, try a brute-force search before quitting.
766  */
767  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
768  if (i.base() == end() || *i != value) {
769  i = std::find(SearchIter(begin(), f), SearchIter(end(), f), value);
770  if (i.base() == end()) {
771  return end();
772  }
773  LOGL_DEBUG("afw.table.Catalog", "Catalog is not sorted by the key. Finding a record may be slow.");
774  }
775  return i.base();
776 }
777 
778 template <typename RecordT>
779 template <typename T>
781  Key<T> const& key) const {
783  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
784  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
785  /* Try binary search for log n search assuming the table is sorted.
786  * If the search is unsuccessful, try a brute-force search before quitting.
787  */
788  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
789  if (i.base() == end() || *i != value) {
790  i = std::find(SearchIter(begin(), f), SearchIter(end(), f), value);
791  if (i.base() == end()) {
792  return end();
793  }
794  LOGL_DEBUG("afw.table.Catalog", "Catalog is not sorted by the key. Finding a record may be slow.");
795  }
796  return i.base();
797 }
798 
799 template <typename RecordT>
800 template <typename T>
802  Key<T> const& key) {
804  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
805  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
806  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
807  return i.base();
808 }
809 
810 template <typename RecordT>
811 template <typename T>
813  typename Field<T>::Value const& value, Key<T> const& key) const {
815  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
816  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
817  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
818  return i.base();
819 }
820 
821 template <typename RecordT>
822 template <typename T>
824  Key<T> const& key) {
826  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
827  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
828  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
829  return i.base();
830 }
831 
832 template <typename RecordT>
833 template <typename T>
835  typename Field<T>::Value const& value, Key<T> const& key) const {
837  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
838  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
839  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
840  return i.base();
841 }
842 
843 template <typename RecordT>
844 template <typename T>
846 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) {
848  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
849  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
851  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
852  return std::make_pair(i.first.base(), i.second.base());
853 }
854 
855 template <typename RecordT>
856 template <typename T>
858 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) const {
860  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
861  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
863  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
864  return std::make_pair(i.first.base(), i.second.base());
865 }
866 
868 
889 template <typename RecordT, typename Catalog, typename T>
890 std::shared_ptr<RecordT> _Catalog_find(Catalog const& catalog, T const& value, Key<T> const& key) {
891  typename Catalog::const_iterator iter = catalog.find(value, key);
892  if (iter == catalog.end()) {
893  return std::shared_ptr<RecordT>();
894  }
895  return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
896 }
897 
898 template <typename Catalog, typename T>
899 int _Catalog_lower_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
900  return catalog.lower_bound(value, key) - catalog.begin();
901 }
902 
903 template <typename Catalog, typename T>
904 int _Catalog_upper_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
905  return catalog.upper_bound(value, key) - catalog.begin();
906 }
907 
908 template <typename Catalog, typename T>
909 std::pair<int, int> _Catalog_equal_range(Catalog const& catalog, T const& value, Key<T> const& key) {
911  catalog.equal_range(value, key);
912  return std::pair<int, int>(p.first - catalog.begin(), p.second - catalog.begin());
913 }
914 
916 } // namespace table
917 } // namespace afw
918 } // namespace lsst
919 
920 #endif // !AFW_TABLE_Catalog_h_INCLUDED
int const step
int end
#define LSST_EXCEPT(type,...)
afw::table::Key< afw::table::Array< MaskPixelT > > mask
#define LOGL_DEBUG(logger, message...)
SchemaMapper * mapper
Definition: SchemaMapper.cc:71
table::Key< int > b
table::Key< int > a
T at(T... args)
T back(T... args)
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:575
size_type capacity() const
Return the capacity of the catalog.
Definition: Catalog.h:421
std::shared_ptr< RecordT > pointer
Definition: Catalog.h:108
CatalogT(CatalogT const &other)
Shallow copy constructor.
Definition: Catalog.h:149
const_iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key) const
Definition: Catalog.h:812
ColumnView getColumnView() const
Return a ColumnView of this catalog's records.
Definition: Catalog.h:378
void pop_back()
Remove the last record in the catalog.
Definition: Catalog.h:493
void push_back(std::shared_ptr< RecordT > const &p)
Add the given record to the end of the catalog without copying.
Definition: Catalog.h:483
reference at(size_type i) const
Return the record at index i (throws std::out_of_range).
Definition: Catalog.h:451
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:486
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:344
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
Definition: Catalog.h:564
void set(size_type i, std::shared_ptr< RecordT > const &p)
Set the record at index i to a pointer.
Definition: Catalog.h:463
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
Definition: Catalog.h:550
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:672
const_iterator end() const
Definition: Catalog.h:400
const_iterator cend() const
Definition: Catalog.h:402
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:409
bool empty() const
Return true if the catalog has no records.
Definition: Catalog.h:406
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:358
void assign(InputIterator first, InputIterator last, bool deep=false)
Replace the contents of the table with an iterator range.
Definition: Catalog.h:471
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:112
bool isContiguous() const
Return true if all records are contiguous.
Definition: Catalog.h:389
Internal::size_type size_type
Definition: Catalog.h:109
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:759
Record::ColumnView ColumnView
Definition: Catalog.h:104
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Definition: Catalog.h:823
CatalogT(Schema const &schema)
Construct a catalog from a schema, creating a table with Table::make(schema).
Definition: Catalog.h:130
reference back() const
Return the last record.
Definition: Catalog.h:457
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition: Catalog.h:556
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:202
Record::Table Table
Definition: Catalog.h:103
CatalogT & operator=(CatalogT &&other)
Definition: Catalog.h:174
CatalogT(CatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Catalog.h:162
iterator begin()
Iterator access.
Definition: Catalog.h:397
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Definition: Catalog.h:561
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:181
CatalogT(CatalogT &&other)
Definition: Catalog.h:151
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition: Catalog.h:429
reference operator[](size_type i) const
Return the record at index i.
Definition: Catalog.h:448
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition: Catalog.h:801
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:111
CatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition: Catalog.h:126
reference front() const
Return the first record.
Definition: Catalog.h:454
const_iterator begin() const
Definition: Catalog.h:399
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:752
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:436
size_type max_size() const
Return the maximum number of elements allowed in a catalog.
Definition: Catalog.h:412
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition: Catalog.h:496
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:319
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Catalog.h:330
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:514
CatalogT & operator=(CatalogT const &other)
Shallow assigment.
Definition: Catalog.h:166
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:369
const_iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key) const
Definition: Catalog.h:834
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:307
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:460
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:143
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition: Catalog.h:745
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:535
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:569
Internal::difference_type difference_type
Definition: Catalog.h:110
Internal const & getInternal() const
Definition: Catalog.h:673
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:477
const_iterator cbegin() const
Definition: Catalog.h:401
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
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)
def iter(self)
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:904
std::shared_ptr< RecordT > _Catalog_find(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:890
std::pair< int, int > _Catalog_equal_range(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:909
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:899
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:702
bool operator()(RecordT const &a, RecordT const &b) const
Definition: Catalog.h:695
result_type operator()(RecordT const &r) const
Definition: Catalog.h:713
T swap(T... args)
table::Schema schema
Definition: python.h:134
T upper_bound(T... args)