LSST Applications g00d0e8bbd7+edbf708997,g199a45376c+5137f08352,g1fd858c14a+48cd4dd530,g228ff663f5+2051e4e242,g262e1987ae+9c6f24d2e3,g29ae962dfc+03663621e0,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3fd5ace14f+8c4d25a1ce,g47891489e3+27ba970c8a,g53246c7159+edbf708997,g5b326b94bb+db962c32ee,g64539dfbff+d237af7fd9,g67b6fd64d1+27ba970c8a,g74acd417e5+8234f56c0c,g786e29fd12+af89c03590,g87389fa792+a4172ec7da,g88cb488625+6878ed1c5e,g89139ef638+27ba970c8a,g8d7436a09f+f76ea57dde,g8ea07a8fe4+79658f16ab,g90f42f885a+6577634e1f,g97be763408+494f77a6c4,g98df359435+1750ea0126,g9b50b81019+d8f85438e7,ga2180abaac+edbf708997,ga9e74d7ce9+128cc68277,gad4c79568f+321c5e11c3,gbf99507273+edbf708997,gc2a301910b+d237af7fd9,gca7fc764a6+27ba970c8a,gcedae5159b+afaec0eb3d,gd7ef33dd92+27ba970c8a,gdab6d2f7ff+8234f56c0c,gdbb4c4dda9+d237af7fd9,ge410e46f29+27ba970c8a,ge41e95a9f2+d237af7fd9,geaed405ab2+062dfc8cdc,w.2025.45
LSST Data Management Base Package
Loading...
Searching...
No Matches
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 165 of file OutputArchive.cc.

165 : _map(), _index(ArchiveIndexSchema::get().schema) {
166 std::shared_ptr<daf::base::PropertyList> metadata(new daf::base::PropertyList());
167 metadata->set("EXTTYPE", "ARCHIVE_INDEX");
168 metadata->set("EXTNAME", "ARCHIVE_INDEX");
169 metadata->set("AR_CATN", 0, "# of this catalog relative to the start of this archive");
170 _index.getTable()->setMetadata(metadata);
171 }
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 }

◆ 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 }
@ 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
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 130 of file OutputArchive.cc.

130 {
131 if (!obj) return 0;
132 if (permissive && !obj->isPersistable()) return 0;
133 int const currentId = _nextId;
134 ++_nextId;
135 OutputArchiveHandle handle(currentId, obj->getPersistenceName(), obj->getPythonModule(), self);
136 obj->write(handle);
137 return currentId;
138 }

◆ 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 140 of file OutputArchive.cc.

140 {
141 if (!obj) return 0;
142 if (permissive && !obj->isPersistable()) return 0;
143 MapItem item(obj, _nextId);
144 std::pair<Map::iterator, bool> r = _map.insert(item);
145 if (r.second) {
146 // We've never seen this object before. Save it.
147 return put(obj.get(), self, permissive);
148 } else {
149 // We had already saved this object, and insert returned an iterator
150 // to the ID we used before; return that.
151 return r.first->second;
152 }
153 }
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 auto metadata = iter->getTable()->getMetadata();
93 // If EXTNAME exists we have already assigned an EXTVER.
94 // Otherwise must scan through all catalogs looking for other
95 // catalogs with the same name that have been assigned EXTNAME
96 // to determine this EXTVER.
97 auto found_extname = metadata->exists("EXTNAME");
98 if (!found_extname) {
99 int extver = 1;
100 // Catalogs can be filled out of order, so look for other
101 // catalogs with this EXTNAME.
102 CatalogVector::iterator ver_iter = _catalogs.begin();
103 for (; ver_iter != _catalogs.end(); ++ver_iter) {
104 auto cat_metadata = ver_iter->getTable()->getMetadata();
105 if (cat_metadata->exists("EXTNAME") && cat_metadata->getAsString("EXTNAME") == name) {
106 ++extver;
107 }
108 }
109 if (extver > 1) { // 1 is the default so no need to write it.
110 metadata->set("EXTVER", extver);
111 }
112 }
113 // Add the name of the class to the header so anyone looking at it can
114 // tell what's stored there. But we don't want to add it multiple times.
115 try {
116 auto names = metadata->getArray<std::string>("AR_NAME");
117 if (std::find(names.begin(), names.end(), name) == names.end()) {
118 iter->getTable()->getMetadata()->add("AR_NAME", name, "Class name for objects stored here");
119 }
120 } catch (pex::exceptions::NotFoundError &) {
121 metadata->add("AR_NAME", name, "Class name for objects stored here");
122 }
123 // Also add an EXTNAME. The most recent AR_NAME given will be used.
124 metadata->set("EXTNAME", name);
125 indexRecord->set(indexKeys.row0, iter->size());
126 indexRecord->set(indexKeys.catArchive, catArchive);
127 iter->insert(iter->end(), catalog.begin(), catalog.end(), false);
128 }
#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 155 of file OutputArchive.cc.

155 {
156 _index.getTable()->getMetadata()->set("AR_NCAT", int(_catalogs.size() + 1),
157 "# of catalogs in this archive, including the index");
158 _index.writeFits(fitsfile);
159 int n = 1;
160 for (CatalogVector::const_iterator iter = _catalogs.begin(); iter != _catalogs.end(); ++iter, ++n) {
161 iter->writeFits(fitsfile);
162 }
163 }

Member Data Documentation

◆ _catalogs

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

Definition at line 176 of file OutputArchive.cc.

◆ _index

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

Definition at line 175 of file OutputArchive.cc.

◆ _map

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

Definition at line 174 of file OutputArchive.cc.

◆ _nextId

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

Definition at line 173 of file OutputArchive.cc.

173{1};

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