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::InputArchive::Impl Class Reference

Public Member Functions

std::shared_ptr< Persistableget (int id, InputArchive const &self)
 
Map const & getAll (InputArchive const &self)
 
 Impl ()
 
 Impl (BaseCatalog const &index, CatalogVector const &catalogs)
 
 Impl (const Impl &)=delete
 
Imploperator= (const Impl &)=delete
 
 Impl (Impl &&)=delete
 
Imploperator= (Impl &&)=delete
 

Public Attributes

Map _map
 
BaseCatalog _index
 
CatalogVector _catalogs
 

Detailed Description

Definition at line 38 of file InputArchive.cc.

Constructor & Destructor Documentation

◆ Impl() [1/4]

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

Definition at line 137 of file InputArchive.cc.

table::Schema schema
Definition: python.h:134
static ArchiveIndexSchema const & get()
Return the singleton instance.

◆ Impl() [2/4]

lsst::afw::table::io::InputArchive::Impl::Impl ( BaseCatalog const &  index,
CatalogVector const &  catalogs 
)
inline

Definition at line 139 of file InputArchive.cc.

139  : _index(index), _catalogs(catalogs) {
140  if (index.getSchema() != indexKeys.schema) {
141  throw LSST_EXCEPT(pex::exceptions::RuntimeError, "Incorrect schema for index catalog");
142  }
144  _index.sort(IndexSortCompare());
145  }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
void sort(Key< T > const &key)
Sort the catalog in-place by the field with the given key.
Definition: Catalog.h:756
T insert(T... args)
T make_pair(T... args)

◆ Impl() [3/4]

lsst::afw::table::io::InputArchive::Impl::Impl ( const Impl )
delete

◆ Impl() [4/4]

lsst::afw::table::io::InputArchive::Impl::Impl ( Impl &&  )
delete

Member Function Documentation

◆ get()

std::shared_ptr<Persistable> lsst::afw::table::io::InputArchive::Impl::get ( int  id,
InputArchive const &  self 
)
inline

Definition at line 40 of file InputArchive.cc.

