3 #include "boost/format.hpp" 22 struct 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) %
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) %
72 int catArchive = indexIter->get(indexKeys.catArchive);
77 if (catN >= _catalogs.size()) {
81 "Invalid catalog number in index for ID %d; got '%d', max is '%d'") %
82 indexIter->get(indexKeys.id) % catN % _catalogs.size())
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) %
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.") %
122 return r.first->second;
128 if (indexIter->get(indexKeys.id) != id) {
129 id = indexIter->get(indexKeys.id);
139 if (index.
getSchema() != indexKeys.schema) {
143 _index.sort(IndexSortCompare());
148 Impl& operator=(
const Impl&) =
delete;
166 : _impl(new
Impl(index, catalogs)) {}
191 boost::format(
"Wrong value for archive index EXTTYPE: '%s'") %
194 int nCatalogs = metadata->
get<
int>(
"AR_NCAT");
197 for (
int n = 1; n < nCatalogs; ++n) {
200 metadata = catalogs.back().getTable()->popMetadata();
203 boost::format(
"Wrong value for archive data EXTTYPE: '%s'") %
206 if (metadata->
get<
int>(
"AR_CATN") != n) {
209 boost::format(
"Incorrect order for archive catalogs: AR_CATN=%d found at position %d") %
210 metadata->
get<
int>(
"AR_CATN") % n);
Schema for the index catalog that specifies where objects are stored in the data catalogs.
CatalogT< BaseRecord > BaseCatalog
afw::table::Schema schema
A base class for factory classes used to reconstruct objects from records.
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.
ItemVariant const * other
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
static PersistableFactory const & lookup(std::string const &name, std::string const &module="")
Return the factory that has been registered with the given name.
static CatalogT readFits(std::string const &filename, int hdu=fits::DEFAULT_HDU, int flags=0)
Read a FITS binary table from a regular file.
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.
An exception thrown when problems are found when reading or writing FITS files.
static constexpr int const NO_CATALOGS_SAVED
Special value used for catArchive, catPersistable, and row0 when an object with no state is saved...
A base class for image defects.
Iterator class for CatalogT.
void setHdu(int hdu, bool relative=false)
Set the current HDU.
#define LSST_EXCEPT(type,...)
A vector of catalogs used by Persistable.
static ArchiveIndexSchema const & get()
Return the singleton instance.
#define LSST_FITS_EXCEPT(type, fitsObj,...)
A FITS-related replacement for LSST_EXCEPT that takes an additional Fits object and uses makeErrorMes...
#define LSST_EXCEPT_ADD(e, m)