LSST Applications g0265f82a02+0e5473021a,g02d81e74bb+0dd8ce4237,g1470d8bcf6+3ea6592b6f,g2079a07aa2+86d27d4dc4,g2305ad1205+5ca4c0b359,g295015adf3+d10818ec9d,g2a9a014e59+6f9be1b9cd,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g3ddfee87b4+703ba97ebf,g487adcacf7+4fa16da234,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+ffa42b374e,g5a732f18d5+53520f316c,g64a986408d+0dd8ce4237,g858d7b2824+0dd8ce4237,g8a8a8dda67+585e252eca,g99cad8db69+d39438377f,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,ga8c6da7877+f1d96605c8,gb0e22166c9+60f28cb32d,gb6a65358fc+0e5473021a,gba4ed39666+c2a2e4ac27,gbb8dafda3b+e5339d463f,gc120e1dc64+da31e9920e,gc28159a63d+0e5473021a,gcf0d15dbbd+703ba97ebf,gdaeeff99f8+f9a426f77a,ge6526c86ff+889fc9d533,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gf18bd8381d+7268b93478,gff1a9f87cc+0dd8ce4237,w.2024.16
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
lsst::afw::table::io::OutputArchive::Impl Class Reference

Public Member Functions

BaseCatalog makeCatalog (Schema const &schema)
 
std::shared_ptr< BaseRecordaddIndexRecord (int id, std::string const &name, std::string const &module)
 
void saveEmpty (int id, std::string const &name, std::string const &module)
 
void saveCatalog (BaseCatalog const &catalog, int id, std::string const &name, std::string const &module, int catPersistable)
 
int put (Persistable const *obj, std::shared_ptr< Impl > const &self, bool permissive)
 
int put (std::shared_ptr< Persistable const > obj, std::shared_ptr< Impl > const &self, bool permissive)
 
void writeFits (fits::Fits &fitsfile)
 
 Impl ()
 

Public Attributes

int _nextId {1}
 
Map _map
 
BaseCatalog _index
 
CatalogVector _catalogs
 

Detailed Description

Definition at line 37 of file OutputArchive.cc.

Constructor & Destructor Documentation

◆ Impl()

lsst::afw::table::io::OutputArchive::Impl::Impl ( )
inline

Definition at line 144 of file OutputArchive.cc.

144 : _map(), _index(ArchiveIndexSchema::get().schema) {
145 std::shared_ptr<daf::base::PropertyList> metadata(new daf::base::PropertyList());
146 metadata->set("EXTTYPE", "ARCHIVE_INDEX");
147 metadata->set("EXTNAME", "ARCHIVE_INDEX");
148 metadata->set("AR_CATN", 0, "# of this catalog relative to the start of this archive");
149 _index.getTable()->setMetadata(metadata);
150 }
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition Catalog.h:114
static ArchiveIndexSchema const & get()
Return the singleton instance.

Member Function Documentation

◆ addIndexRecord()

std::shared_ptr< BaseRecord > lsst::afw::table::io::OutputArchive::Impl::addIndexRecord ( int id,
std::string const & name,
std::string const & module )
inline

Definition at line 60 of file OutputArchive.cc.

60 {
61 auto indexRecord = _index.addNew();
62 indexRecord->set(indexKeys.id, id);
63 indexRecord->set(indexKeys.name, name);
64 indexRecord->set(indexKeys.module, module);
65 return indexRecord;
66 }
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition Catalog.h:489

◆ makeCatalog()

BaseCatalog lsst::afw::table::io::OutputArchive::Impl::makeCatalog ( Schema const & schema)
inline

Definition at line 39 of file OutputArchive.cc.

39 {
40 int catArchive = 1;
41 CatalogVector::iterator iter = _catalogs.begin();
43 for (; iter != _catalogs.end(); ++iter, ++catArchive) {
44 if (iter->getSchema().compare(schema, flags) == flags) {
45 break;
46 }
47 }
48 if (iter == _catalogs.end()) {
49 iter = _catalogs.insert(_catalogs.end(), BaseCatalog(schema));
50 }
51 if (!iter->getTable()->getMetadata()) {
52 std::shared_ptr<daf::base::PropertyList> metadata(new daf::base::PropertyList());
53 iter->getTable()->setMetadata(metadata);
54 metadata->set("EXTTYPE", "ARCHIVE_DATA");
55 metadata->set("AR_CATN", catArchive, "# of this catalog relative to the start of this archive");
56 }
57 return BaseCatalog(iter->getTable());
58 }
T begin(T... args)
@ EQUAL_NAMES
Fields have the same names (ordered).
Definition Schema.h:67
@ EQUAL_KEYS
Keys have the same types offsets, and sizes.
Definition Schema.h:66
T end(T... args)
T insert(T... args)
CatalogT< BaseRecord > BaseCatalog
Definition fwd.h:72

◆ put() [1/2]

int lsst::afw::table::io::OutputArchive::Impl::put ( Persistable const * obj,
std::shared_ptr< Impl > const & self,
bool permissive )
inline

Definition at line 109 of file OutputArchive.cc.

109 {
110 if (!obj) return 0;
111 if (permissive && !obj->isPersistable()) return 0;
112 int const currentId = _nextId;
113 ++_nextId;
114 OutputArchiveHandle handle(currentId, obj->getPersistenceName(), obj->getPythonModule(), self);
115 obj->write(handle);
116 return currentId;
117 }

