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