7 #include "boost/format.hpp" 27 typedef Map::value_type MapItem;
40 if (iter->getSchema().compare(schema, flags) == flags) {
47 if (!iter->getTable()->getMetadata()) {
49 iter->getTable()->setMetadata(metadata);
50 metadata->set(
"EXTTYPE",
"ARCHIVE_DATA");
51 metadata->set(
"AR_CATN", catArchive,
"# of this catalog relative to the start of this archive");
58 indexRecord->set(indexKeys.id,
id);
59 indexRecord->set(indexKeys.name, name);
60 indexRecord->set(indexKeys.module, module);
66 indexRecord->set(indexKeys.nRows, 0);
75 indexRecord->set(indexKeys.catPersistable, catPersistable);
76 indexRecord->set(indexKeys.nRows, catalog.
size());
80 if (iter->getTable() == catalog.
getTable()) {
86 "All catalogs passed to saveCatalog must be created by makeCatalog");
91 auto names = iter->getTable()->getMetadata()->getArray<
std::string>(
"AR_NAME");
92 if (
std::find(names.begin(), names.end(),
name) == names.end()) {
93 iter->getTable()->getMetadata()->add(
"AR_NAME", name,
"Class name for objects stored here");
96 iter->getTable()->getMetadata()->add(
"AR_NAME", name,
"Class name for objects stored here");
98 indexRecord->set(indexKeys.row0, iter->size());
99 indexRecord->set(indexKeys.catArchive, catArchive);
114 assert(r.first->first == obj);
116 return r.first->second;
121 "# of catalogs in this archive, including the index");
125 iter->writeFits(fitsfile);
131 metadata->set(
"EXTTYPE",
"ARCHIVE_INDEX");
132 metadata->set(
"AR_CATN", 0,
"# of this catalog relative to the start of this archive");
160 if (!_impl.unique()) {
164 return _impl->put(obj, _impl, permissive);
170 if (n == 0)
return _impl->_index;
171 if (
std::size_t(n) > _impl->_catalogs.size() || n < 0) {
174 (boost::format(
"Catalog number %d is out of range [0,%d]") % n % _impl->_catalogs.size())
177 return _impl->_catalogs[n - 1];
191 _impl->saveCatalog(catalog,
_id,
_name, _module, _catPersistable);
198 return _impl->put(obj, _impl, permissive);
203 :
_id(
id), _catPersistable(0),
_name(name), _module(module), _impl(impl) {}
Defines the fields and offsets for a table.
int countCatalogs() const
Return the total number of catalogs, including the index.
void saveEmpty(int id, std::string const &name, std::string const &module)
Schema for the index catalog that specifies where objects are stored in the data catalogs.
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
Keys have the same types offsets, and sizes.
OutputArchive & operator=(OutputArchive const &other)
Assign from another OutputArchive. Saved objects are not deep-copied.
OutputArchive()
Construct an empty OutputArchive containing no objects.
OutputArchiveHandle(const OutputArchiveHandle &)=delete
CatalogT< BaseRecord > BaseCatalog
An object passed to Persistable::write to allow it to persist itself.
std::string const & _name
afw::table::Schema schema
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
void saveEmpty()
Indicate that the object being persisted has no state, and hence will never call makeCatalog() or sav...
ItemVariant const * other
A simple struct that combines the two arguments that must be passed to most cfitsio routines and cont...
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
BaseCatalog const & getIndexCatalog() const
Return the index catalog that specifies where objects are stored in the data catalogs.
A base class for objects that can be persisted via afw::table::io Archive classes.
A multi-catalog archive object used to save table::io::Persistable objects.
static constexpr int const NO_CATALOGS_SAVED
Special value used for catArchive, catPersistable, and row0 when an object with no state is saved...
void writeFits(fits::Fits &fitsfile) const
Write the archive to an already-open FITS object.
void saveCatalog(BaseCatalog const &catalog, int id, std::string const &name, std::string const &module, int catPersistable)
Fields have the same names (ordered).
A base class for image defects.
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
BaseCatalog makeCatalog(Schema const &schema)
iterator end()
Iterator access.
void writeFits(std::string const &filename, std::string const &mode="w", int flags=0) const
Write a FITS binary table to a regular file.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
#define LSST_EXCEPT(type,...)
A vector of catalogs used by Persistable.
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
int put(Persistable const *obj, std::shared_ptr< Impl > const &self, bool permissive)
void writeFits(fits::Fits &fitsfile)
std::shared_ptr< BaseRecord > addIndexRecord(int id, std::string const &name, std::string const &module)
size_type size() const
Return the number of elements in the catalog.
virtual bool isPersistable() const noexcept
Return true if this particular object can be persisted using afw::table::io.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
iterator begin()
Iterator access.
static ArchiveIndexSchema const & get()
Return the singleton instance.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
BaseCatalog const & getCatalog(int n) const
Return the nth catalog. Catalog 0 is always the index catalog.