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) %
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);
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) %
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) {
144 _index.sort(IndexSortCompare());
149 Impl& operator=(
const Impl&) =
delete;
167 : _impl(new
Impl(index, catalogs)) {}
192 boost::format(
"Wrong value for archive index EXTTYPE: '%s'") %
195 int nCatalogs = metadata->
get<
int>(
"AR_NCAT");
198 for (
int n = 1; n < nCatalogs; ++n) {
201 metadata = catalogs.back().getTable()->popMetadata();
204 boost::format(
"Wrong value for archive data EXTTYPE: '%s'") %
207 if (metadata->
get<
int>(
"AR_CATN") != n) {
210 boost::format(
"Incorrect order for archive catalogs: AR_CATN=%d found at position %d") %
211 metadata->
get<
int>(
"AR_CATN") % n);
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Schema for the index catalog that specifies where objects are stored in the data catalogs.
CatalogT< BaseRecord > BaseCatalog
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.
Provides consistent interface for LSST exceptions.
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.
Reports attempts to access elements using an invalid key.
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,...)
Create an exception with a given 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)
Add the current location and a message to an existing exception before rethrowing it...
Reports errors that are due to events beyond the control of the program.