CMS 3D CMS Logo

KeyList.h
Go to the documentation of this file.
1 #ifndef CondCore_CondDB_KeyList_h
2 #define CondCore_CondDB_KeyList_h
3 
9 //
10 #include<map>
11 #include<memory>
12 #include<vector>
13 #include<string>
14 
15 /*
16  * KeyList represents a set of payloads each identified by a key and "valid" at given time
17  * Usually these payloads are configuration objects loaded in anvance
18  * The model used here calls for all payloads to be "stored" in a single IOVSequence each identified by a unique key
19  * (properly hashed to be mapped in 64bits)
20  *
21  * the keylist is just a vector of the hashes each corresponding to a key
22  * the correspondence position in the vector user-friendly name is kept in
23  * a list of all "names" that is defined in advance and kept in a dictionary at IOVSequence level
24 
25  *
26  */
27 
28 namespace cond {
29 
30  namespace persistency {
31 
32  class KeyList {
33  public:
34 
35  void init( IOVProxy iovProxy );
36 
37  void load( const std::vector<unsigned long long>& keys );
38 
39  template<typename T>
40  std::shared_ptr<T> get(size_t n) const {
41  if( n >= size() ) throwException( "Index outside the bounds of the key array.",
42  "KeyList::get");
43  if( !m_objects[n] ){
44  auto i = m_data.find( n );
45  if( i != m_data.end() ){
46  m_objects[n] = deserialize<T>( i->second.first, i->second.second.first, i->second.second.second );
47  m_data.erase( n );
48  } else {
49  throwException( "Payload for index "+boost::lexical_cast<std::string>(n)+" has not been found.",
50  "KeyList::get");
51  }
52  }
53  return std::static_pointer_cast<T>( m_objects[n] );
54  }
55 
56  size_t size() const { return m_objects.size();}
57 
58  private:
59  // the db session
61  // the key selection:
62  mutable std::map<size_t,std::pair<std::string,std::pair<cond::Binary,cond::Binary> > > m_data;
63  mutable std::vector<std::shared_ptr<void> > m_objects;
64 
65  };
66 
67  }
68 }
69 
70 #endif
size_t size() const
Definition: KeyList.h:56
std::vector< std::shared_ptr< void > > m_objects
Definition: KeyList.h:63
std::map< size_t, std::pair< std::string, std::pair< cond::Binary, cond::Binary > > > m_data
Definition: KeyList.h:62
Definition: plugin.cc:24
void init(IOVProxy iovProxy)
Definition: KeyList.cc:8
void load(const std::vector< unsigned long long > &keys)
Definition: KeyList.cc:14
long double T
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14