LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
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.

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  }
table::Schema schema
Definition: python.h:134
std::shared_ptr< Table > getTable() const
Return the table associated with the catalog.
Definition: Catalog.h:115
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  }
table::Key< std::string > name
Definition: Amplifier.cc:116
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:490

◆ 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()) {
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:311
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.


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