lsst.afw  13.0-39-g3deb52d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/table/fwd.h"
17 
18 namespace lsst {
19 namespace afw {
20 namespace table {
21 
36 template <typename BaseT>
37 class CatalogIterator : public boost::iterator_adaptor<CatalogIterator<BaseT>, BaseT,
38  typename BaseT::value_type::element_type> {
39 public:
41 
42  template <typename OtherBaseT>
44  : CatalogIterator::iterator_adaptor_(other.base()) {}
45 
46  explicit CatalogIterator(BaseT const& base) : CatalogIterator::iterator_adaptor_(base) {}
47 
48  template <typename RecordT>
49  operator std::shared_ptr<RecordT>() const {
50  return *this->base();
51  }
52 
53  template <typename RecordT>
54  CatalogIterator& operator=(std::shared_ptr<RecordT> const& other) const {
55  *this->base() = other;
56  return *this;
57  }
58 
59 private:
61  typename BaseT::value_type::element_type& dereference() const { return **this->base(); }
62 };
63 
95 template <typename RecordT>
96 class CatalogT {
97  typedef std::vector<std::shared_ptr<RecordT>> Internal;
98 
99 public:
100  typedef RecordT Record;
101  typedef typename Record::Table Table;
102  typedef typename Record::ColumnView ColumnView;
103 
104  typedef RecordT value_type;
105  typedef RecordT& reference;
106  typedef std::shared_ptr<RecordT> pointer;
107  typedef typename Internal::size_type size_type;
108  typedef typename Internal::difference_type difference_type;
111 
113  std::shared_ptr<Table> getTable() const { return _table; }
114 
116  Schema getSchema() const { return _table->getSchema(); }
117 
124  explicit CatalogT(std::shared_ptr<Table> const& table = std::shared_ptr<Table>())
125  : _table(table), _internal() {}
126 
128  explicit CatalogT(Schema const& schema) : _table(Table::make(schema)), _internal() {}
129 
140  template <typename InputIterator>
141  CatalogT(std::shared_ptr<Table> const& table, InputIterator first, InputIterator last, bool deep = false)
142  : _table(table), _internal() {
143  insert(end(), first, last, deep);
144  }
145 
147  CatalogT(CatalogT const& other) : _table(other._table), _internal(other._internal) {}
148 
155  template <typename OtherRecordT>
157  : _table(other.getTable()), _internal(other.begin().base(), other.end().base()) {}
158 
160  CatalogT& operator=(CatalogT const& other) {
161  if (&other != this) {
162  _table = other._table;
163  _internal = other._internal;
164  }
165  return *this;
166  }
167 
173  CatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
174  if (size_type(mask.size()) != size()) {
175  throw LSST_EXCEPT(
176  pex::exceptions::LengthError,
177  (boost::format("Mask array with %d elements applied to catalog with %d elements") %
178  mask.size() %
179  size()).str());
180  }
182  ndarray::Array<bool const, 1>::Iterator maskIter = mask.begin();
183  const_iterator catIter = begin();
184  for (; maskIter != mask.end(); ++maskIter, ++catIter) {
185  if (*maskIter) result.push_back(catIter);
186  }
187  return result;
188  }
189 
194  CatalogT<RecordT> subset(std::ptrdiff_t startd, std::ptrdiff_t stopd, std::ptrdiff_t step) const {
195  /* Python's slicing syntax is weird and wonderful.
196 
197  Both the "start" and "stop" indices can be negative, which means the
198  abs() of the index less than the size; [-1] means the last item.
199  Moreover, it's possible to have a negative index less than -len(); it
200  will get clipped. That is in fact one way to slice *backward* through
201  the array *and* include element 0;
202 
203  >>> range(10)[5:-20:-1]
204  [5, 4, 3, 2, 1, 0]
205 
206  The clipping tests in this function look more complicated than they
207  need to be, but that is partly because there are some weird edge cases.
208 
209  Also, ptrdiff_t vs size_t introduces some annoying complexity. Note
210  that the args are "startd"/"stopd" (not "start"/"stop").
211 
212  There is a fairly complete set of tests in tests/ticket2026.py; if you
213  try to simplify this function, be sure they continue to pass.
214  */
215  size_type S = size();
216  size_type start, stop = 0;
217  // Python doesn't allow step == 0
218  if (step == 0) {
219  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Step cannot be zero");
220  }
221  // Basic negative indexing rule: first add size
222  if (startd < 0) {
223  startd += S;
224  }
225  if (stopd < 0) {
226  stopd += S;
227  }
228  // Start gets clipped to zero; stop does not (yet).
229  if (startd < 0) {
230  startd = 0;
231  }
232  // Now start is non-negative, so can cast to size_t.
233  start = (size_type)startd;
234  if (start > S) {
235  start = S;
236  }
237  if (step > 0) {
238  // When stepping forward, stop gets clipped at zero,
239  // so is non-negative and can get cast to size_t.
240  if (stopd < 0) {
241  stopd = 0;
242  }
243  stop = (size_type)stopd;
244  if (stop > S) {
245  stop = S;
246  }
247  } else if (step < 0) {
248  // When stepping backward, stop gets clipped at -1 so that slices
249  // including 0 are possible.
250  if (stopd < 0) {
251  stopd = -1;
252  }
253  }
254 
255  if (((step > 0) && (start >= stop)) || ((step < 0) && ((std::ptrdiff_t)start <= stopd))) {
256  // Empty range
257  return CatalogT<RecordT>(getTable(), begin(), begin());
258  }
259 
260  if (step == 1) {
261  // Use the iterator-based constructor for this simple case
262  assert(start >= 0);
263  assert(stop > 0);
264  assert(start < S);
265  assert(stop <= S);
266  return CatalogT<RecordT>(getTable(), begin() + start, begin() + stop);
267  }
268 
269  // Build a new CatalogT and copy records into it.
271  size_type N = 0;
272  if (step >= 0) {
273  N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
274  } else {
275  N = (size_t)((stopd - (std::ptrdiff_t)start) / step +
276  (((stopd - (std::ptrdiff_t)start) % step) ? 1 : 0));
277  }
278  cat.reserve(N);
279  if (step >= 0) {
280  for (size_type i = start; i < stop; i += step) {
281  cat.push_back(get(i));
282  }
283  } else {
284  for (std::ptrdiff_t i = (std::ptrdiff_t)start; i > stopd; i += step) {
285  cat.push_back(get(i));
286  }
287  }
288  return cat;
289  }
290 
299  void writeFits(std::string const& filename, std::string const& mode = "w", int flags = 0) const {
300  io::FitsWriter::apply(filename, mode, *this, flags);
301  }
302 
311  void writeFits(fits::MemFileManager& manager, std::string const& mode = "w", int flags = 0) const {
312  io::FitsWriter::apply(manager, mode, *this, flags);
313  }
314 
322  void writeFits(fits::Fits& fitsfile, int flags = 0) const {
323  io::FitsWriter::apply(fitsfile, *this, flags);
324  }
325 
335  static CatalogT readFits(std::string const& filename, int hdu = INT_MIN, int flags = 0) {
336  return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
337  }
338 
348  static CatalogT readFits(fits::MemFileManager& manager, int hdu = INT_MIN, int flags = 0) {
349  return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
350  }
351 
359  static CatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
360  return io::FitsReader::apply<CatalogT>(fitsfile, flags);
361  }
362 
369  if (std::is_const<RecordT>::value) {
370  throw LSST_EXCEPT(
371  pex::exceptions::LogicError,
372  "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
373  "non-const views).");
374  }
375  return ColumnView::make(_table, begin(), end());
376  }
377 
379  bool isContiguous() const { return ColumnView::isRangeContiguous(_table, begin(), end()); }
380 
382 
387  iterator begin() { return iterator(_internal.begin()); }
388  iterator end() { return iterator(_internal.end()); }
389  const_iterator begin() const { return const_iterator(_internal.begin()); }
390  const_iterator end() const { return const_iterator(_internal.end()); }
392 
394  bool empty() const { return _internal.empty(); }
395 
397  size_type size() const { return _internal.size(); }
398 
400  size_type max_size() const { return _internal.max_size(); }
401 
409  size_type capacity() const { return _internal.size() + _table->getBufferSize(); }
410 
417  void reserve(size_type n) {
418  if (n <= _internal.size()) return;
419  _table->preallocate(n - _internal.size());
420  }
421 
423  reference operator[](size_type i) const { return *_internal[i]; }
424 
426  reference at(size_type i) const { return *_internal.at(i); }
427 
429  reference front() const { return *_internal.front(); }
430 
432  reference back() const { return *_internal.back(); }
433 
435  std::shared_ptr<RecordT> const get(size_type i) const { return _internal[i]; }
436 
438  void set(size_type i, std::shared_ptr<RecordT> const& p) { _internal[i] = p; }
439 
445  template <typename InputIterator>
446  void assign(InputIterator first, InputIterator last, bool deep = false) {
447  clear();
448  insert(end(), first, last, deep);
449  }
450 
452  void push_back(Record const& r) {
453  std::shared_ptr<RecordT> p = _table->copyRecord(r);
454  _internal.push_back(p);
455  }
456 
458  void push_back(std::shared_ptr<RecordT> const& p) { _internal.push_back(p); }
459 
461  std::shared_ptr<RecordT> addNew() {
462  std::shared_ptr<RecordT> r = _table->makeRecord();
463  _internal.push_back(r);
464  return r;
465  }
466 
468  void pop_back() { _internal.pop_back(); }
469 
471  CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
472 
488  template <typename InputIterator>
489  void insert(iterator pos, InputIterator first, InputIterator last, bool deep = false) {
490  _maybeReserve(pos, first, last, deep,
491  (typename std::iterator_traits<InputIterator>::iterator_category*)0);
492  if (deep) {
493  while (first != last) {
494  pos = insert(pos, *first);
495  ++pos;
496  ++first;
497  }
498  } else {
499  while (first != last) {
500  pos = insert(pos, first);
501  assert(pos != end());
502  ++pos;
503  ++first;
504  }
505  }
506  }
507 
509  template <typename InputIterator>
510  void insert(SchemaMapper const& mapper, iterator pos, InputIterator first, InputIterator last) {
511  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
512  throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
513  "SchemaMapper's output schema does not match catalog's schema");
514  }
515  _maybeReserve(pos, first, last, true,
516  (typename std::iterator_traits<InputIterator>::iterator_category*)0);
517  while (first != last) {
518  pos = insert(pos, _table->copyRecord(*first, mapper));
519  ++pos;
520  ++first;
521  }
522  }
523 
525  iterator insert(iterator pos, Record const& r) {
526  std::shared_ptr<RecordT> p = _table->copyRecord(r);
527  return iterator(_internal.insert(pos.base(), p));
528  }
529 
531  iterator insert(iterator pos, std::shared_ptr<RecordT> const& p) {
532  return iterator(_internal.insert(pos.base(), p));
533  }
534 
536  iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
537 
540  return iterator(_internal.erase(first.base(), last.base()));
541  }
542 
544  void swap(CatalogT& other) {
545  _table.swap(other._table);
546  _internal.swap(other._internal);
547  }
548 
550  void clear() { _internal.clear(); }
551 
553  template <typename T>
554  bool isSorted(Key<T> const& key) const;
555 
561  template <typename Compare>
562  bool isSorted(Compare cmp) const;
563 
565  template <typename T>
566  void sort(Key<T> const& key);
567 
573  template <typename Compare>
574  void sort(Compare cmp);
575 
577 
591  template <typename T>
592  iterator find(typename Field<T>::Value const& value, Key<T> const& key);
593 
594  template <typename T>
595  const_iterator find(typename Field<T>::Value const& value, Key<T> const& key) const;
597 
599 
612  template <typename T>
613  iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key);
614 
615  template <typename T>
616  const_iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
617 
618  template <typename T>
619  iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key);
620 
621  template <typename T>
622  const_iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
623 
624  template <typename T>
625  std::pair<iterator, iterator> equal_range(typename Field<T>::Value const& value, Key<T> const& key);
626 
627  template <typename T>
628  std::pair<const_iterator, const_iterator> equal_range(typename Field<T>::Value const& value,
629  Key<T> const& key) const;
631 
633 
645  Internal& getInternal() { return _internal; }
646  Internal const& getInternal() const { return _internal; }
648 
649 private:
650  template <typename InputIterator>
651  void _maybeReserve(iterator& pos, InputIterator first, InputIterator last, bool deep,
652  std::random_access_iterator_tag*) {
653  if (deep) _table->preallocate(last - first);
654  }
655 
656  template <typename InputIterator>
657  void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep,
658  std::input_iterator_tag*) {}
659 
660  std::shared_ptr<Table> _table;
661  Internal _internal;
662 };
663 
664 namespace detail {
665 
666 template <typename RecordT, typename T>
668  bool operator()(RecordT const& a, RecordT const& b) const { return a.get(key) < b.get(key); }
669 
671 };
672 
673 template <typename RecordT, typename Adaptee>
675  bool operator()(std::shared_ptr<RecordT> const& a, std::shared_ptr<RecordT> const& b) const {
676  return adaptee(*a, *b);
677  }
678 
679  Adaptee adaptee;
680 };
681 
682 template <typename RecordT, typename T>
684  typedef typename Field<T>::Value result_type;
685 
686  result_type operator()(RecordT const& r) const { return r.get(key); }
687 
689 };
690 
691 } // namespace detail
692 
693 template <typename RecordT>
694 template <typename Compare>
695 bool CatalogT<RecordT>::isSorted(Compare cmp) const {
698  if (empty()) return true;
699  const_iterator last = this->begin();
700  const_iterator i = last;
701  ++i;
702  for (; i != this->end(); ++i) {
703  if (f(i, last)) return false;
704  last = i;
705  }
706  return true;
707 }
708 
709 template <typename RecordT>
710 template <typename Compare>
711 void CatalogT<RecordT>::sort(Compare cmp) {
713  std::stable_sort(_internal.begin(), _internal.end(), f);
714 }
715 
716 template <typename RecordT>
717 template <typename T>
718 bool CatalogT<RecordT>::isSorted(Key<T> const& key) const {
720  return isSorted(f);
721 }
722 
723 template <typename RecordT>
724 template <typename T>
725 void CatalogT<RecordT>::sort(Key<T> const& key) {
727  return sort(f);
728 }
729 
730 template <typename RecordT>
731 template <typename T>
733  Key<T> const& key) {
735  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
736  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
737  // Use binary search for log n search; requires sorted table.
738  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
739  if (i.base() == end() || *i != value) return end();
740  return i.base();
741 }
742 
743 template <typename RecordT>
744 template <typename T>
746  Key<T> const& key) const {
748  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
749  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
750  // Use binary search for log n search; requires sorted table.
751  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
752  if (i.base() == end() || *i != value) return end();
753  return i.base();
754 }
755 
756 template <typename RecordT>
757 template <typename T>
759  Key<T> const& key) {
761  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
762  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
763  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
764  return i.base();
765 }
766 
767 template <typename RecordT>
768 template <typename T>
770  typename Field<T>::Value const& value, 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  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
775  return i.base();
776 }
777 
778 template <typename RecordT>
779 template <typename T>
781  Key<T> const& key) {
783  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
784  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
785  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
786  return i.base();
787 }
788 
789 template <typename RecordT>
790 template <typename T>
792  typename Field<T>::Value const& value, Key<T> const& key) const {
794  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
795  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
796  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
797  return i.base();
798 }
799 
800 template <typename RecordT>
801 template <typename T>
802 std::pair<typename CatalogT<RecordT>::iterator, typename CatalogT<RecordT>::iterator>
803 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) {
805  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
806  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
807  std::pair<SearchIter, SearchIter> i =
808  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
809  return std::make_pair(i.first.base(), i.second.base());
810 }
811 
812 template <typename RecordT>
813 template <typename T>
814 std::pair<typename CatalogT<RecordT>::const_iterator, typename CatalogT<RecordT>::const_iterator>
815 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) const {
817  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
818  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
819  std::pair<SearchIter, SearchIter> i =
820  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
821  return std::make_pair(i.first.base(), i.second.base());
822 }
823 
825 
846 template <typename RecordT, typename Catalog, typename T>
847 std::shared_ptr<RecordT> _Catalog_find(Catalog const& catalog, T const& value, Key<T> const& key) {
848  typename Catalog::const_iterator iter = catalog.find(value, key);
849  if (iter == catalog.end()) {
850  return std::shared_ptr<RecordT>();
851  }
852  return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
853 }
854 
855 template <typename Catalog, typename T>
856 int _Catalog_lower_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
857  return catalog.lower_bound(value, key) - catalog.begin();
858 }
859 
860 template <typename Catalog, typename T>
861 int _Catalog_upper_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
862  return catalog.upper_bound(value, key) - catalog.begin();
863 }
864 
865 template <typename Catalog, typename T>
866 std::pair<int, int> _Catalog_equal_range(Catalog const& catalog, T const& value, Key<T> const& key) {
867  std::pair<typename Catalog::const_iterator, typename Catalog::const_iterator> p =
868  catalog.equal_range(value, key);
869  return std::pair<int, int>(p.first - catalog.begin(), p.second - catalog.begin());
870 }
871 
873 }
874 }
875 } // namespace lsst::afw::table
876 
877 #endif // !AFW_TABLE_Catalog_h_INCLUDED
CatalogT(CatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Catalog.h:156
void push_back(std::shared_ptr< RecordT > const &p)
Add the given record to the end of the catalog without copying.
Definition: Catalog.h:458
const_iterator end() const
Iterator access.
Definition: Catalog.h:390
const_iterator begin() const
Iterator access.
Definition: Catalog.h:389
Defines the fields and offsets for a table.
Definition: Schema.h:46
std::shared_ptr< RecordT > _Catalog_find(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:847
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
bool operator()(RecordT const &a, RecordT const &b) const
Definition: Catalog.h:668
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition: Catalog.h:531
static CatalogT readFits(std::string const &filename, int hdu=INT_MIN, int flags=0)
Read a FITS binary table from a regular file.
Definition: Catalog.h:335
Internal::difference_type difference_type
Definition: Catalog.h:108
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
Definition: SchemaMapper.h:27
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition: Catalog.h:718
static CatalogT readFits(fits::MemFileManager &manager, int hdu=INT_MIN, int flags=0)
Read a FITS binary table from a RAM file.
Definition: Catalog.h:348
CatalogT & operator=(CatalogT const &other)
Shallow assigment.
Definition: Catalog.h:160
CatalogIterator(CatalogIterator< OtherBaseT > const &other)
Definition: Catalog.h:43
A custom container class for records, based on std::vector.
Definition: Catalog.h:96
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:725
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:645
void pop_back()
Remove the last record in the catalog.
Definition: Catalog.h:468
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:856
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:489
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:199
reference at(size_type i) const
Return the record at index i (throws std::out_of_range).
Definition: Catalog.h:426
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:194
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:141
std::pair< int, int > _Catalog_equal_range(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:866
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:397
CatalogT(CatalogT const &other)
Shallow copy constructor.
Definition: Catalog.h:147
CatalogIterator & operator=(std::shared_ptr< RecordT > const &other) const
Definition: Catalog.h:54
int _Catalog_upper_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:861
bool empty() const
Return true if the catalog has no records.
Definition: Catalog.h:394
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:452
Internal const & getInternal() const
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:646
void clear()
Remove all records from the catalog.
Definition: Catalog.h:550
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:113
Internal::size_type size_type
Definition: Catalog.h:107
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:100
iterator end()
Iterator access.
Definition: Catalog.h:388
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:173
CatalogT(Schema const &schema)
Construct a catalog from a schema, creating a table with Table::make(schema).
Definition: Catalog.h:128
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Definition: Catalog.h:536
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition: Catalog.h:471
Iterator class for CatalogT.
Definition: Catalog.h:37
bool operator()(std::shared_ptr< RecordT > const &a, std::shared_ptr< RecordT > const &b) const
Definition: Catalog.h:675
Record::ColumnView ColumnView
Definition: Catalog.h:102
size_type max_size() const
Return the maximum number of elements allowed in a catalog.
Definition: Catalog.h:400
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
Definition: Catalog.h:539
CatalogIterator(BaseT const &base)
Definition: Catalog.h:46
bool isContiguous() const
Return true if all records are contiguous.
Definition: Catalog.h:379
CatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition: Catalog.h:124
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:110
void swap(CatalogT &other)
Shallow swap of two catalogs.
Definition: Catalog.h:544
result_type operator()(RecordT const &r) const
Definition: Catalog.h:686
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition: Catalog.h:417
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
Definition: Catalog.h:525
afw::table::Key< afw::table::Array< MaskPixelT > > mask
Record::Table Table
Definition: Catalog.h:101
void assign(InputIterator first, InputIterator last, bool deep=false)
Replace the contents of the table with an iterator range.
Definition: Catalog.h:446
A class used as a handle to a particular field in a table.
Definition: fwd.h:45
T Value
the type returned by BaseRecord::get
Definition: FieldBase.h:47
size_type capacity() const
Return the capacity of the catalog.
Definition: Catalog.h:409
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:37
ColumnView getColumnView() const
Return a ColumnView of this catalog&#39;s records.
Definition: Catalog.h:368
reference back() const
Return the last record.
Definition: Catalog.h:432
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:510
reference operator[](size_type i) const
Return the record at index i.
Definition: Catalog.h:423
reference front() const
Return the first record.
Definition: Catalog.h:429
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
iterator find(typename Field< T >::Value const &value, Key< T > const &key)
Return an iterator to the record with the given value.
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Catalog.h:322
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:299
py::object result
Definition: schema.cc:290
iterator begin()
Iterator access.
Definition: Catalog.h:387
std::pair< iterator, iterator > equal_range(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
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:359
Schema getSchema() const
Return the schema associated with the catalog&#39;s table.
Definition: Catalog.h:116
afw::table::Schema schema
Definition: GaussianPsf.cc:43
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:109
void set(size_type i, std::shared_ptr< RecordT > const &p)
Set the record at index i to a pointer.
Definition: Catalog.h:438
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:311
std::shared_ptr< RecordT > pointer
Definition: Catalog.h:106
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:461
friend class boost::iterator_core_access
Definition: Catalog.h:60