40  {
42  if (id == 0) return empty;
44  if (r.second) {
45  // insertion successful means we haven't reassembled this object yet; do that now.
46  CatalogVector factoryArgs;
47  // iterate over records in index with this ID; we know they're sorted by ID and then
48  // by catPersistable, so we can just append to factoryArgs.
51  for (BaseCatalog::iterator indexIter = _index.find(id, indexKeys.id);
52  indexIter != _index.end() && indexIter->get(indexKeys.id) == id; ++indexIter) {
53  if (name.empty()) {
54  name = indexIter->get(indexKeys.name);
55  } else if (name != indexIter->get(indexKeys.name)) {
56  throw LSST_EXCEPT(
57  MalformedArchiveError,
58  (boost::format("Inconsistent name in index for ID %d; got '%s', expected '%s'") %
59  indexIter->get(indexKeys.id) % indexIter->get(indexKeys.name) % name)
60  .str());
61  }
62  if (module.empty()) {
63  module = indexIter->get(indexKeys.module);
64  } else if (module != indexIter->get(indexKeys.module)) {
65  throw LSST_EXCEPT(
66  MalformedArchiveError,
68  "Inconsistent module in index for ID %d; got '%s', expected '%s'") %
69  indexIter->get(indexKeys.id) % indexIter->get(indexKeys.module) % module)
70  .str());
71  }
72  int catArchive = indexIter->get(indexKeys.catArchive);
73  if (catArchive == ArchiveIndexSchema::NO_CATALOGS_SAVED) {
74  break; // object was written with saveEmpty, and hence no catalogs.
75  }
76  std::size_t catN = catArchive - 1;
77  if (catN >= _catalogs.size()) {
78  throw LSST_EXCEPT(
79  MalformedArchiveError,
81  "Invalid catalog number in index for ID %d; got '%d', max is '%d'") %
82  indexIter->get(indexKeys.id) % catN % _catalogs.size())
83  .str());
84  }
85  BaseCatalog& fullCatalog = _catalogs[catN];
86  std::size_t i1 = indexIter->get(indexKeys.row0);
87  std::size_t i2 = i1 + indexIter->get(indexKeys.nRows);
88  if (i2 > fullCatalog.size()) {
89  throw LSST_EXCEPT(MalformedArchiveError,
90  (boost::format("Index and data catalogs do not agree for ID %d; "
91  "catalog %d has %d rows, not %d") %
92  indexIter->get(indexKeys.id) % indexIter->get(indexKeys.catArchive) %
93  fullCatalog.size() % i2)
94  .str());
95  }
96  factoryArgs.push_back(BaseCatalog(fullCatalog.getTable(), fullCatalog.begin() + i1,
97  fullCatalog.begin() + i2));
98  }
99  try {
100  PersistableFactory const& factory = PersistableFactory::lookup(name, module);
101  r.first->second = factory.read(self, factoryArgs);
102  } catch (pex::exceptions::Exception& err) {
103  LSST_EXCEPT_ADD(err,
104  (boost::format("loading object with id=%d, name='%s'") % id % name).str());
105  throw;
106  }
107  // If we're loading the object for the first time, and we've failed, we should have already
108  // thrown an exception, and we assert that here.
109  assert(r.first->second);
110  } else if (!r.first->second) {
111  // If we'd already tried and failed to load this object before - but we'd caught the exception
112  // previously (because the calling code didn't consider that to be a fatal error) - we'll
113  // just throw an exception again. While we can't know exactly what was thrown before,
114  // it's most likely it was a NotFoundError because a needed extension package was not setup.
115  // And conveniently it's appropriate to throw that here too, since now the problem is that
116  // the object should have been loaded into the cache and it wasn't found there.
117  throw LSST_EXCEPT(pex::exceptions::NotFoundError,
118  (boost::format("Not trying to reload object with id=%d; a previous attempt to "
119  "load it already failed.") %
120  id)
121  .str());
122  }
123  return r.first->second;
124  }
table::Key< std::string > name
Definition: Amplifier.cc:116
#define LSST_EXCEPT_ADD(e, m)
Add the current location and a message to an existing exception before rethrowing it.
Definition: Exception.h:54
iterator find(typename Field< T >::Value const &value, Key< T > const &key)
Return an iterator to the record with the given value.
Definition: Catalog.h:763
CatalogIterator< typename Internal::iterator > iterator
Definition: Catalog.h:111
static PersistableFactory const & lookup(std::string const &name, std::string const &module="")
Return the factory that has been registered with the given name.
Definition: Persistable.cc:76
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:72
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
T size(T... args)
static constexpr int const NO_CATALOGS_SAVED
Special value used for catArchive, catPersistable, and row0 when an object with no state is saved.

◆ getAll()

Map const& lsst::afw::table::io::InputArchive::Impl::getAll ( InputArchive const &  self)
inline

Definition at line 126 of file InputArchive.cc.

126  {
127  int id = 0;
128  for (BaseCatalog::iterator indexIter = _index.begin(); indexIter != _index.end(); ++indexIter) {
129  if (indexIter->get(indexKeys.id) != id) {
130  id = indexIter->get(indexKeys.id);
131  get(id, self);
132  }
133  }
134  return _map;
135  }
iterator begin()
Iterator access.
Definition: Catalog.h:401
std::shared_ptr< Persistable > get(int id, InputArchive const &self)
Definition: InputArchive.cc:40

◆ operator=() [1/2]

Impl& lsst::afw::table::io::InputArchive::Impl::operator= ( const Impl )
delete

◆ operator=() [2/2]

Impl& lsst::afw::table::io::InputArchive::Impl::operator= ( Impl &&  )
delete

Member Data Documentation

◆ _catalogs

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

Definition at line 157 of file InputArchive.cc.

◆ _index

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

Definition at line 156 of file InputArchive.cc.

◆ _map

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

Definition at line 155 of file InputArchive.cc.


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