LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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  }
432 
434  reference operator[](size_type i) const { return *_internal[i]; }
435 
437  reference at(size_type i) const { return *_internal.at(i); }
438 
440  reference front() const { return *_internal.front(); }
441 
443  reference back() const { return *_internal.back(); }
444 
446  std::shared_ptr<RecordT> const get(size_type i) const { return _internal[i]; }
447 
449  void set(size_type i, std::shared_ptr<RecordT> const& p) { _internal[i] = p; }
450 
456  template <typename InputIterator>
457  void assign(InputIterator first, InputIterator last, bool deep = false) {
458  clear();
459  insert(end(), first, last, deep);
460  }
461 
463  void push_back(Record const& r) {
464  std::shared_ptr<RecordT> p = _table->copyRecord(r);
465  _internal.push_back(p);
466  }
467 
469  void push_back(std::shared_ptr<RecordT> const& p) { _internal.push_back(p); }
470 
473  std::shared_ptr<RecordT> r = _table->makeRecord();
474  _internal.push_back(r);
475  return r;
476  }
477 
479  void pop_back() { _internal.pop_back(); }
480 
482  CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
483 
499  template <typename InputIterator>
500  void insert(iterator pos, InputIterator first, InputIterator last, bool deep = false) {
501  _maybeReserve(pos, first, last, deep,
503  if (deep) {
504  while (first != last) {
505  pos = insert(pos, *first);
506  ++pos;
507  ++first;
508  }
509  } else {
510  while (first != last) {
511  pos = insert(pos, first);
512  assert(pos != end());
513  ++pos;
514  ++first;
515  }
516  }
517  }
518 
520  template <typename InputIterator>
521  void insert(SchemaMapper const& mapper, iterator pos, InputIterator first, InputIterator last) {
522  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
524  "SchemaMapper's output schema does not match catalog's schema");
525  }
526  _maybeReserve(pos, first, last, true,
528  while (first != last) {
529  pos = insert(pos, _table->copyRecord(*first, mapper));
530  ++pos;
531  ++first;
532  }
533  }
534 
536  iterator insert(iterator pos, Record const& r) {
537  std::shared_ptr<RecordT> p = _table->copyRecord(r);
538  return iterator(_internal.insert(pos.base(), p));
539  }
540 
542  iterator insert(iterator pos, std::shared_ptr<RecordT> const& p) {
543  return iterator(_internal.insert(pos.base(), p));
544  }
545 
547  iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
548 
550  iterator erase(iterator first, iterator last) {
551  return iterator(_internal.erase(first.base(), last.base()));
552  }
553 
555  void swap(CatalogT& other) noexcept {
556  _table.swap(other._table);
557  _internal.swap(other._internal);
558  }
559 
561  void clear() { _internal.clear(); }
562 
564  template <typename T>
565  bool isSorted(Key<T> const& key) const;
566 
572  template <typename Compare>
573  bool isSorted(Compare cmp) const;
574 
576  template <typename T>
577  void sort(Key<T> const& key);
578 
584  template <typename Compare>
585  void sort(Compare cmp);
586 
588 
602  template <typename T>
603  iterator find(typename Field<T>::Value const& value, Key<T> const& key);
604 
605  template <typename T>
606  const_iterator find(typename Field<T>::Value const& value, Key<T> const& key) const;
608 
610 
623  template <typename T>
624  iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key);
625 
626  template <typename T>
627  const_iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
628 
629  template <typename T>
630  iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key);
631 
632  template <typename T>
633  const_iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
634 
635  template <typename T>
636  std::pair<iterator, iterator> equal_range(typename Field<T>::Value const& value, Key<T> const& key);
637 
638  template <typename T>
639  std::pair<const_iterator, const_iterator> equal_range(typename Field<T>::Value const& value,
640  Key<T> const& key) const;
642 
644 
656  Internal& getInternal() { return _internal; }
657  Internal const& getInternal() const { return _internal; }
659 
660 private:
661  template <typename InputIterator>
662  void _maybeReserve(iterator& pos, InputIterator first, InputIterator last, bool deep,
664  if (deep) _table->preallocate(last - first);
665  }
666 
667  template <typename InputIterator>
668  void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep,
670 
671  std::shared_ptr<Table> _table;
672  Internal _internal;
673 };
674 
675 namespace detail {
676 
677 template <typename RecordT, typename T>
679  bool operator()(RecordT const& a, RecordT const& b) const { return a.get(key) < b.get(key); }
680 
682 };
683 
684 template <typename RecordT, typename Adaptee>
687  return adaptee(*a, *b);
688  }
689 
690  Adaptee adaptee;
691 };
692 
693 template <typename RecordT, typename T>
695  typedef typename Field<T>::Value result_type;
696 
697  result_type operator()(RecordT const& r) const { return r.get(key); }
698 
700 };
701 
702 } // namespace detail
703 
704 template <typename RecordT>
705 template <typename Compare>
706 bool CatalogT<RecordT>::isSorted(Compare cmp) const {
709  if (empty()) return true;
710  const_iterator last = this->begin();
711  const_iterator i = last;
712  ++i;
713  for (; i != this->end(); ++i) {
714  if (f(i, last)) return false;
715  last = i;
716  }
717  return true;
718 }
719 
720 template <typename RecordT>
721 template <typename Compare>
722 void CatalogT<RecordT>::sort(Compare cmp) {
724  std::stable_sort(_internal.begin(), _internal.end(), f);
725 }
726 
727 template <typename RecordT>
728 template <typename T>
731  return isSorted(f);
732 }
733 
734 template <typename RecordT>
735 template <typename T>
738  return sort(f);
739 }
740 
741 template <typename RecordT>
742 template <typename T>
744  Key<T> const& key) {
746  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
747  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
748  // Use binary search for log n search; requires sorted table.
749  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
750  if (i.base() == end() || *i != value) return end();
751  return i.base();
752 }
753 
754 template <typename RecordT>
755 template <typename T>
757  Key<T> const& key) const {
759  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
760  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_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) {
772  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
773  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, 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  typename Field<T>::Value const& value, 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  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
786  return i.base();
787 }
788 
789 template <typename RecordT>
790 template <typename T>
792  Key<T> const& key) {
794  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
795  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, 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>
803  typename Field<T>::Value const& value, Key<T> const& key) const {
805  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
806  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
807  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
808  return i.base();
809 }
810 
811 template <typename RecordT>
812 template <typename T>
816  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
817  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
819  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
820  return std::make_pair(i.first.base(), i.second.base());
821 }
822 
823 template <typename RecordT>
824 template <typename T>
826 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) const {
828  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
829  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
831  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
832  return std::make_pair(i.first.base(), i.second.base());
833 }
834 
836 
857 template <typename RecordT, typename Catalog, typename T>
858 std::shared_ptr<RecordT> _Catalog_find(Catalog const& catalog, T const& value, Key<T> const& key) {
859  typename Catalog::const_iterator iter = catalog.find(value, key);
860  if (iter == catalog.end()) {
861  return std::shared_ptr<RecordT>();
862  }
863  return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
864 }
865 
866 template <typename Catalog, typename T>
867 int _Catalog_lower_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
868  return catalog.lower_bound(value, key) - catalog.begin();
869 }
870 
871 template <typename Catalog, typename T>
872 int _Catalog_upper_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
873  return catalog.upper_bound(value, key) - catalog.begin();
874 }
875 
876 template <typename Catalog, typename T>
877 std::pair<int, int> _Catalog_equal_range(Catalog const& catalog, T const& value, Key<T> const& key) {
879  catalog.equal_range(value, key);
880  return std::pair<int, int>(p.first - catalog.begin(), p.second - catalog.begin());
881 }
882 
884 } // namespace table
885 } // namespace afw
886 } // namespace lsst
887 
888 #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:469
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:858
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition: Catalog.h:542
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
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:729
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:284
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:736
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:656
void swap(CatalogT &other) noexcept
Shallow swap of two catalogs.
Definition: Catalog.h:555
reference back() const
Return the last record.
Definition: Catalog.h:443
void pop_back()
Remove the last record in the catalog.
Definition: Catalog.h:479
bool operator()(std::shared_ptr< RecordT > const &a, std::shared_ptr< RecordT > const &b) const
Definition: Catalog.h:686
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:867
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition: Catalog.h:769
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:500
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:296
result_type operator()(RecordT const &r) const
Definition: Catalog.h:697
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:877
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:657
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:872
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:463
A base class for image defects.
void clear()
Remove all records from the catalog.
Definition: Catalog.h:561
reference front() const
Return the first record.
Definition: Catalog.h:440
Internal::size_type size_type
Definition: Catalog.h:108
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:120
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:547
Iterator class for CatalogT.
Definition: Catalog.h:38
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:550
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:536
#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:457
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:743
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:434
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:679
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:521
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:437
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:791
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition: Catalog.h:482
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:44
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
Basic LSST definitions.
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:472
friend class boost::iterator_core_access
Definition: Catalog.h:61