LSST Applications 28.0.2,g0fba68d861+5b923b673a,g1fd858c14a+7a7b9dd5ed,g2c84ff76c0+5548bfee71,g30358e5240+f0e04ebe90,g35bb328faa+fcb1d3bbc8,g436fd98eb5+bdc6fcdd04,g4af146b050+742274f7cd,g4d2262a081+3efd3f8190,g4e0f332c67+cb09b8a5b6,g53246c7159+fcb1d3bbc8,g5a012ec0e7+477f9c599b,g5edb6fd927+826dfcb47f,g60b5630c4e+bdc6fcdd04,g67b6fd64d1+2218407a0c,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g7b71ed6315+fcb1d3bbc8,g87b7deb4dc+f9ac2ab1bd,g8852436030+ebf28f0d95,g89139ef638+2218407a0c,g9125e01d80+fcb1d3bbc8,g989de1cb63+2218407a0c,g9f33ca652e+42fb53f4c8,g9f7030ddb1+11b9b6f027,ga2b97cdc51+bdc6fcdd04,gab72ac2889+bdc6fcdd04,gabe3b4be73+1e0a283bba,gabf8522325+3210f02652,gb1101e3267+9c79701da9,gb58c049af0+f03b321e39,gb89ab40317+2218407a0c,gcf25f946ba+ebf28f0d95,gd6cbbdb0b4+e8f9c9c900,gd9a9a58781+fcb1d3bbc8,gde0f65d7ad+a08f294619,ge278dab8ac+3ef3db156b,ge410e46f29+2218407a0c,gf67bdafdda+2218407a0c
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: