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