test
CMS 3D CMS Logo

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