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.
125 
126  std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime> getMetadata() const;
127 
128  // loads in memory the tag information and the iov groups
129  // full=true load the full iovSequence
130  void load(const std::string& tag);
131 
132  // loads in memory the tag information and the iov groups
133  void load(const std::string& tag, const boost::posix_time::ptime& snapshottime);
134 
135  // clear all the iov data in memory
136  void reset();
137 
138  // it does NOT use the cache, every time it performs a new query.
140 
141  // the size of the LOADED iov sequence subset.
142  int loadedSize() const;
143 
144  // the size of the entire iov sequence. Peforms a query at every call.
145  int sequenceSize() const;
146 
147  // for reporting
148  size_t numberOfQueries() const;
149 
150  // for debugging
151  std::pair<cond::Time_t, cond::Time_t> loadedGroup() const;
152 
153  // maybe will be removed with a re-design of the top level interface (ESSources )
154  const std::shared_ptr<SessionImpl>& session() const;
155 
156  private:
157  void checkTransaction(const std::string& ctx) const;
158  void resetIOVCache();
159  void loadGroups();
160  void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup);
161 
162  private:
163  std::shared_ptr<IOVProxyData> m_data;
164  std::shared_ptr<SessionImpl> m_session;
165  };
166 
167  } // namespace persistency
168 } // namespace cond
169 
170 #endif
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:295
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:164
std::tuple< std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const
Definition: IOVProxy.cc:275
IOVProxy & operator=(const IOVProxy &rhs)
Definition: IOVProxy.cc:133
std::pair< cond::Time_t, cond::Time_t > loadedGroup() const
Definition: IOVProxy.cc:399
cond::TagInfo_t iovSequenceInfo() const
Definition: IOVProxy.cc:260
size_t numberOfQueries() const
Definition: IOVProxy.cc:397
Iterator begin() const
Definition: IOVProxy.cc:97
std::unique_ptr< IOVContainer > m_array
Definition: IOVProxy.h:87
Iterator end() const
Definition: IOVProxy.cc:99
std::vector< std::tuple< cond::Time_t, cond::Hash > > IOVContainer
Definition: IOVProxy.h:25
bool operator==(const Iterator &rhs) const
Definition: IOVProxy.cc:73
unsigned long long Time_t
Definition: Time.h:14
const cond::Tag_t & tagInfo() const
Definition: IOVProxy.cc:95
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:404
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:320
Iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:101
void checkTransaction(const std::string &ctx) const
Definition: IOVProxy.cc:288
cond::Tag_t tagInfo() const
Definition: IOVProxy.cc:246
std::shared_ptr< IOVProxyData > m_data
Definition: IOVProxy.h:163
void load(const std::string &tag)
Definition: IOVProxy.cc:139
IOVContainer::const_iterator m_current
Definition: IOVProxy.h:60
Definition: plugin.cc:23
IOVArray selectRange(const cond::Time_t &begin, const cond::Time_t &end)
Definition: IOVProxy.cc:197
bool operator!=(const Iterator &rhs) const
Definition: IOVProxy.cc:81
IOVArray & operator=(const IOVArray &rhs)
Definition: IOVProxy.cc:89
Iterator & operator=(const Iterator &rhs)
Definition: IOVProxy.cc:35