CMS 3D CMS Logo

IOVProxy.h
Go to the documentation of this file.
1 #ifndef CondCore_CondDB_IOVProxy_h
2 #define CondCore_CondDB_IOVProxy_h
3 //
4 // Package: CondDB
5 // Class : IOVProxy
6 //
10 //
11 // Author: Giacomo Govi
12 // Created: Apr 2013
13 //
14 
17 //
18 #include <boost/date_time/posix_time/posix_time.hpp>
19 
20 namespace cond {
21 
22  namespace persistency {
23 
24  class SessionImpl;
25  class IOVProxyData;
26 
27  typedef std::vector<std::tuple<cond::Time_t, cond::Hash> > IOVContainer;
28 
29  class IOVArray {
30  public:
31  IOVArray();
32  IOVArray(const IOVArray& rhs);
33  IOVArray& operator=(const IOVArray& rhs);
34 
35  public:
36  // more or less compliant with typical iterator semantics...
37  class Iterator : public std::iterator<std::input_iterator_tag, cond::Iov_t> {
38  public:
39  //
40  Iterator();
41  Iterator(IOVContainer::const_iterator current, const IOVArray* parent);
42 
43  Iterator(const Iterator& rhs);
44 
45  //
46  Iterator& operator=(const Iterator& rhs);
47 
48  // returns a VALUE not a reference!
50 
51  //
53  Iterator operator++(int);
54 
55  //
56  bool operator==(const Iterator& rhs) const;
57  bool operator!=(const Iterator& rhs) const;
58 
59  private:
60  IOVContainer::const_iterator m_current;
62  };
63  friend class Iterator;
64 
65  public:
66  const cond::Tag_t& tagInfo() const;
67 
68  // start the iteration. it referes to the LOADED iov sequence subset, which consists in two consecutive groups - or the entire sequence if it has been requested.
69  // returns data only when a find or a load( tag, true ) have been at least called once.
70  Iterator begin() const;
71 
72  // the real end of the LOADED iov sequence subset.
73  Iterator end() const;
74 
75  // searches the array for a valid iov containing the specified time.
76  // if the available iov sequence subset contains the target time, it does not issue a new query.
77  // otherwise, a new query will be executed using the resolved group boundaries.
79 
80  size_t size() const;
81 
82  // returns true if at least one IOV is in the sequence.
83  bool isEmpty() const;
84 
85  private:
86  friend class IOVProxy;
87  std::unique_ptr<IOVContainer> m_array;
89  };
90 
91  // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
92  class IOVProxy {
93  public:
94  //
95  IOVProxy();
96 
97  // the only way to construct it from scratch...
98  explicit IOVProxy(const std::shared_ptr<SessionImpl>& session);
99 
100  //
101  IOVProxy(const IOVProxy& rhs);
102 
103  //
104  IOVProxy& operator=(const IOVProxy& rhs);
105 
107  IOVArray selectAll(const boost::posix_time::ptime& snapshottime);
108 
109  IOVArray selectRange(const cond::Time_t& begin, const cond::Time_t& end);
110  IOVArray selectRange(const cond::Time_t& begin,
111  const cond::Time_t& end,
112  const boost::posix_time::ptime& snapshottime);
113 
114  bool selectRange(const cond::Time_t& begin, const cond::Time_t& end, IOVContainer& destination);
115 
116  cond::Tag_t tagInfo() const;
117 
119 
120  // searches the DB for a valid iov containing the specified time.
121  // if the available iov sequence subset contains the target time, it does not issue a new query.
122  // otherwise, a new query will be executed using the resolved group boundaries.
123  // throws if the target time cannot be found.
126 
127  std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime> getMetadata() const;
128 
129  // loads in memory the tag information and the iov groups
130  // full=true load the full iovSequence
131  void load(const std::string& tag);
132 
133  // loads in memory the tag information and the iov groups
134  void load(const std::string& tag, const boost::posix_time::ptime& snapshottime);
135 
136  // clear all the iov data in memory
137  void reset();
138 
139  // it does NOT use the cache, every time it performs a new query.
141 
142  // the size of the LOADED iov sequence subset.
143  int loadedSize() const;
144 
145  // the size of the entire iov sequence. Peforms a query at every call.
146  int sequenceSize() const;
147 
148  // for reporting
149  size_t numberOfQueries() const;
150 
151  // for debugging
152  std::pair<cond::Time_t, cond::Time_t> loadedGroup() const;
153 
154  // maybe will be removed with a re-design of the top level interface (ESSources )
155  const std::shared_ptr<SessionImpl>& session() const;
156 
157  private:
158  void checkTransaction(const std::string& ctx) const;
159  void resetIOVCache();
160  void loadGroups();
161  void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup);
162 
163  private:
164  std::shared_ptr<IOVProxyData> m_data;
165  std::shared_ptr<SessionImpl> m_session;
166  };
167 
168  } // namespace persistency
169 } // namespace cond
170 
171 #endif
cond::persistency::IOVArray::begin
Iterator begin() const
Definition: IOVProxy.cc:91
cond::persistency::IOVProxy::getLast
cond::Iov_t getLast()
Definition: IOVProxy.cc:390
cond::persistency::IOVProxy::getMetadata
std::tuple< std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const
Definition: IOVProxy.cc:276
cond::persistency::IOVProxy::getInterval
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:321
cond::persistency::IOVArray::end
Iterator end() const
Definition: IOVProxy.cc:93
cond::persistency::IOVProxy::loadedSize
int loadedSize() const
Definition: IOVProxy.cc:401
cond::persistency::IOVProxy::selectRange
IOVArray selectRange(const cond::Time_t &begin, const cond::Time_t &end)
Definition: IOVProxy.cc:191
protons_cff.time
time
Definition: protons_cff.py:39
cond::persistency::IOVArray::m_array
std::unique_ptr< IOVContainer > m_array
Definition: IOVProxy.h:87
cond::persistency::IOVProxy::selectAll
IOVArray selectAll()
Definition: IOVProxy.cc:175
cond::persistency::IOVArray::operator=
IOVArray & operator=(const IOVArray &rhs)
Definition: IOVProxy.cc:83
cond::persistency::IOVProxy::load
void load(const std::string &tag)
Definition: IOVProxy.cc:133
cond::persistency::IOVArray::find
Iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:95
cond::persistency::IOVProxy::resetIOVCache
void resetIOVCache()
Definition: IOVProxy.cc:230
cond::persistency::IOVArray
Definition: IOVProxy.h:29
cond::persistency::IOVProxy::iovSequenceInfo
cond::TagInfo_t iovSequenceInfo() const
Definition: IOVProxy.cc:261
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
cond::persistency::IOVProxy::loadGroups
void loadGroups()
Definition: IOVProxy.cc:161
mps_fire.end
end
Definition: mps_fire.py:242
cond::persistency::IOVProxy::session
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:418
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
cond
Definition: plugin.cc:23
cond::persistency::IOVArray::Iterator::m_current
IOVContainer::const_iterator m_current
Definition: IOVProxy.h:60
Time.h
cond::persistency::IOVProxy::operator=
IOVProxy & operator=(const IOVProxy &rhs)
Definition: IOVProxy.cc:127
cond::persistency::IOVProxy::loadedGroup
std::pair< cond::Time_t, cond::Time_t > loadedGroup() const
Definition: IOVProxy.cc:413
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
cond::persistency::IOVArray::size
size_t size() const
Definition: IOVProxy.cc:97
cond::persistency::IOVProxy::m_data
std::shared_ptr< IOVProxyData > m_data
Definition: IOVProxy.h:164
cond::persistency::IOVProxy::numberOfQueries
size_t numberOfQueries() const
Definition: IOVProxy.cc:411
cond::Tag_t
Definition: Types.h:58
cond::persistency::IOVArray::Iterator::operator*
cond::Iov_t operator*()
Definition: IOVProxy.cc:43
cond::persistency::IOVProxy::IOVProxy
IOVProxy()
Definition: IOVProxy.cc:121
cond::persistency::IOVArray::Iterator::m_parent
const IOVArray * m_parent
Definition: IOVProxy.h:61
cond::persistency::IOVArray::Iterator
Definition: IOVProxy.h:37
cond::persistency::IOVProxy::sequenceSize
int sequenceSize() const
Definition: IOVProxy.cc:403
HLTMuonOfflineAnalyzer_cff.destination
destination
Definition: HLTMuonOfflineAnalyzer_cff.py:50
cond::persistency::IOVArray::IOVArray
IOVArray()
Definition: IOVProxy.cc:77
cond::persistency::IOVArray::Iterator::operator++
Iterator & operator++()
Definition: IOVProxy.cc:56
cond::persistency::IOVProxy::reset
void reset()
Definition: IOVProxy.cc:240
cond::persistency::IOVArray::isEmpty
bool isEmpty() const
Definition: IOVProxy.cc:100
cond::persistency::IOVProxy::checkTransaction
void checkTransaction(const std::string &ctx) const
Definition: IOVProxy.cc:289
cond::persistency::IOVArray::Iterator::operator=
Iterator & operator=(const Iterator &rhs)
Definition: IOVProxy.cc:35
cond::persistency::IOVProxy::fetchSequence
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:296
cond::Iov_t
Definition: Types.h:47
cond::persistency::IOVArray::tagInfo
const cond::Tag_t & tagInfo() const
Definition: IOVProxy.cc:89
cond::persistency::IOVProxyData
Definition: IOVProxy.cc:104
cond::persistency::IOVArray::m_tagInfo
cond::Tag_t m_tagInfo
Definition: IOVProxy.h:88
cond::persistency::IOVContainer
std::vector< std::tuple< cond::Time_t, cond::Hash > > IOVContainer
Definition: IOVProxy.h:25
cond::persistency::IOVArray::Iterator::operator==
bool operator==(const Iterator &rhs) const
Definition: IOVProxy.cc:67
Types.h
cond::TagInfo_t
Definition: Types.h:69
cond::persistency::IOVProxy::tagInfo
cond::Tag_t tagInfo() const
Definition: IOVProxy.cc:247
class-composition.parent
parent
Definition: class-composition.py:88
cond::persistency::IOVProxy::m_session
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:165
cond::persistency::IOVArray::Iterator::operator!=
bool operator!=(const Iterator &rhs) const
Definition: IOVProxy.cc:75
cond::persistency::IOVArray::Iterator::Iterator
Iterator()
Definition: IOVProxy.cc:28