◆ put() [2/2]

int lsst::afw::table::io::OutputArchive::Impl::put ( std::shared_ptr< Persistable const > obj,
std::shared_ptr< Impl > const & self,
bool permissive )
inline

Definition at line 119 of file OutputArchive.cc.

119 {
120 if (!obj) return 0;
121 if (permissive && !obj->isPersistable()) return 0;
122 MapItem item(obj, _nextId);
123 std::pair<Map::iterator, bool> r = _map.insert(item);
124 if (r.second) {
125 // We've never seen this object before. Save it.
126 return put(obj.get(), self, permissive);
127 } else {
128 // We had already saved this object, and insert returned an iterator
129 // to the ID we used before; return that.
130 return r.first->second;
131 }
132 }
int put(Persistable const *obj, std::shared_ptr< Impl > const &self, bool permissive)

◆ saveCatalog()

void lsst::afw::table::io::OutputArchive::Impl::saveCatalog ( BaseCatalog const & catalog,
int id,
std::string const & name,
std::string const & module,
int catPersistable )
inline

Definition at line 76 of file OutputArchive.cc.

77 {
78 auto indexRecord = addIndexRecord(id, name, module);
79 indexRecord->set(indexKeys.catPersistable, catPersistable);
80 indexRecord->set(indexKeys.nRows, catalog.size());
81 int catArchive = 1;
82 CatalogVector::iterator iter = _catalogs.begin();
83 for (; iter != _catalogs.end(); ++iter, ++catArchive) {
84 if (iter->getTable() == catalog.getTable()) {
85 break;
86 }
87 }
88 if (iter == _catalogs.end()) {
89 throw LSST_EXCEPT(pex::exceptions::LogicError,
90 "All catalogs passed to saveCatalog must be created by makeCatalog");
91 }
92 // Add the name of the class to the header so anyone looking at it can
93 // tell what's stored there. But we don't want to add it multiple times.
94 try {
95 auto names = iter->getTable()->getMetadata()->getArray<std::string>("AR_NAME");
96 if (std::find(names.begin(), names.end(), name) == names.end()) {
97 iter->getTable()->getMetadata()->add("AR_NAME", name, "Class name for objects stored here");
98 }
99 } catch (pex::exceptions::NotFoundError &) {
100 iter->getTable()->getMetadata()->add("AR_NAME", name, "Class name for objects stored here");
101 }
102 // Also add an EXTNAME. The most recent AR_NAME given will be used.
103 iter->getTable()->getMetadata()->set("EXTNAME", name);
104 indexRecord->set(indexKeys.row0, iter->size());
105 indexRecord->set(indexKeys.catArchive, catArchive);
106 iter->insert(iter->end(), catalog.begin(), catalog.end(), false);
107 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
std::shared_ptr< BaseRecord > addIndexRecord(int id, std::string const &name, std::string const &module)
T find(T... args)

◆ saveEmpty()

void lsst::afw::table::io::OutputArchive::Impl::saveEmpty ( int id,
std::string const & name,
std::string const & module )
inline

Definition at line 68 of file OutputArchive.cc.

68 {
69 auto indexRecord = addIndexRecord(id, name, module);
70 indexRecord->set(indexKeys.nRows, 0);
71 indexRecord->set(indexKeys.catPersistable, ArchiveIndexSchema::NO_CATALOGS_SAVED);
72 indexRecord->set(indexKeys.row0, ArchiveIndexSchema::NO_CATALOGS_SAVED);
73 indexRecord->set(indexKeys.catArchive, ArchiveIndexSchema::NO_CATALOGS_SAVED);
74 }
static constexpr int const NO_CATALOGS_SAVED
Special value used for catArchive, catPersistable, and row0 when an object with no state is saved.

◆ writeFits()

void lsst::afw::table::io::OutputArchive::Impl::writeFits ( fits::Fits & fitsfile)
inline

Definition at line 134 of file OutputArchive.cc.

134 {
135 _index.getTable()->getMetadata()->set("AR_NCAT", int(_catalogs.size() + 1),
136 "# of catalogs in this archive, including the index");
137 _index.writeFits(fitsfile);
138 int n = 1;
139 for (CatalogVector::const_iterator iter = _catalogs.begin(); iter != _catalogs.end(); ++iter, ++n) {
140 iter->writeFits(fitsfile);
141 }
142 }
void writeFits(std::string const &filename, std::string const &mode="w", int flags=0) const
Write a FITS binary table to a regular file.
Definition Catalog.h:310
T size(T... args)

Member Data Documentation

◆ _catalogs

CatalogVector lsst::afw::table::io::OutputArchive::Impl::_catalogs

Definition at line 155 of file OutputArchive.cc.

◆ _index

BaseCatalog lsst::afw::table::io::OutputArchive::Impl::_index

Definition at line 154 of file OutputArchive.cc.

◆ _map

Map lsst::afw::table::io::OutputArchive::Impl::_map

Definition at line 153 of file OutputArchive.cc.

◆ _nextId

int lsst::afw::table::io::OutputArchive::Impl::_nextId {1}

Definition at line 152 of file OutputArchive.cc.

152{1};

The documentation for this class was generated from the following file: