LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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/table/fwd.h"
17 
18 namespace lsst { namespace afw { namespace table {
19 
34 template <typename BaseT>
36  : public boost::iterator_adaptor<CatalogIterator<BaseT>,BaseT,typename BaseT::value_type::element_type>
37 {
38 public:
39 
41 
42  template <typename OtherBaseT>
44  CatalogIterator::iterator_adaptor_(other.base())
45  {}
46 
47  explicit CatalogIterator(BaseT const & base) : CatalogIterator::iterator_adaptor_(base) {}
48 
49  template <typename RecordT>
50  operator PTR(RecordT) () const { return *this->base(); }
51 
52  template <typename RecordT>
53  CatalogIterator & operator=(PTR(RecordT) const & other) const {
54  *this->base() = other;
55  return *this;
56  }
57 
58 private:
60  typename BaseT::value_type::element_type & dereference() const { return **this->base(); }
61 };
62 
94 template <typename RecordT>
95 class CatalogT {
96  typedef std::vector<PTR(RecordT)> Internal;
97 public:
98 
99  typedef RecordT Record;
100  typedef typename Record::Table Table;
101  typedef typename Record::ColumnView ColumnView;
102 
103  typedef RecordT value_type;
104  typedef RecordT & reference;
105  typedef PTR(RecordT) pointer;
106  typedef typename Internal::size_type size_type;
110 
112  PTR(Table) getTable() const { return _table; }
113 
115  Schema getSchema() const { return _table->getSchema(); }
116 
123  explicit CatalogT(PTR(Table) const & table = PTR(Table)()) : _table(table), _internal() {}
124 
126  explicit CatalogT(Schema const & schema) : _table(Table::make(schema)), _internal() {}
127 
138  template <typename InputIterator>
139  CatalogT(PTR(Table) const & table, InputIterator first, InputIterator last, bool deep=false) :
140  _table(table), _internal()
141  {
142  insert(end(), first, last, deep);
143  }
144 
146  CatalogT(CatalogT const & other) : _table(other._table), _internal(other._internal) {}
147 
154  template <typename OtherRecordT>
156  _table(other.getTable()), _internal(other.begin().base(), other.end().base())
157  {}
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() % size()).str()
179  );
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 
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(
220  pex::exceptions::InvalidParameterError,
221  "Step cannot be zero"
222  );
223  }
224  // Basic negative indexing rule: first add size
225  if (startd < 0) {
226  startd += S;
227  }
228  if (stopd < 0) {
229  stopd += S;
230  }
231  // Start gets clipped to zero; stop does not (yet).
232  if (startd < 0) {
233  startd = 0;
234  }
235  // Now start is non-negative, so can cast to size_t.
236  start = (size_type)startd;
237  if (start > S) {
238  start = S;
239  }
240  if (step > 0) {
241  // When stepping forward, stop gets clipped at zero,
242  // so is non-negative and can get cast to size_t.
243  if (stopd < 0) {
244  stopd = 0;
245  }
246  stop = (size_type)stopd;
247  if (stop > S) {
248  stop = S;
249  }
250  } else if (step < 0) {
251  // When stepping backward, stop gets clipped at -1 so that slices
252  // including 0 are possible.
253  if (stopd < 0) {
254  stopd = -1;
255  }
256  }
257 
258  if (((step > 0) && (start >= stop)) ||
259  ((step < 0) && ((std::ptrdiff_t)start <= stopd))) {
260  // Empty range
261  return CatalogT<RecordT>(getTable(), begin(), begin());
262  }
263 
264  if (step == 1) {
265  // Use the iterator-based constructor for this simple case
266  assert(start >= 0);
267  assert(stop > 0);
268  assert(start < S);
269  assert(stop <= S);
270  return CatalogT<RecordT>(getTable(), begin()+start, begin()+stop);
271  }
272 
273  // Build a new CatalogT and copy records into it.
275  size_type N = 0;
276  if (step >= 0) {
277  N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
278  } else {
279  N = (size_t)((stopd - (std::ptrdiff_t)start) / step +
280  (((stopd - (std::ptrdiff_t)start) % step) ? 1 : 0));
281  }
282  cat.reserve(N);
283  if (step >= 0) {
284  for (size_type i=start; i<stop; i+=step) {
285  cat.push_back(get(i));
286  }
287  } else {
288  for (std::ptrdiff_t i=(std::ptrdiff_t)start; i>stopd; i+=step) {
289  cat.push_back(get(i));
290  }
291  }
292  return cat;
293  }
294 
303  void writeFits(std::string const & filename, std::string const & mode="w", int flags=0) const {
304  io::FitsWriter::apply(filename, mode, *this, flags);
305  }
306 
315  void writeFits(fits::MemFileManager & manager, std::string const & mode="w", int flags=0) const {
316  io::FitsWriter::apply(manager, mode, *this, flags);
317  }
318 
326  void writeFits(fits::Fits & fitsfile, int flags=0) const {
327  io::FitsWriter::apply(fitsfile, *this, flags);
328  }
329 
339  static CatalogT readFits(std::string const & filename, int hdu=0, int flags=0) {
340  return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
341  }
342 
352  static CatalogT readFits(fits::MemFileManager & manager, int hdu=0, int flags=0) {
353  return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
354  }
355 
363  static CatalogT readFits(fits::Fits & fitsfile, int flags=0) {
364  return io::FitsReader::apply<CatalogT>(fitsfile, flags);
365  }
366 
373  if (std::is_const<RecordT>::value) {
374  throw LSST_EXCEPT(
375  pex::exceptions::LogicError,
376  "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
377  "non-const views)."
378  );
379  }
380  return ColumnView::make(_table, begin(), end());
381  }
382 
384  bool isContiguous() const { return ColumnView::isRangeContiguous(_table, begin(), end()); }
385 
387 
392  iterator begin() { return iterator(_internal.begin()); }
393  iterator end() { return iterator(_internal.end()); }
394  const_iterator begin() const { return const_iterator(_internal.begin()); }
395  const_iterator end() const { return const_iterator(_internal.end()); }
397 
399  bool empty() const { return _internal.empty(); }
400 
402  size_type size() const { return _internal.size(); }
403 
405  size_type max_size() const { return _internal.max_size(); }
406 
414  size_type capacity() const { return _internal.size() + _table->getBufferSize(); }
415 
422  void reserve(size_type n) {
423  if (n <= _internal.size()) return;
424  _table->preallocate(n - _internal.size());
425  }
426 
428  reference operator[](size_type i) const { return *_internal[i]; }
429 
431  reference at(size_type i) const { return *_internal.at(i); }
432 
434  reference front() const { return *_internal.front(); }
435 
437  reference back() const { return *_internal.back(); }
438 
440  PTR(RecordT) const get(size_type i) const { return _internal[i]; }
441 
443  void set(size_type i, PTR(RecordT) const & p) {
444  _internal[i] = p;
445  }
446 
452  template <typename InputIterator>
453  void assign(InputIterator first, InputIterator last, bool deep=false) {
454  clear();
455  insert(end(), first, last, deep);
456  }
457 
459  void push_back(Record const & r) {
460  PTR(RecordT) p = _table->copyRecord(r);
461  _internal.push_back(p);
462  }
463 
465  void push_back(PTR(RecordT) const & p) {
466  _internal.push_back(p);
467  }
468 
470  PTR(RecordT) addNew() {
471  PTR(RecordT) r = _table->makeRecord();
472  _internal.push_back(r);
473  return r;
474  }
475 
477  void pop_back() { _internal.pop_back(); }
478 
480  CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
481 
497  template <typename InputIterator>
498  void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false) {
500  pos, first, last, deep, (typename std::iterator_traits<InputIterator>::iterator_category*)0
501  );
502  if (deep) {
503  while (first != last) {
504  pos = insert(pos, *first);
505  ++pos;
506  ++first;
507  }
508  } else {
509  while (first != last) {
510  pos = insert(pos, first);
511  assert(pos != end());
512  ++pos;
513  ++first;
514  }
515  }
516  }
517 
519  template <typename InputIterator>
520  void insert(SchemaMapper const & mapper, iterator pos, InputIterator first, InputIterator last) {
521  if (!_table->getSchema().contains(mapper.getOutputSchema())) {
522  throw LSST_EXCEPT(
523  pex::exceptions::InvalidParameterError,
524  "SchemaMapper's output schema does not match catalog's schema"
525  );
526  }
528  pos, first, last, true, (typename std::iterator_traits<InputIterator>::iterator_category*)0
529  );
530  while (first != last) {
531  pos = insert(pos, _table->copyRecord(*first, mapper));
532  ++pos;
533  ++first;
534  }
535  }
536 
538  iterator insert(iterator pos, Record const & r) {
539  PTR(RecordT) p = _table->copyRecord(r);
540  return iterator(_internal.insert(pos.base(), p));
541  }
542 
544  iterator insert(iterator pos, PTR(RecordT) const & p) {
545  return iterator(_internal.insert(pos.base(), p));
546  }
547 
549  iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
550 
553  return iterator(_internal.erase(first.base(), last.base()));
554  }
555 
557  void swap(CatalogT & other) {
558  _table.swap(other._table);
559  _internal.swap(other._internal);
560  }
561 
563  void clear() { _internal.clear(); }
564 
566  template <typename T>
567  bool isSorted(Key<T> const & key) const;
568 
574  template <typename Compare>
575  bool isSorted(Compare cmp) const;
576 
578  template <typename T>
579  void sort(Key<T> const & key);
580 
586  template <typename Compare>
587  void sort(Compare cmp);
588 
590 
604  template <typename T>
605  iterator find(typename Field<T>::Value const & value, Key<T> const & key);
606 
607  template <typename T>
608  const_iterator find(typename Field<T>::Value const & value, Key<T> const & key) const;
610 
612 
625  template <typename T>
626  iterator lower_bound(typename Field<T>::Value const & value, Key<T> const & key);
627 
628  template <typename T>
629  const_iterator lower_bound(typename Field<T>::Value const & value, Key<T> const & key) const;
630 
631  template <typename T>
632  iterator upper_bound(typename Field<T>::Value const & value, Key<T> const & key);
633 
634  template <typename T>
635  const_iterator upper_bound(typename Field<T>::Value const & value, Key<T> const & key) const;
636 
637  template <typename T>
638  std::pair<iterator,iterator>
639  equal_range(typename Field<T>::Value const & value, Key<T> const & key);
640 
641  template <typename T>
642  std::pair<const_iterator,const_iterator>
643  equal_range(typename Field<T>::Value const & value, Key<T> const & key) const;
645 
647 
660  Internal const & getInternal() const { return _internal; }
662 
663 private:
664 
665  template <typename InputIterator>
667  iterator & pos, InputIterator first, InputIterator last, bool deep,
668  std::random_access_iterator_tag *
669  ) {
670  if (deep) _table->preallocate(last - first);
671  }
672 
673  template <typename InputIterator>
675  iterator pos, InputIterator first, InputIterator last, bool deep,
676  std::input_iterator_tag *
677  ) {}
678 
681 };
682 
683 namespace detail {
684 
685 template <typename RecordT, typename T>
687 
688  bool operator()(RecordT const & a, RecordT const & b) const { return a.get(key) < b.get(key); }
689 
691 };
692 
693 template <typename RecordT, typename Adaptee>
695 
696  bool operator()(PTR(RecordT) const & a, PTR(RecordT) const & b) const {
697  return adaptee(*a, *b);
698  }
699 
700  Adaptee adaptee;
701 };
702 
703 template <typename RecordT, typename T>
705 
706  typedef typename Field<T>::Value result_type;
707 
708  result_type operator()(RecordT const & r) const { return r.get(key); }
709 
711 };
712 
713 } // namespace detail
714 
715 template <typename RecordT>
716 template <typename Compare>
717 bool CatalogT<RecordT>::isSorted(Compare cmp) const {
720  if (empty()) return true;
721  const_iterator last = this->begin();
722  const_iterator i = last; ++i;
723  for (; i != this->end(); ++i) {
724  if (f(i, last)) return false;
725  last = i;
726  }
727  return true;
728 }
729 
730 template <typename RecordT>
731 template <typename Compare>
732 void CatalogT<RecordT>::sort(Compare cmp) {
734  std::stable_sort(_internal.begin(), _internal.end(), f);
735 }
736 
737 template <typename RecordT>
738 template <typename T>
739 bool CatalogT<RecordT>::isSorted(Key<T> const & key) const {
741  return isSorted(f);
742 }
743 
744 template <typename RecordT>
745 template <typename T>
746 void CatalogT<RecordT>::sort(Key<T> const & key) {
748  return sort(f);
749 }
750 
751 template <typename RecordT>
752 template <typename T>
754 CatalogT<RecordT>::find(typename Field<T>::Value const & value, Key<T> const & key) {
756  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
757  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,iterator> SearchIter;
758  // Use binary search for log n search; requires sorted table.
759  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
760  if (i.base() == end() || *i != value) return end();
761  return i.base();
762 }
763 
764 template <typename RecordT>
765 template <typename T>
767 CatalogT<RecordT>::find(typename Field<T>::Value const & value, Key<T> const & key) const {
769  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
770  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,const_iterator> SearchIter;
771  // Use binary search for log n search; requires sorted table.
772  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
773  if (i.base() == end() || *i != value) return end();
774  return i.base();
775 }
776 
777 template <typename RecordT>
778 template <typename T>
780 CatalogT<RecordT>::lower_bound(typename Field<T>::Value const & value, Key<T> const & key) {
782  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
783  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,iterator> SearchIter;
784  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
785  return i.base();
786 }
787 
788 template <typename RecordT>
789 template <typename T>
791 CatalogT<RecordT>::lower_bound(typename Field<T>::Value const & value, Key<T> const & key) const {
793  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
794  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,const_iterator> SearchIter;
795  SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
796  return i.base();
797 }
798 
799 template <typename RecordT>
800 template <typename T>
802 CatalogT<RecordT>::upper_bound(typename Field<T>::Value const & value, Key<T> const & key) {
804  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
805  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,iterator> SearchIter;
806  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
807  return i.base();
808 }
809 
810 template <typename RecordT>
811 template <typename T>
813 CatalogT<RecordT>::upper_bound(typename Field<T>::Value const & value, Key<T> const & key) const {
815  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
816  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,const_iterator> SearchIter;
817  SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
818  return i.base();
819 }
820 
821 template <typename RecordT>
822 template <typename T>
823 std::pair<typename CatalogT<RecordT>::iterator,typename CatalogT<RecordT>::iterator>
824 CatalogT<RecordT>::equal_range(typename Field<T>::Value const & value, Key<T> const & key) {
826  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
827  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,iterator> SearchIter;
828  std::pair<SearchIter,SearchIter> i
829  = std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
830  return std::make_pair(i.first.base(), i.second.base());
831 
832 }
833 
834 template <typename RecordT>
835 template <typename T>
836 std::pair<typename CatalogT<RecordT>::const_iterator,typename CatalogT<RecordT>::const_iterator>
837 CatalogT<RecordT>::equal_range(typename Field<T>::Value const & value, Key<T> const & key) const {
839  // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
840  typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT,T>,const_iterator> SearchIter;
841  std::pair<SearchIter,SearchIter> i
842  = std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
843  return std::make_pair(i.first.base(), i.second.base());
844 }
845 
847 
868 template <typename RecordT, typename Catalog, typename T>
869 PTR(RecordT) _Catalog_find(Catalog const & catalog, T const & value, Key<T> const & key) {
870  typename Catalog::const_iterator iter = catalog.find(value, key);
871  if (iter == catalog.end()) {
872  return PTR(RecordT)();
873  }
874  return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
875 }
876 
877 template <typename Catalog, typename T>
878 int _Catalog_lower_bound(Catalog const & catalog, T const & value, Key<T> const & key) {
879  return catalog.lower_bound(value, key) - catalog.begin();
880 }
881 
882 template <typename Catalog, typename T>
883 int _Catalog_upper_bound(Catalog const & catalog, T const & value, Key<T> const & key) {
884  return catalog.upper_bound(value, key) - catalog.begin();
885 }
886 
887 template <typename Catalog, typename T>
888 std::pair<int,int> _Catalog_equal_range(Catalog const & catalog, T const & value, Key<T> const & key) {
889  std::pair<typename Catalog::const_iterator,typename Catalog::const_iterator> p
890  = catalog.equal_range(value, key);
891  return std::pair<int,int>(p.first - catalog.begin(), p.second - catalog.begin());
892 }
893 
895 
896 
897 }}} // namespace lsst::afw::table
898 
899 #endif // !AFW_TABLE_Catalog_h_INCLUDED
int iter
CatalogT(CatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition: Catalog.h:155
const_iterator end() const
Definition: Catalog.h:395
const_iterator begin() const
Definition: Catalog.h:394
Defines the fields and offsets for a table.
Definition: Schema.h:44
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:688
iterator insert(iterator pos, boost::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition: Catalog.h:544
Internal::difference_type difference_type
Definition: Catalog.h:107
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
Definition: SchemaMapper.h:26
CatalogT(boost::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:139
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition: Catalog.h:739
boost::shared_ptr< Table > _table
Definition: Catalog.h:679
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:95
afw::table::Schema schema
Definition: GaussianPsf.cc:41
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:19
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:746
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:659
bool operator()(boost::shared_ptr< RecordT > const &a, boost::shared_ptr< RecordT > const &b) const
Definition: Catalog.h:696
void pop_back()
Remove the last record in the catalog.
Definition: Catalog.h:477
std::pair< int, int > _Catalog_equal_range(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:888
boost::shared_ptr< PeakRecord > pointer
Definition: Catalog.h:105
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:878
std::vector< boost::shared_ptr< RecordT > > Internal
Definition: Catalog.h:96
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition: Catalog.h:498
void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep, std::input_iterator_tag *)
Definition: Catalog.h:674
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition: fits.h:201
reference at(size_type i) const
Return the record at index i (throws std::out_of_range).
Definition: Catalog.h:431
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. The arguments correspond to python&#39;s slice() synt...
Definition: Catalog.h:194
size_type size() const
Return the number of elements in the catalog.
Definition: Catalog.h:402
void push_back(boost::shared_ptr< RecordT > const &p)
Add the given record to the end of the catalog without copying.
Definition: Catalog.h:465
CatalogT(CatalogT const &other)
Shallow copy constructor.
Definition: Catalog.h:146
static CatalogT readFits(std::string const &filename, int hdu=0, int flags=0)
Read a FITS binary table from a regular file.
Definition: Catalog.h:339
int _Catalog_upper_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:883
bool empty() const
Return true if the catalog has no records.
Definition: Catalog.h:399
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition: Catalog.h:459
Internal const & getInternal() const
Return a reference to the internal vector-of-shared_ptr.
Definition: Catalog.h:660
void clear()
Remove all records from the catalog.
Definition: Catalog.h:563
Lifetime-management for memory that goes into FITS memory files.
Definition: fits.h:105
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:126
BaseT::value_type::element_type & dereference() const
Definition: Catalog.h:60
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Definition: Catalog.h:549
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition: Catalog.h:480
Iterator class for CatalogT.
Definition: Catalog.h:35
Record::ColumnView ColumnView
Definition: Catalog.h:101
size_type max_size() const
Return the maximum number of elements allowed in a catalog.
Definition: Catalog.h:405
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
Definition: Catalog.h:552
CatalogIterator(BaseT const &base)
Definition: Catalog.h:47
void _maybeReserve(iterator &pos, InputIterator first, InputIterator last, bool deep, std::random_access_iterator_tag *)
Definition: Catalog.h:666
boost::shared_ptr< RecordT > _Catalog_find(Catalog const &catalog, T const &value, Key< T > const &key)
Definition: Catalog.h:869
bool isContiguous() const
Return true if all records are contiguous.
Definition: Catalog.h:384
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition: Catalog.h:109
void swap(CatalogT &other)
Shallow swap of two catalogs.
Definition: Catalog.h:557
result_type operator()(RecordT const &r) const
Definition: Catalog.h:708
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition: Catalog.h:422
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
Definition: Catalog.h:538
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition: Catalog.h:440
Record::Table Table
Definition: Catalog.h:100
void assign(InputIterator first, InputIterator last, bool deep=false)
Replace the contents of the table with an iterator range.
Definition: Catalog.h:453
A class used as a handle to a particular field in a table.
Definition: fwd.h:44
T Value
the type returned by BaseRecord::get
Definition: FieldBase.h:50
size_type capacity() const
Return the capacity of the catalog.
Definition: Catalog.h:414
boost::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:112
#define PTR(...)
Definition: base.h:41
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition: FitsWriter.h:35
boost::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:470
ColumnView getColumnView() const
Return a ColumnView of this catalog&#39;s records.
Definition: Catalog.h:372
reference back() const
Return the last record.
Definition: Catalog.h:437
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:520
afw::table::Key< double > b
reference operator[](size_type i) const
Return the record at index i.
Definition: Catalog.h:428
reference front() const
Return the first record.
Definition: Catalog.h:434
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
void set(size_type i, boost::shared_ptr< RecordT > const &p)
Set the record at index i to a pointer.
Definition: Catalog.h:443
iterator find(typename Field< T >::Value const &value, Key< T > const &key)
Return an iterator to the record with the given value.
CatalogT(boost::shared_ptr< Table > const &table=boost::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition: Catalog.h:123
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
Definition: Catalog.h:326
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:303
Include files required for standard LSST Exception handling.
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:363
Schema getSchema() const
Return the schema associated with the catalog&#39;s table.
Definition: Catalog.h:115
static CatalogT readFits(fits::MemFileManager &manager, int hdu=0, int flags=0)
Read a FITS binary table from a RAM file.
Definition: Catalog.h:352
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:108
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:315
std::pair< iterator, iterator > equal_range(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
CatalogIterator & operator=(boost::shared_ptr< RecordT > const &other) const
Definition: Catalog.h:53
friend class boost::iterator_core_access
Definition: Catalog.h:59