CMS 3D CMS Logo

KeyList.cc
Go to the documentation of this file.
3 
4 namespace cond {
5 
6  namespace persistency {
7 
8  void KeyList::init(IOVProxy iovProxy) {
9  m_proxy = iovProxy;
10  m_data.clear();
11  m_keys.clear();
12  }
13 
14  void KeyList::init(KeyList const& originalKeyList) { init(originalKeyList.m_proxy); }
15 
16  void KeyList::setKeys(const std::vector<unsigned long long>& keys) {
17  std::shared_ptr<SessionImpl> simpl = m_proxy.session();
18  if (!simpl.get())
19  cond::throwException("The KeyList has not been initialized.", "KeyList::setKeys");
20  Session s(simpl);
21  s.transaction().start(true);
22  m_keys = keys;
23  std::sort(m_keys.begin(), m_keys.end(), std::less<unsigned long long>());
24  m_data.clear();
25  m_data.resize(keys.size(), std::make_pair("", std::make_pair(cond::Binary(), cond::Binary())));
26  IOVArray keyIovs = m_proxy.selectAll();
27  for (size_t i = 0; i < m_keys.size(); ++i) {
28  if (m_keys[i] != 0) {
29  auto p = keyIovs.find(m_keys[i]);
30  if (p != keyIovs.end()) {
31  auto& item = m_data[i];
32  if (!s.fetchPayloadData((*p).payloadId, item.first, item.second.first, item.second.second))
33  cond::throwException("The Iov contains a broken payload reference.", "KeyList::setKeys");
34  }
35  }
36  }
37  s.transaction().commit();
38  }
39 
40  std::pair<std::string, std::pair<cond::Binary, cond::Binary> > KeyList::loadFromDB(unsigned long long key) const {
41  std::pair<std::string, std::pair<cond::Binary, cond::Binary> > item;
42  if (key == 0) {
43  return item;
44  }
45  std::shared_ptr<SessionImpl> simpl = m_proxy.session();
46  if (!simpl.get())
47  cond::throwException("The KeyList has not been initialized.", "KeyList::loadFromDB");
48  Session s(simpl);
49  s.transaction().start(true);
50  IOVArray keyIovs = m_proxy.selectAll();
51  auto p = keyIovs.find(key);
52  if (p != keyIovs.end()) {
53  if (!s.fetchPayloadData((*p).payloadId, item.first, item.second.first, item.second.second))
54  cond::throwException("The Iov contains a broken payload reference.", "KeyList::loadFromDB");
55  } else {
56  throwException("Payload for key " + std::to_string(key) + " has not been found.", "KeyList::loadFromDB");
57  }
58  s.transaction().commit();
59  return item;
60  }
61 
62  } // namespace persistency
63 } // namespace cond
std::vector< unsigned long long > m_keys
Definition: KeyList.h:70
Iterator end() const
Definition: IOVProxy.cc:99
std::string to_string(const V &value)
Definition: OMSAccess.h:77
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:18
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:404
Iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:101
std::vector< std::pair< std::string, std::pair< cond::Binary, cond::Binary > > > m_data
Definition: KeyList.h:71
void setKeys(const std::vector< unsigned long long > &keys)
determines which keys to use to read from the DB. Should only be used by PoolDBESSource ...
Definition: KeyList.cc:16
Definition: plugin.cc:23
std::pair< std::string, std::pair< cond::Binary, cond::Binary > > loadFromDB(unsigned long long key) const
Definition: KeyList.cc:40
void init(IOVProxy iovProxy)
Called by PoolDBESSource.
Definition: KeyList.cc:8
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12