LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
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"
14#include "lsst/afw/table/fwd.h"
18#include "lsst/log/Log.h"
19
20namespace lsst {
21namespace afw {
22namespace table {
23
38template <typename BaseT>
39class CatalogIterator : public boost::iterator_adaptor<CatalogIterator<BaseT>, BaseT,
40 typename BaseT::value_type::element_type> {
41public:
43
44 template <typename OtherBaseT>
47
48 explicit CatalogIterator(BaseT const& base) : CatalogIterator::iterator_adaptor_(base) {}
49
50 template <typename RecordT>
51 operator std::shared_ptr<RecordT>() const {
52 return *this->base();
53 }
54
55 template <typename RecordT>
57 *this->base() = other;
58 return *this;
59 }
60
61private:
63 typename BaseT::value_type::element_type& dereference() const { return **this->base(); }
64};
65
97template <typename RecordT>
98class CatalogT {
100
101public:
103 using Table = typename Record::Table;
104 using ColumnView = typename Record::ColumnView;
105
108 using size_type = typename Internal::size_type;
109 using difference_type = typename Internal::difference_type;
112
114 std::shared_ptr<Table> getTable() const { return _table; }
115
117 Schema getSchema() const { return _table->getSchema(); }
118
125 : _table(table), _internal() {
126 if(!_table) {
127 auto schema=Table::makeMinimalSchema();
128 _table=Table::make(schema);
129 }
130 }
131
133 explicit CatalogT(Schema const& schema) : _table(Table::make(schema)), _internal() {}
134
145 template <typename InputIterator>
147 : _table(table), _internal() {
148 insert(end(), first, last, deep);
149 }
150
152 CatalogT(CatalogT const& other) : _table(other._table), _internal(other._internal) {}
153 // Delegate to copy constructor for backward compatibility
154 CatalogT(CatalogT&& other) : CatalogT(other) {}
155
156 ~CatalogT() = default;
157
164 template <typename OtherRecordT>
166 : _table(other.getTable()), _internal(other.begin().base(), other.end().base()) {}
167
169 CatalogT& operator=(CatalogT const& other) {
170 if (&other != this) {
171 _table = other._table;
172 _internal = other._internal;
173 }
174 return *this;
175 }
176 // Delegate to copy assignment for backward compatibility
177 CatalogT& operator=(CatalogT&& other) { return *this = other; }
178
184 CatalogT<RecordT> subset(ndarray::Array<bool const, 1> const& mask) const {
185 if (size_type(mask.size()) != size()) {
186 throw LSST_EXCEPT(
188 (boost::format("Mask array with %d elements applied to catalog with %d elements") %
189 mask.size() % size())
190 .str());
191 }
193 ndarray::Array<bool const, 1>::Iterator maskIter = mask.begin();
195 for (; maskIter != mask.end(); ++maskIter, ++catIter) {
196 if (*maskIter) result.push_back(catIter);
197 }
198 return result;
199 }
200
206 /* Python's slicing syntax is weird and wonderful.
207
208 Both the "start" and "stop" indices can be negative, which means the
209 abs() of the index less than the size; [-1] means the last item.
210 Moreover, it's possible to have a negative index less than -len(); it
211 will get clipped. That is in fact one way to slice *backward* through
212 the array *and* include element 0;
213
214 >>> range(10)[5:-20:-1]
215 [5, 4, 3, 2, 1, 0]
216
217 The clipping tests in this function look more complicated than they
218 need to be, but that is partly because there are some weird edge cases.
219
220 Also, ptrdiff_t vs size_t introduces some annoying complexity. Note
221 that the args are "startd"/"stopd" (not "start"/"stop").
222
223 There is a fairly complete set of tests in tests/ticket2026.py; if you
224 try to simplify this function, be sure they continue to pass.
225 */
226 size_type S = size();
227 size_type start, stop = 0;
228 // Python doesn't allow step == 0
229 if (step == 0) {
230 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError, "Step cannot be zero");
231 }
232 // Basic negative indexing rule: first add size
233 if (startd < 0) {
234 startd += S;
235 }
236 if (stopd < 0) {
237 stopd += S;
238 }
239 // Start gets clipped to zero; stop does not (yet).
240 if (startd < 0) {
241 startd = 0;
242 }
243 // Now start is non-negative, so can cast to size_t.
244 start = (size_type)startd;
245 if (start > S) {
246 start = S;
247 }
248 if (step > 0) {
249 // When stepping forward, stop gets clipped at zero,
250 // so is non-negative and can get cast to size_t.
251 if (stopd < 0) {
252 stopd = 0;
253 }
254 stop = (size_type)stopd;
255 if (stop > S) {
256 stop = S;
257 }
258 } else if (step < 0) {
259 // When stepping backward, stop gets clipped at -1 so that slices
260 // including 0 are possible.
261 if (stopd < 0) {
262 stopd = -1;
263 }
264 }
265
266 if (((step > 0) && (start >= stop)) || ((step < 0) && ((std::ptrdiff_t)start <= stopd))) {
267 // Empty range
268 return CatalogT<RecordT>(getTable(), begin(), begin());
269 }
270
271 if (step == 1) {
272 // Use the iterator-based constructor for this simple case
273 assert(start >= 0);
274 assert(stop > 0);
275 assert(start < S);
276 assert(stop <= S);
277 return CatalogT<RecordT>(getTable(), begin() + start, begin() + stop);
278 }
279
280 // Build a new CatalogT and copy records into it.
282 size_type N = 0;
283 if (step >= 0) {
284 N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
285 } else {
286 N = (size_t)((stopd - (std::ptrdiff_t)start) / step +
287 (((stopd - (std::ptrdiff_t)start) % step) ? 1 : 0));
288 }
289 cat.reserve(N);
290 if (step >= 0) {
291 for (size_type i = start; i < stop; i += step) {
292 cat.push_back(get(i));
293 }
294 } else {
295 for (std::ptrdiff_t i = (std::ptrdiff_t)start; i > stopd; i += step) {
296 cat.push_back(get(i));
297 }
298 }
299 return cat;
300 }
301
310 void writeFits(std::string const& filename, std::string const& mode = "w", int flags = 0) const {
311 io::FitsWriter::apply(filename, mode, *this, flags);
312 }
313
322 void writeFits(fits::MemFileManager& manager, std::string const& mode = "w", int flags = 0) const {
323 io::FitsWriter::apply(manager, mode, *this, flags);
324 }
325
333 void writeFits(fits::Fits& fitsfile, int flags = 0) const {
334 io::FitsWriter::apply(fitsfile, *this, flags);
335 }
336
347 static CatalogT readFits(std::string const& filename, int hdu = fits::DEFAULT_HDU, int flags = 0) {
348 return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
349 }
350
361 static CatalogT readFits(fits::MemFileManager& manager, int hdu = fits::DEFAULT_HDU, int flags = 0) {
362 return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
363 }
364
372 static CatalogT readFits(fits::Fits& fitsfile, int flags = 0) {
373 return io::FitsReader::apply<CatalogT>(fitsfile, flags);
374 }
375
383 throw LSST_EXCEPT(
385 "Cannot get a column view from a CatalogT<RecordT const> (as column views are always "
386 "non-const views).");
387 }
388 return ColumnView::make(_table, begin(), end());
389 }
390
392 bool isContiguous() const { return ColumnView::isRangeContiguous(_table, begin(), end()); }
393
395
400 iterator begin() { return iterator(_internal.begin()); }
401 iterator end() { return iterator(_internal.end()); }
402 const_iterator begin() const { return const_iterator(_internal.begin()); }
403 const_iterator end() const { return const_iterator(_internal.end()); }
404 const_iterator cbegin() const { return begin(); }
405 const_iterator cend() const { return end(); }
407
409 bool empty() const { return _internal.empty(); }
410
412 size_type size() const { return _internal.size(); }
413
415 size_type max_size() const { return _internal.max_size(); }
416
424 size_type capacity() const { return _internal.size() + _table->getBufferSize(); }
425
433 if (n <= _internal.size()) return;
434 _table->preallocate(n - _internal.size());
435 _internal.reserve(n);
436 }
437
440 size_type old = size();
441 _internal.resize(n);
442 if (old < n) {
443 _table->preallocate(n - old);
444 for (size_type i = old; i != n; ++i) {
445 _internal[i] = _table->makeRecord();
446 }
447 }
448 }
449
451 reference operator[](size_type i) const { return *_internal[i]; }
452
454 reference at(size_type i) const { return *_internal.at(i); }
455
457 reference front() const { return *_internal.front(); }
458
460 reference back() const { return *_internal.back(); }
461
463 std::shared_ptr<RecordT> const get(size_type i) const { return _internal[i]; }
464
466 void set(size_type i, std::shared_ptr<RecordT> const& p) { _internal[i] = p; }
467
473 template <typename InputIterator>
475 clear();
476 insert(end(), first, last, deep);
477 }
478
480 void push_back(Record const& r) {
481 std::shared_ptr<RecordT> p = _table->copyRecord(r);
482 _internal.push_back(p);
483 }
484
486 void push_back(std::shared_ptr<RecordT> const& p) { _internal.push_back(p); }
487
490 std::shared_ptr<RecordT> r = _table->makeRecord();
491 _internal.push_back(r);
492 return r;
493 }
494
496 void pop_back() { _internal.pop_back(); }
497
499 CatalogT copy() const { return CatalogT(getTable()->clone(), begin(), end(), true); }
500
516 template <typename InputIterator>
518 _maybeReserve(pos, first, last, deep,
520 if (deep) {
521 while (first != last) {
522 pos = insert(pos, *first);
523 ++pos;
524 ++first;
525 }
526 } else {
527 while (first != last) {
528 pos = insert(pos, first);
529 assert(pos != end());
530 ++pos;
531 ++first;
532 }
533 }
534 }
535
537 template <typename InputIterator>
539 if (!_table->getSchema().contains(mapper.getOutputSchema())) {
541 "SchemaMapper's output schema does not match catalog's schema");
542 }
543 _maybeReserve(pos, first, last, true,
545 while (first != last) {
546 pos = insert(pos, _table->copyRecord(*first, mapper));
547 ++pos;
548 ++first;
549 }
550 }
551
554 std::shared_ptr<RecordT> p = _table->copyRecord(r);
555 return iterator(_internal.insert(pos.base(), p));
556 }
557
560 return iterator(_internal.insert(pos.base(), p));
561 }
562
564 iterator erase(iterator pos) { return iterator(_internal.erase(pos.base())); }
565
568 return iterator(_internal.erase(first.base(), last.base()));
569 }
570
572 void swap(CatalogT& other) noexcept {
573 _table.swap(other._table);
574 _internal.swap(other._internal);
575 }
576
578 void clear() { _internal.clear(); }
579
581 template <typename T>
582 bool isSorted(Key<T> const& key) const;
583
589 template <typename Compare>
590 bool isSorted(Compare cmp) const;
591
593 template <typename T>
594 void sort(Key<T> const& key);
595
601 template <typename Compare>
603
605
621 template <typename T>
622 iterator find(typename Field<T>::Value const& value, Key<T> const& key);
623
624 template <typename T>
625 const_iterator find(typename Field<T>::Value const& value, Key<T> const& key) const;
627
629
642 template <typename T>
643 iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key);
644
645 template <typename T>
646 const_iterator lower_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
647
648 template <typename T>
649 iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key);
650
651 template <typename T>
652 const_iterator upper_bound(typename Field<T>::Value const& value, Key<T> const& key) const;
653
654 template <typename T>
656
657 template <typename T>
659 Key<T> const& key) const;
661
663
675 Internal& getInternal() { return _internal; }
676 Internal const& getInternal() const { return _internal; }
678
679private:
680 template <typename InputIterator>
681 void _maybeReserve(iterator& pos, InputIterator first, InputIterator last, bool deep,
683 if (deep) _table->preallocate(last - first);
684 }
685
686 template <typename InputIterator>
687 void _maybeReserve(iterator pos, InputIterator first, InputIterator last, bool deep,
689
691 Internal _internal;
692};
693
694namespace detail {
695
696template <typename RecordT, typename T>
698 bool operator()(RecordT const& a, RecordT const& b) const { return a.get(key) < b.get(key); }
699
701};
702
703template <typename RecordT, typename Adaptee>
706 return adaptee(*a, *b);
707 }
708
710};
711
712template <typename RecordT, typename T>
714 using result_type = typename Field<T>::Value;
715
716 result_type operator()(RecordT const& r) const { return r.get(key); }
717
719};
720
721} // namespace detail
722
723template <typename RecordT>
724template <typename Compare>
728 if (empty()) return true;
729 const_iterator last = this->begin();
731 ++i;
732 for (; i != this->end(); ++i) {
733 if (f(i, last)) return false;
734 last = i;
735 }
736 return true;
737}
738
739template <typename RecordT>
740template <typename Compare>
743 std::stable_sort(_internal.begin(), _internal.end(), f);
744}
745
746template <typename RecordT>
747template <typename T>
748bool CatalogT<RecordT>::isSorted(Key<T> const& key) const {
750 return isSorted(f);
751}
752
753template <typename RecordT>
754template <typename T>
757 return sort(f);
758}
759
760template <typename RecordT>
761template <typename T>
763 Key<T> const& key) {
765 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
766 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
767 /* Try binary search for log n search assuming the table is sorted.
768 * If the search is unsuccessful, try a brute-force search before quitting.
769 */
770 SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
771 if (i.base() == end() || *i != value) {
772 i = std::find(SearchIter(begin(), f), SearchIter(end(), f), value);
773 if (i.base() == end()) {
774 return end();
775 }
776 LOGL_DEBUG("lsst.afw.table.Catalog", "Catalog is not sorted by the key. Finding a record may be slow.");
777 }
778 return i.base();
779}
780
781template <typename RecordT>
782template <typename T>
784 Key<T> const& key) const {
786 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
787 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
788 /* Try binary search for log n search assuming the table is sorted.
789 * If the search is unsuccessful, try a brute-force search before quitting.
790 */
791 SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
792 if (i.base() == end() || *i != value) {
793 i = std::find(SearchIter(begin(), f), SearchIter(end(), f), value);
794 if (i.base() == end()) {
795 return end();
796 }
797 LOGL_DEBUG("lsst.afw.table.Catalog", "Catalog is not sorted by the key. Finding a record may be slow.");
798 }
799 return i.base();
800}
801
802template <typename RecordT>
803template <typename T>
805 Key<T> const& key) {
807 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
808 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
809 SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
810 return i.base();
811}
812
813template <typename RecordT>
814template <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 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
820 SearchIter i = std::lower_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
821 return i.base();
822}
823
824template <typename RecordT>
825template <typename T>
827 Key<T> const& key) {
829 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
830 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
831 SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
832 return i.base();
833}
834
835template <typename RecordT>
836template <typename T>
838 typename Field<T>::Value const& value, Key<T> const& key) const {
840 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
841 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
842 SearchIter i = std::upper_bound(SearchIter(begin(), f), SearchIter(end(), f), value);
843 return i.base();
844}
845
846template <typename RecordT>
847template <typename T>
849CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) {
851 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
852 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator>;
854 std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
855 return std::make_pair(i.first.base(), i.second.base());
856}
857
858template <typename RecordT>
859template <typename T>
861CatalogT<RecordT>::equal_range(typename Field<T>::Value const& value, Key<T> const& key) const {
863 // Iterator adaptor that makes a CatalogT iterator work like an iterator over field values.
864 using SearchIter = boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator>;
866 std::equal_range(SearchIter(begin(), f), SearchIter(end(), f), value);
867 return std::make_pair(i.first.base(), i.second.base());
868}
869
871
892template <typename RecordT, typename Catalog, typename T>
893std::shared_ptr<RecordT> _Catalog_find(Catalog const& catalog, T const& value, Key<T> const& key) {
894 typename Catalog::const_iterator iter = catalog.find(value, key);
895 if (iter == catalog.end()) {
897 }
898 return iter; // n.b. CatalogIterator is explicitly convertible to shared_ptr
899}
900
901template <typename Catalog, typename T>
902int _Catalog_lower_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
903 return catalog.lower_bound(value, key) - catalog.begin();
904}
905
906template <typename Catalog, typename T>
907int _Catalog_upper_bound(Catalog const& catalog, T const& value, Key<T> const& key) {
908 return catalog.upper_bound(value, key) - catalog.begin();
909}
910
911template <typename Catalog, typename T>
912std::pair<int, int> _Catalog_equal_range(Catalog const& catalog, T const& value, Key<T> const& key) {
914 catalog.equal_range(value, key);
915 return std::pair<int, int>(p.first - catalog.begin(), p.second - catalog.begin());
916}
917
919} // namespace table
920} // namespace afw
921} // namespace lsst
922
923#endif // !AFW_TABLE_Catalog_h_INCLUDED
py::object result
Definition _schema.cc:429
int const step
int end
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
afw::table::Key< afw::table::Array< MaskPixelT > > mask
LSST DM logging module built on log4cxx.
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition Log.h:515
SchemaMapper * mapper
table::Key< int > b
T at(T... args)
T back(T... args)
Basic LSST definitions.
T begin(T... args)
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
Definition fits.h:308
Lifetime-management for memory that goes into FITS memory files.
Definition fits.h:125
Tag types used to declare specialized field types.
Definition misc.h:31
Iterator class for CatalogT.
Definition Catalog.h:40
CatalogIterator(BaseT const &base)
Definition Catalog.h:48
CatalogIterator & operator=(std::shared_ptr< RecordT > const &other) const
Definition Catalog.h:56
friend class boost::iterator_core_access
Definition Catalog.h:62
CatalogIterator(CatalogIterator< OtherBaseT > const &other)
Definition Catalog.h:45
A custom container class for records, based on std::vector.
Definition Catalog.h:98
void clear()
Remove all records from the catalog.
Definition Catalog.h:578
CatalogT & operator=(CatalogT &&other)
Definition Catalog.h:177
size_type capacity() const
Return the capacity of the catalog.
Definition Catalog.h:424
CatalogT(CatalogT const &other)
Shallow copy constructor.
Definition Catalog.h:152
const_iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key) const
Definition Catalog.h:815
std::shared_ptr< RecordT > const get(size_type i) const
Return a pointer to the record at index i.
Definition Catalog.h:463
ColumnView getColumnView() const
Return a ColumnView of this catalog's records.
Definition Catalog.h:381
void pop_back()
Remove the last record in the catalog.
Definition Catalog.h:496
void push_back(std::shared_ptr< RecordT > const &p)
Add the given record to the end of the catalog without copying.
Definition Catalog.h:486
reference at(size_type i) const
Return the record at index i (throws std::out_of_range).
Definition Catalog.h:454
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:347
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
Definition Catalog.h:567
void set(size_type i, std::shared_ptr< RecordT > const &p)
Set the record at index i to a pointer.
Definition Catalog.h:466
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
Definition Catalog.h:553
typename Record::ColumnView ColumnView
Definition Catalog.h:104
const_iterator end() const
Definition Catalog.h:403
const_iterator cend() const
Definition Catalog.h:405
size_type size() const
Return the number of elements in the catalog.
Definition Catalog.h:412
bool empty() const
Return true if the catalog has no records.
Definition Catalog.h:409
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:361
void assign(InputIterator first, InputIterator last, bool deep=false)
Replace the contents of the table with an iterator range.
Definition Catalog.h:474
bool isContiguous() const
Return true if all records are contiguous.
Definition Catalog.h:392
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:762
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Definition Catalog.h:826
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:205
CatalogT(Schema const &schema)
Construct a catalog from a schema, creating a table with Table::make(schema).
Definition Catalog.h:133
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:489
reference back() const
Return the last record.
Definition Catalog.h:460
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Definition Catalog.h:559
std::pair< iterator, iterator > equal_range(typename Field< T >::Value const &value, Key< T > const &key)
CatalogIterator< typename Internal::iterator > iterator
Definition Catalog.h:110
std::pair< const_iterator, const_iterator > equal_range(typename Field< T >::Value const &value, Key< T > const &key) const
CatalogT(CatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
Definition Catalog.h:165
iterator begin()
Iterator access.
Definition Catalog.h:400
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Definition Catalog.h:564
CatalogT(CatalogT &&other)
Definition Catalog.h:154
CatalogIterator< typename Internal::const_iterator > const_iterator
Definition Catalog.h:111
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
Definition Catalog.h:432
reference operator[](size_type i) const
Return the record at index i.
Definition Catalog.h:451
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Definition Catalog.h:804
typename Record::Table Table
Definition Catalog.h:103
typename Internal::size_type size_type
Definition Catalog.h:108
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:184
CatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
Definition Catalog.h:124
reference front() const
Return the first record.
Definition Catalog.h:457
const_iterator begin() const
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:755
void resize(size_type n)
Change the size of the catalog, removing or adding empty records as needed.
Definition Catalog.h:439
size_type max_size() const
Return the maximum number of elements allowed in a catalog.
Definition Catalog.h:415
CatalogT copy() const
Deep-copy the catalog using a cloned table.
Definition Catalog.h:499
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:322
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
Definition Catalog.h:333
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
Definition Catalog.h:517
Internal const & getInternal() const
Definition Catalog.h:676
CatalogT & operator=(CatalogT const &other)
Shallow assigment.
Definition Catalog.h:169
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
Definition Catalog.h:675
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:372
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition Catalog.h:114
const_iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key) const
Definition Catalog.h:837
Schema getSchema() const
Return the schema associated with the catalog's table.
Definition Catalog.h:117
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:310
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:146
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
Definition Catalog.h:748
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:538
void swap(CatalogT &other) noexcept
Shallow swap of two catalogs.
Definition Catalog.h:572
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
Definition Catalog.h:480
const_iterator cbegin() const
Definition Catalog.h:404
typename Internal::difference_type difference_type
Definition Catalog.h:109
Defines the fields and offsets for a table.
Definition Schema.h:51
A mapping between the keys of two Schemas, used to copy data between them.
typename Base::const_iterator const_iterator
typename Base::iterator iterator
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
Definition FitsWriter.h:37
Reports invalid arguments.
Definition Runtime.h:66
Reports attempts to exceed implementation-defined length limits for some classes.
Definition Runtime.h:76
Reports errors in the logical structure of the program.
Definition Runtime.h:46
T clear(T... args)
T empty(T... args)
T end(T... args)
T equal_range(T... args)
T erase(T... args)
T find(T... args)
T front(T... args)
T insert(T... args)
T lower_bound(T... args)
T make_pair(T... args)
T max_size(T... args)
const int DEFAULT_HDU
Specify that the default HDU should be read.
int _Catalog_upper_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition Catalog.h:907
std::shared_ptr< RecordT > _Catalog_find(Catalog const &catalog, T const &value, Key< T > const &key)
Definition Catalog.h:893
std::pair< int, int > _Catalog_equal_range(Catalog const &catalog, T const &value, Key< T > const &key)
Definition Catalog.h:912
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
Definition Catalog.h:902
T pop_back(T... args)
T push_back(T... args)
T reserve(T... args)
T resize(T... args)
T size(T... args)
T stable_sort(T... args)
T Value
the type returned by BaseRecord::get
Definition FieldBase.h:42
bool operator()(std::shared_ptr< RecordT > const &a, std::shared_ptr< RecordT > const &b) const
Definition Catalog.h:705
bool operator()(RecordT const &a, RecordT const &b) const
Definition Catalog.h:698
result_type operator()(RecordT const &r) const
Definition Catalog.h:716
typename Field< T >::Value result_type
Definition Catalog.h:714
T swap(T... args)
T upper_bound(T... args)