CMS 3D CMS Logo

KeyList.h
Go to the documentation of this file.
1 
2 #ifndef CondCore_CondDB_KeyList_h
3 #define CondCore_CondDB_KeyList_h
4 
10 //
11 #include <map>
12 #include <memory>
13 #include <vector>
14 #include <string>
15 
16 /*
17  * KeyList represents a set of payloads each identified by a key and "valid" at given time
18  * Usually these payloads are configuration objects loaded in anvance
19  * The model used here calls for all payloads to be "stored" in a single IOVSequence each identified by a unique key
20  * (properly hashed to be mapped in 64bits)
21  *
22  * the keylist is just a vector of the hashes each corresponding to a key
23  * the correspondence position in the vector user-friendly name is kept in
24  * a list of all "names" that is defined in advance and kept in a dictionary at IOVSequence level
25 
26  *
27  */
28 
29 namespace cond {
30 
31  namespace persistency {
32 
33  class KeyList {
34  public:
36  void init(IOVProxy iovProxy);
37  void init(KeyList const&);
38 
40  void setKeys(const std::vector<unsigned long long>& keys);
41 
43  template <typename T>
44  std::shared_ptr<T> getUsingIndex(size_t n) const {
45  if (n >= size())
46  throwException("Index outside the bounds of the key array.", "KeyList::getUsingIndex");
47  if (m_keys[n] == 0 or m_data[n].first.empty()) {
48  throwException("Payload for index " + std::to_string(n) + " has not been found.", "KeyList::getUsingIndex");
49  }
50  auto const& i = m_data[n];
51  return deserialize<T>(i.first, i.second.first, i.second.second);
52  }
53 
56  template <typename T>
57  std::shared_ptr<T> getUsingKey(unsigned long long key) const {
58  auto item = loadFromDB(key);
59  return deserialize<T>(item.first, item.second.first, item.second.second);
60  }
61 
63  size_t size() const { return m_data.size(); }
64 
65  private:
66  std::pair<std::string, std::pair<cond::Binary, cond::Binary>> loadFromDB(unsigned long long key) const;
67  // the db session, protected by a mutex
68  mutable IOVProxy m_proxy;
69  // the key selection:
70  std::vector<unsigned long long> m_keys;
71  std::vector<std::pair<std::string, std::pair<cond::Binary, cond::Binary>>> m_data;
72  };
73 
74  } // namespace persistency
75 } // namespace cond
76 
77 #endif
std::vector< unsigned long long > m_keys
Definition: KeyList.h:70
std::string to_string(const V &value)
Definition: OMSAccess.h:77
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
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
size_t size() const
Number of keys based on container passed to setKeys.
Definition: KeyList.h:63
std::shared_ptr< T > getUsingIndex(size_t n) const
Retrieves the pre-fetched data. The index is the same order as the keys used in setKeys.
Definition: KeyList.h:44
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
std::shared_ptr< T > getUsingKey(unsigned long long key) const
Definition: KeyList.h:57