2 #ifndef AFW_TABLE_Catalog_h_INCLUDED 3 #define AFW_TABLE_Catalog_h_INCLUDED 8 #include "boost/iterator/iterator_adaptor.hpp" 9 #include "boost/iterator/transform_iterator.hpp" 37 template <
typename BaseT>
38 class CatalogIterator :
public boost::iterator_adaptor<CatalogIterator<BaseT>, BaseT,
39 typename BaseT::value_type::element_type> {
43 template <
typename OtherBaseT>
49 template <
typename RecordT>
54 template <
typename RecordT>
56 *this->base() = other;
62 typename BaseT::value_type::element_type& dereference()
const {
return **this->base(); }
96 template <
typename RecordT>
126 : _table(table), _internal() {}
141 template <
typename InputIterator>
143 : _table(table), _internal() {
144 insert(
end(), first, last, deep);
156 template <
typename OtherRecordT>
158 : _table(other.getTable()), _internal(other.begin().base(), other.
end().base()) {}
162 if (&other !=
this) {
163 _table = other._table;
164 _internal = other._internal;
175 if (size_type(mask.size()) != size()) {
178 (boost::format(
"Mask array with %d elements applied to catalog with %d elements") %
183 ndarray::Array<bool const, 1>::Iterator maskIter = mask.begin();
184 const_iterator catIter = begin();
185 for (; maskIter != mask.end(); ++maskIter, ++catIter) {
186 if (*maskIter) result.push_back(catIter);
216 size_type S = size();
217 size_type start, stop = 0;
234 start = (size_type)startd;
244 stop = (size_type)stopd;
248 }
else if (step < 0) {
256 if (((step > 0) && (start >= stop)) || ((step < 0) && ((
std::ptrdiff_t)start <= stopd))) {
274 N = (stop - start) / step + (((stop - start) % step) ? 1 : 0);
281 for (size_type i = start; i < stop; i +=
step) {
338 return io::FitsReader::apply<CatalogT>(filename, hdu, flags);
352 return io::FitsReader::apply<CatalogT>(manager, hdu, flags);
363 return io::FitsReader::apply<CatalogT>(fitsfile, flags);
375 "Cannot get a column view from a CatalogT<RecordT const> (as column views are always " 376 "non-const views).");
378 return ColumnView::make(_table, begin(),
end());
382 bool isContiguous()
const {
return ColumnView::isRangeContiguous(_table, begin(),
end()); }
390 iterator
begin() {
return iterator(_internal.begin()); }
391 iterator
end() {
return iterator(_internal.end()); }
392 const_iterator
begin()
const {
return const_iterator(_internal.begin()); }
393 const_iterator
end()
const {
return const_iterator(_internal.end()); }
394 const_iterator
cbegin()
const {
return begin(); }
399 bool empty()
const {
return _internal.empty(); }
402 size_type
size()
const {
return _internal.size(); }
405 size_type
max_size()
const {
return _internal.max_size(); }
414 size_type
capacity()
const {
return _internal.size() + _table->getBufferSize(); }
423 if (n <= _internal.size())
return;
424 _table->preallocate(n - _internal.size());
428 reference
operator[](size_type i)
const {
return *_internal[i]; }
431 reference
at(size_type i)
const {
return *_internal.at(i); }
434 reference
front()
const {
return *_internal.front(); }
437 reference
back()
const {
return *_internal.back(); }
450 template <
typename InputIterator>
451 void assign(InputIterator
first, InputIterator last,
bool deep =
false) {
453 insert(
end(), first, last, deep);
459 _internal.push_back(p);
468 _internal.push_back(r);
493 template <
typename InputIterator>
494 void insert(iterator pos, InputIterator
first, InputIterator last,
bool deep =
false) {
495 _maybeReserve(pos, first, last, deep,
498 while (first != last) {
499 pos = insert(pos, *first);
504 while (first != last) {
505 pos = insert(pos, first);
506 assert(pos !=
end());
514 template <
typename InputIterator>
518 "SchemaMapper's output schema does not match catalog's schema");
520 _maybeReserve(pos, first, last,
true,
522 while (first != last) {
523 pos = insert(pos, _table->copyRecord(*first, mapper));
530 iterator
insert(iterator pos, Record
const& r) {
532 return iterator(_internal.insert(pos.base(), p));
537 return iterator(_internal.insert(pos.base(), p));
541 iterator
erase(iterator pos) {
return iterator(_internal.erase(pos.base())); }
545 return iterator(_internal.erase(first.base(), last.base()));
550 _table.swap(other._table);
551 _internal.swap(other._internal);
558 template <
typename T>
559 bool isSorted(
Key<T> const& key)
const;
566 template <
typename Compare>
567 bool isSorted(Compare cmp)
const;
570 template <
typename T>
571 void sort(
Key<T> const& key);
578 template <
typename Compare>
579 void sort(Compare cmp);
596 template <
typename T>
599 template <
typename T>
617 template <
typename T>
620 template <
typename T>
623 template <
typename T>
626 template <
typename T>
629 template <
typename T>
632 template <
typename T>
655 template <
typename InputIterator>
656 void _maybeReserve(iterator& pos, InputIterator
first, InputIterator last,
bool deep,
658 if (deep) _table->preallocate(last - first);
661 template <
typename InputIterator>
662 void _maybeReserve(iterator pos, InputIterator first, InputIterator last,
bool deep,
671 template <
typename RecordT,
typename T>
673 bool operator()(RecordT
const&
a, RecordT
const&
b)
const {
return a.get(key) < b.get(key); }
678 template <
typename RecordT,
typename Adaptee>
681 return adaptee(*a, *b);
687 template <
typename RecordT,
typename T>
691 result_type
operator()(RecordT
const& r)
const {
return r.get(key); }
698 template <
typename RecordT>
699 template <
typename Compare>
703 if (empty())
return true;
704 const_iterator last = this->begin();
705 const_iterator i = last;
707 for (; i != this->
end(); ++i) {
708 if (f(i, last))
return false;
714 template <
typename RecordT>
715 template <
typename Compare>
721 template <
typename RecordT>
722 template <
typename T>
728 template <
typename RecordT>
729 template <
typename T>
735 template <
typename RecordT>
736 template <
typename T>
741 typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
744 if (i.base() ==
end() || *i != value)
return end();
748 template <
typename RecordT>
749 template <
typename T>
751 Key<T> const& key)
const {
754 typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
757 if (i.base() ==
end() || *i != value)
return end();
761 template <
typename RecordT>
762 template <
typename T>
767 typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
772 template <
typename RecordT>
773 template <
typename T>
778 typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
783 template <
typename RecordT>
784 template <
typename T>
789 typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
794 template <
typename RecordT>
795 template <
typename T>
800 typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
805 template <
typename RecordT>
806 template <
typename T>
811 typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, iterator> SearchIter;
817 template <
typename RecordT>
818 template <
typename T>
823 typedef boost::transform_iterator<detail::KeyExtractionFunctor<RecordT, T>, const_iterator> SearchIter;
851 template <
typename RecordT,
typename Catalog,
typename T>
853 typename Catalog::const_iterator iter = catalog.find(value, key);
854 if (iter == catalog.end()) {
860 template <
typename Catalog,
typename T>
862 return catalog.lower_bound(value, key) - catalog.begin();
865 template <
typename Catalog,
typename T>
867 return catalog.upper_bound(value, key) - catalog.begin();
870 template <
typename Catalog,
typename T>
873 catalog.equal_range(value, key);
882 #endif // !AFW_TABLE_Catalog_h_INCLUDED
CatalogT(CatalogT< OtherRecordT > const &other)
Shallow copy constructor from a container containing a related record type.
void push_back(std::shared_ptr< RecordT > const &p)
Add the given record to the end of the catalog without copying.
Defines the fields and offsets for a table.
std::shared_ptr< RecordT > _Catalog_find(Catalog const &catalog, T const &value, Key< T > const &key)
iterator insert(iterator pos, std::shared_ptr< RecordT > const &p)
Insert the given record at the given position without copying.
Internal::difference_type difference_type
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...
CatalogT & operator=(CatalogT const &other)
Shallow assigment.
CatalogIterator(CatalogIterator< OtherBaseT > const &other)
A custom container class for records, based on std::vector.
afw::table::Schema schema
A mapping between the keys of two Schemas, used to copy data between them.
bool isSorted(Key< T > const &key) const
Return true if the catalog is in ascending order according to the given key.
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Schema const getOutputSchema() const
Return the output schema (copy-on-write).
size_type max_size() const
Return the maximum number of elements allowed in a catalog.
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
static CatalogT readFits(fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU, int flags=0)
Read a FITS binary table from a RAM file.
Internal & getInternal()
Return a reference to the internal vector-of-shared_ptr.
reference back() const
Return the last record.
void pop_back()
Remove the last record in the catalog.
bool operator()(std::shared_ptr< RecordT > const &a, std::shared_ptr< RecordT > const &b) const
int _Catalog_lower_bound(Catalog const &catalog, T const &value, Key< T > const &key)
iterator lower_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
Schema getSchema() const
Return the schema associated with the catalog's table.
void insert(iterator pos, InputIterator first, InputIterator last, bool deep=false)
Insert an iterator range into the table.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
CatalogT(std::shared_ptr< Table > const &table, InputIterator first, InputIterator last, bool deep=false)
Construct a catalog from a table and an iterator range.
std::pair< int, int > _Catalog_equal_range(Catalog const &catalog, T const &value, Key< T > const &key)
CatalogIterator & operator=(std::shared_ptr< RecordT > const &other) const
Internal const & getInternal() const
Return a reference to the internal vector-of-shared_ptr.
static CatalogT readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU, int flags=0)
Read a FITS binary table from a regular file.
CatalogT(CatalogT const &other)
Shallow copy constructor.
const_iterator cend() const
Iterator access.
int _Catalog_upper_bound(Catalog const &catalog, T const &value, Key< T > const &key)
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.
void push_back(Record const &r)
Add a copy of the given record to the end of the catalog.
A base class for image defects.
void clear()
Remove all records from the catalog.
reference front() const
Return the first record.
Internal::size_type size_type
Lifetime-management for memory that goes into FITS memory files.
iterator end()
Iterator access.
CatalogT(Schema const &schema)
Construct a catalog from a schema, creating a table with Table::make(schema).
iterator erase(iterator pos)
Erase the record pointed to by pos, and return an iterator the next record.
Iterator class for CatalogT.
size_type capacity() const
Return the capacity of the catalog.
Record::ColumnView ColumnView
iterator erase(iterator first, iterator last)
Erase the records in the range [first, last).
CatalogIterator(BaseT const &base)
CatalogT(std::shared_ptr< Table > const &table=std::shared_ptr< Table >())
Construct a catalog from a table (or nothing).
bool empty() const
Return true if the catalog has no records.
void writeFits(fits::Fits &fitsfile, int flags=0) const
Write a FITS binary table to an open file object.
CatalogIterator< typename Internal::const_iterator > const_iterator
void swap(CatalogT &other)
Shallow swap of two catalogs.
void writeFits(std::string const &filename, std::string const &mode="w", int flags=0) const
Write a FITS binary table to a regular file.
const_iterator begin() const
Iterator access.
void reserve(size_type n)
Increase the capacity of the catalog to the given size.
iterator insert(iterator pos, Record const &r)
Insert a copy of the given record at the given position.
#define LSST_EXCEPT(type,...)
bool isContiguous() const
Return true if all records are contiguous.
void assign(InputIterator first, InputIterator last, bool deep=false)
Replace the contents of the table with an iterator range.
A class used as a handle to a particular field in a table.
T Value
the type returned by BaseRecord::get
const_iterator cbegin() const
Iterator access.
iterator find(typename Field< T >::Value const &value, Key< T > const &key)
Return an iterator to the record with the given value.
ColumnView getColumnView() const
Return a ColumnView of this catalog's records.
reference operator[](size_type i) const
Return the record at index i.
static void apply(OutputT &output, std::string const &mode, ContainerT const &container, int flags)
Driver for writing FITS files.
bool operator()(RecordT const &a, RecordT const &b) const
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.
size_type size() const
Return the number of elements in the catalog.
const_iterator end() const
Iterator access.
iterator begin()
Iterator access.
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).
static CatalogT readFits(fits::Fits &fitsfile, int flags=0)
Read a FITS binary table from a file object already at the correct extension.
iterator upper_bound(typename Field< T >::Value const &value, Key< T > const &key)
Performed binary searches on sorted fields.
CatalogT copy() const
Deep-copy the catalog using a cloned table.
void writeFits(fits::MemFileManager &manager, std::string const &mode="w", int flags=0) const
Write a FITS binary table to a RAM file.
Table of amplifier information (AmpInfoRecord records)
CatalogIterator< typename Internal::iterator > iterator
std::shared_ptr< RecordT > pointer
const int DEFAULT_HDU
Specify that the default HDU should be read.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
friend class boost::iterator_core_access