LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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)
T get(T... args)

◆ 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: