3#include "boost/format.hpp"
22struct IndexSortCompare {
23 bool operator()(BaseRecord
const&
a, BaseRecord
const&
b)
const {
24 if (
a.get(indexKeys.id) <
b.get(indexKeys.id)) {
27 if (
a.get(indexKeys.id) ==
b.get(indexKeys.id)) {
28 return a.get(indexKeys.catPersistable) <
b.get(indexKeys.catPersistable);
42 if (
id == 0)
return empty;
52 indexIter !=
_index.
end() && indexIter->get(indexKeys.id) ==
id; ++indexIter) {
54 name = indexIter->get(indexKeys.name);
55 }
else if (
name != indexIter->get(indexKeys.name)) {
58 (boost::format(
"Inconsistent name in index for ID %d; got '%s', expected '%s'") %
59 indexIter->get(indexKeys.id) % indexIter->get(indexKeys.name) %
name)
63 module = indexIter->get(indexKeys.module);
64 }
else if (module != indexIter->get(indexKeys.module)) {
68 "Inconsistent module in index for ID %d; got '%s', expected '%s'") %
69 indexIter->get(indexKeys.id) % indexIter->get(indexKeys.module) % module)
72 int catArchive = indexIter->get(indexKeys.catArchive);
81 "Invalid catalog number in index for ID %d; got '%d', max is '%d'") %
87 std::size_t i2 = i1 + indexIter->get(indexKeys.nRows);
88 if (i2 > fullCatalog.
size()) {
90 (boost::format(
"Index and data catalogs do not agree for ID %d; "
91 "catalog %d has %d rows, not %d") %
92 indexIter->get(indexKeys.id) % indexIter->get(indexKeys.catArchive) %
93 fullCatalog.
size() % i2)
97 fullCatalog.
begin() + i2));
101 r.first->second = factory.
read(self, factoryArgs);
104 (boost::format(
"loading object with id=%d, name='%s'") %
id %
name).
str());
109 assert(r.first->second);
110 }
else if (!r.first->second) {
118 (boost::format(
"Not trying to reload object with id=%d; a previous attempt to "
119 "load it already failed.") %
123 return r.first->second;
129 if (indexIter->get(indexKeys.id) !=
id) {
130 id = indexIter->get(indexKeys.id);
140 if (index.
getSchema() != indexKeys.schema) {
167 : _impl(new
Impl(index, catalogs)) {}
189 boost::format(
"Wrong value for archive index EXTTYPE: '%s'") %
192 int nCatalogs = metadata->
get<
int>(
"AR_NCAT");
195 for (
int n = 1; n < nCatalogs; ++n) {
198 metadata = catalogs.back().getTable()->popMetadata();
201 boost::format(
"Wrong value for archive data EXTTYPE: '%s'") %
204 if (metadata->
get<
int>(
"AR_CATN") != n) {
207 boost::format(
"Incorrect order for archive catalogs: AR_CATN=%d found at position %d") %
208 metadata->
get<
int>(
"AR_CATN") % n);
table::Key< std::string > name
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
An exception thrown when problems are found when reading or writing FITS files.
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
void setHdu(int hdu, bool relative=false)
Set the current HDU.
Iterator class for CatalogT.
static CatalogT readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU, int flags=0)
Read a FITS binary table from a regular file.
size_type size() const
Return the number of elements in the catalog.
iterator find(typename Field< T >::Value const &value, Key< T > const &key)
Return an iterator to the record with the given value.
iterator begin()
Iterator access.
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Schema getSchema() const
Return the schema associated with the catalog's table.
A vector of catalogs used by Persistable.
A base class for factory classes used to reconstruct objects from records.
virtual std::shared_ptr< Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const =0
Construct a new object from the given InputArchive and vector of catalogs.
static PersistableFactory const & lookup(std::string const &name, std::string const &module="")
Return the factory that has been registered with the given name.
Provides consistent interface for LSST exceptions.
Reports attempts to access elements using an invalid key.
Reports errors that are due to events beyond the control of the program.
#define LSST_FITS_EXCEPT(type, fitsObj,...)
A FITS-related replacement for LSST_EXCEPT that takes an additional Fits object and uses makeErrorMes...
CatalogT< BaseRecord > BaseCatalog
Schema for the index catalog that specifies where objects are stored in the data catalogs.
static constexpr int const NO_CATALOGS_SAVED
Special value used for catArchive, catPersistable, and row0 when an object with no state is saved.
static ArchiveIndexSchema const & get()
Return the singleton instance.