lsst.afw  14.0-25-g0e8fc950e+3
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>
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 {
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;
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 
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(
177  (boost::format("Mask array with %d elements applied to catalog with %d elements") %
178  mask.size() %
179  size()).str());
180  }
181  CatalogT<RecordT> result(getTable());
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 
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.
270  CatalogT<RecordT> cat(getTable());
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 
368  ColumnView getColumnView() const {
370  throw LSST_EXCEPT(
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()); }
391  const_iterator cbegin() const { return begin(); }
392  const_iterator cend() const { return end(); }
394 
396  bool empty() const { return _internal.empty(); }
397 
399  size_type size() const { return _internal.size(); }
400 
402  size_type max_size() const { return _internal.max_size(); }
403 
411  size_type capacity() const { return _internal.size() + _table->getBufferSize(); }
412 
419  void reserve(size_type n) {
420  if (n <= _internal.size()) return;
421  _table->preallocate(n - _internal.size());
422  }
423 
425  reference operator[](size_type i) const { return *_internal[i]; }
426 
428  reference at(size_type i) const { return *_internal.at(i); }
429 
431  reference front() const { return *_internal.front(); }
432 
434  reference back() const { return *_internal.back(); }
435 
437  std::shared_ptr<RecordT> const get(size_type i) const { return _internal[i]; }
438 
440  void set(size_type i, std::shared_ptr<RecordT> const& p) { _internal[i] = p; }
441 
447  template <typename InputIterator>
448  void assign(InputIterator first, InputIterator last, bool deep = false) {
449  clear();
450  insert(end(), first, last, deep);
451  }
452 
454  void push_back(Record const& r) {
455  std::shared_ptr<RecordT> p = _table->copyRecord(r);
456  _internal.push_back(p);
457  }
458 
460  void push_back(std::shared_ptr<RecordT> const& p) { _internal.push_back(p); }
461 
464  std::shared_ptr<RecordT> r = _table->makeRecord();
465  _internal.push_back(r);
466  return r;
467  }
468 
470  void pop_back() { _internal.pop_back(); }
471 
473  CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
474 
490  template <typename InputIterator>
491  void insert(iterator pos, InputIterator first, InputIterator last, bool deep = false) {
492  _maybeReserve(pos, first, last, deep,
494  if (deep) {
495  while (first != last) {
496  pos = insert(pos, *first);
497  ++pos;
498  ++first;
499  }
500  } else {
501  while (first != last) {
502  pos = insert(pos, first);
503  assert(pos != end());
504  ++pos;
505  ++first;
506  }
507  }
508  }
509 
511  template <typename InputIterator>
512  void insert(SchemaMapper const& mapper, iterator pos, InputIterator first, InputIterator last) {
513  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
515  "SchemaMapper's output schema does not match catalog's schema");
516  }
517  _maybeReserve(pos, first, last, true,
519  while (first != last) {
520  pos = insert(pos, _table->copyRecord(*first, mapper));
521  ++pos;
522  ++first;
523  }
524  }
525 
527  iterator insert(iterator pos, Record const& r) {
528  std::shared_ptr<RecordT> p = _table->copyRecord(r);
529  return iterator(_internal.insert(pos.base(), p));
530  }
531 
533  iterator insert(iterator pos, std::shared_ptr<RecordT> const& p) {
534  return iterator(_internal.insert(pos.base(), p));
535  }
536 
538  iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
539 
541  iterator erase(iterator first, iterator last) {
542  return iterator(_internal.erase(first.base(), last.base()));
543  }
544 
546  void swap(CatalogT& other) {
547  _table.swap(other._table);
548  _internal.swap(other._internal);
549  }
550 
552  void clear() { _internal.clear(); }
553 
555  template <typename T>
556  bool isSorted(Key<T> const& key) const;
557 
563  template <typename Compare>
564  bool isSorted(Compare cmp) const;
565 
567  template <typename T>
568  void sort(Key<T> const& key);
569 
575  template <typename Compare>
576  void sort(Compare cmp);
577 
579 
593  template <typename T>
594  iterator find(typename Field<T>::Value const& value, Key<T> const& key);
595 
596  template <typename T>
597  const_iterator find(typename Field<T>::Value const& value, Key<T> const& key) const;
599 
601 
614  template <typename T>
615  iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key);
616 
617  template <typename T>
618  const_iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
619 
620  template <typename T>
621  iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key);
622 
623  template <typename T>
624  const_iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
625 
626  template <typename T>
627  std::pair<iterator, iterator> equal_range(typename Field<T>::Value const& value, Key<T> const& key);
628 
629  template <typename T>
630  std::pair<const_iterator, const_iterator> equal_range(typename Field<T>::Value const& value,
631  Key<T> const& key) const;
633 
635 
647  Internal& getInternal() { return _internal; }
648  Internal const& getInternal() const { return _internal; }
650 
651 private:
652  template <typename InputIterator>
653  void _maybeReserve(iterator& pos, InputIterator first, InputIterator last, bool deep,
655  if (deep) _table->preallocate(last - first);
656  }
657 
658  template <typename InputIterator>
659  void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep,
661 
662  std::shared_ptr<Table> _table;
663  Internal _internal;
664 };
665 
666 namespace detail {
667 
668 template <typename RecordT, typename T>
670  bool operator()(RecordT const& a, RecordT const& b) const { return a.get(key) < b.get(key); }
671 
673 };
674 
675 template <typename RecordT, typename Adaptee>
678  return adaptee(*a, *b);
679  }
680 
681  Adaptee adaptee;
682 };
683 
684 template <typename RecordT, typename T>
686  typedef typename Field<T>::Value result_type;
687 
688  result_type operator()(RecordT const& r) const { return r.get(key); }
689 
691 };
692 
693 } // namespace detail
694 
695 template <typename RecordT>
696 template <typename Compare>
697 bool CatalogT<RecordT>::isSorted(Compare cmp) const {
700  if (empty()) return true;
701  const_iterator last = this->begin();
702  const_iterator i = last;
703  ++i;
704  for (; i != this->end(); ++i) {
705  if (f(i, last)) return false;
706  last = i;
707  }
708  return true;
709 }
710 
711 template <typename RecordT>
712 template <typename Compare>
713 void CatalogT<RecordT>::sort(Compare cmp) {
715  std::stable_sort(_internal.begin(), _internal.end(), f);
716 }
717 
718 template <typename RecordT>
719 template <typename T>
720 bool CatalogT<RecordT>::isSorted(Key<T> const& key) const {
722  return isSorted(f);
723 }
724 
725 template <typename RecordT>
726 template <typename T>
727 void CatalogT<RecordT>::sort(Key<T> const& key) {
729  return sort(f);
730 }
731 
732 template <typename RecordT>
733 template <typename T>
735  Key<T> const& key) {
737  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
738  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
739  // Use binary search for log n search; requires sorted table.
740  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
741  if (i.base() == end() || *i != value) return end();
742  return i.base();
743 }
744 
745 template <typename RecordT>
746 template <typename T>
748  Key<T> const& key) const {
750  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
751  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
752  // Use binary search for log n search; requires sorted table.
753  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
754  if (i.base() == end() || *i != value) return end();
755  return i.base();
756 }
757 
758 template <typename RecordT>
759 template <typename T>
761  Key<T> const& key) {
763  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
764  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
765  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
766  return i.base();
767 }
768 
769 template <typename RecordT>
770 template <typename T>
772  typename Field<T>::Value const& value, Key<T> const& key) const {
774  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
775  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
776  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
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::upper_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::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
799  return i.base();
800 }
801 
802 template <typename RecordT>
803 template <typename T>
805 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, 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;
810  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
811  return std::make_pair(i.first.base(), i.second.base());
812 }
813 
814 template <typename RecordT>
815 template <typename T>
817 CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) const {
819  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
820  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
822  std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
823  return std::make_pair(i.first.base(), i.second.base());
824 }
825 
827 
848 template <typename RecordT, typename Catalog, typename T>
849 std::shared_ptr<RecordT> _Catalog_find(Catalog const& catalog, T const& value, Key<T> const& key) {
850  typename Catalog::const_iterator iter = catalog.find(value, key);
851  if (iter == catalog.end()) {
852  return std::shared_ptr<RecordT>();
853  }
854  return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
855 }
856 
857 template <typename Catalog, typename T>
858 int _Catalog_lower_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
859  return catalog.lower_bound(value, key) - catalog.begin();
860 }
861 
862 template <typename Catalog, typename T>
863 int _Catalog_upper_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
864  return catalog.upper_bound(value, key) - catalog.begin();
865 }
866 
867 template <typename Catalog, typename T>
868 std::pair<int, int> _Catalog_equal_range(Catalog const& catalog, T const& value, Key<T> const& key) {
870  catalog.equal_range(value, key);
871  return std::pair<int, int>(p.first - catalog.begin(), p.second - catalog.begin());
872 }
873 
875 }
876 }
877 } // namespace lsst::afw::table
878 
879 #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:460
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:849
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition: Catalog.h:533
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
T stable_sort(T... args)
Internal::difference_type difference_type
Definition: Catalog.h:108
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
afw::table::Key< afw::table::Array< MaskPixelT > > mask
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 & 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
afw::table::Schema schema
Definition: GaussianPsf.cc:43
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:720
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:113
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:402
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:727
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:647
reference back() const
Return the last record.
Definition: Catalog.h:434
void pop_back()
Remove the last record in the catalog.
Definition: Catalog.h:470
bool operator()(std::shared_ptr< RecordT > const &a, std::shared_ptr< RecordT > const &b) const
Definition: Catalog.h:677
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:858
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition: Catalog.h:760
Schema getSchema() const
Return the schema associated with the catalog&#39;s table.
Definition: Catalog.h:116
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:491
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:279
result_type operator()(RecordT const &r) const
Definition: Catalog.h:688
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:868
CatalogIterator & operator=(std::shared_ptr< RecordT > const &other) const
Definition: Catalog.h:54
Internal const & getInternal() const
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:648
int const step
Definition: BoundedField.cc:97
STL class.
CatalogT(CatalogT const &other)
Shallow copy constructor.
Definition: Catalog.h:147
const_iterator cend() const
Iterator access.
Definition: Catalog.h:392
int _Catalog_upper_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:863
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
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:454
A base class for image defects.
void clear()
Remove all records from the catalog.
Definition: Catalog.h:552
reference front() const
Return the first record.
Definition: Catalog.h:431
int end
Internal::size_type size_type
Definition: Catalog.h:107
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:101
iterator end()
Iterator access.
Definition: Catalog.h:388
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:538
Iterator class for CatalogT.
Definition: Catalog.h:37
size_type capacity() const
Return the capacity of the catalog.
Definition: Catalog.h:411
Record::ColumnView ColumnView
Definition: Catalog.h:102
T make_pair(T... args)
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
Definition: Catalog.h:541
CatalogIterator(BaseT const &base)
Definition: Catalog.h:46
CatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition: Catalog.h:124
bool empty() const
Return true if the catalog has no records.
Definition: Catalog.h:396
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Catalog.h:322
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:110
void swap(CatalogT &other)
Shallow swap of two catalogs.
Definition: Catalog.h:546
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
const_iterator begin() const
Iterator access.
Definition: Catalog.h:389
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition: Catalog.h:419
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
Definition: Catalog.h:527
#define LSST_EXCEPT(type,...)
STL class.
bool isContiguous() const
Return true if all records are contiguous.
Definition: Catalog.h:379
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:448
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:45
const_iterator cbegin() const
Iterator access.
Definition: Catalog.h:391
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:734
ColumnView getColumnView() const
Return a ColumnView of this catalog&#39;s records.
Definition: Catalog.h:368
reference operator[](size_type i) const
Return the record at index i.
Definition: Catalog.h:425
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:670
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:512
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:399
const_iterator end() const
Iterator access.
Definition: Catalog.h:390
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.
reference at(size_type i) const
Return the record at index i (throws std::out_of_range).
Definition: Catalog.h:428
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
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition: Catalog.h:782
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition: Catalog.h:473
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
Table of amplifier information (AmpInfoRecord records)
Definition: AmpInfo.h:168
T equal_range(T... args)
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:109
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:463
friend class boost::iterator_core_access
Definition: Catalog.h:60