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 {
38  public:
39  // C++17 compliant iterator definition
40  using iterator_category = std::input_iterator_tag;
42  using difference_type = void; // Not used
43  using pointer = void; // Not used
44  using reference = void; // Not used
45 
46  //
47  Iterator();
48  Iterator(IOVContainer::const_iterator current, const IOVArray* parent);
49 
50  Iterator(const Iterator& rhs);
51 
52  //
53  Iterator& operator=(const Iterator& rhs);
54 
55  // returns a VALUE not a reference!
57 
58  //
60  Iterator operator++(int);
61 
62  //
63  bool operator==(const Iterator& rhs) const;
64  bool operator!=(const Iterator& rhs) const;
65 
66  private:
67  IOVContainer::const_iterator m_current;
69  };
70  friend class Iterator;
71 
72  public:
73  const cond::Tag_t& tagInfo() const;
74 
75  // 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.
76  // returns data only when a find or a load( tag, true ) have been at least called once.
77  Iterator begin() const;
78 
79  // the real end of the LOADED iov sequence subset.
80  Iterator end() const;
81 
82  // searches the array for a valid iov containing the specified time.
83  // if the available iov sequence subset contains the target time, it does not issue a new query.
84  // otherwise, a new query will be executed using the resolved group boundaries.
86 
87  size_t size() const;
88 
89  // returns true if at least one IOV is in the sequence.
90  bool isEmpty() const;
91 
92  private:
93  friend class IOVProxy;
94  std::unique_ptr<IOVContainer> m_array;
96  };
97 
98  // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
99  class IOVProxy {
100  public:
101  //
102  IOVProxy();
103 
104  // the only way to construct it from scratch...
105  explicit IOVProxy(const std::shared_ptr<SessionImpl>& session);
106 
107  //
108  IOVProxy(const IOVProxy& rhs);
109 
110  //
111  IOVProxy& operator=(const IOVProxy& rhs);
112 
114  IOVArray selectAll(const boost::posix_time::ptime& snapshottime);
115 
116  IOVArray selectRange(const cond::Time_t& begin, const cond::Time_t& end);
117  IOVArray selectRange(const cond::Time_t& begin,
118  const cond::Time_t& end,
119  const boost::posix_time::ptime& snapshottime);
120 
121  bool selectRange(const cond::Time_t& begin, const cond::Time_t& end, IOVContainer& destination);
122 
123  cond::Tag_t tagInfo() const;
124 
126 
127  // searches the DB for a valid iov containing the specified time.
128  // if the available iov sequence subset contains the target time, it does not issue a new query.
129  // otherwise, a new query will be executed using the resolved group boundaries.
130  // throws if the target time cannot be found.
132 
133  std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime> getMetadata() const;
134 
135  // loads in memory the tag information and the iov groups
136  // full=true load the full iovSequence
137  void load(const std::string& tag);
138 
139  // loads in memory the tag information and the iov groups
140  void load(const std::string& tag, const boost::posix_time::ptime& snapshottime);
141 
142  // clear all the iov data in memory
143  void reset();
144 
145  // it does NOT use the cache, every time it performs a new query.
147 
148  // the size of the LOADED iov sequence subset.
149  int loadedSize() const;
150 
151  // the size of the entire iov sequence. Peforms a query at every call.
152  int sequenceSize() const;
153 
154  // for reporting
155  size_t numberOfQueries() const;
156 
157  // for debugging
158  std::pair<cond::Time_t, cond::Time_t> loadedGroup() const;
159 
160  // maybe will be removed with a re-design of the top level interface (ESSources )
161  const std::shared_ptr<SessionImpl>& session() const;
162 
163  private:
164  void checkTransaction(const std::string& ctx) const;
165  void resetIOVCache();
166  void loadGroups();
167  void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup);
168 
169  private:
170  std::shared_ptr<IOVProxyData> m_data;
171  std::shared_ptr<SessionImpl> m_session;
172  };
173 
174  } // namespace persistency
175 } // namespace cond
176 
177 #endif
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:295
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:171
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:94
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
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
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:170
void load(const std::string &tag)
Definition: IOVProxy.cc:139
IOVContainer::const_iterator m_current
Definition: IOVProxy.h:67
IOVArray selectRange(const cond::Time_t &begin, const cond::Time_t &end)
Definition: IOVProxy.cc:197
std::input_iterator_tag iterator_category
Definition: IOVProxy.h:40
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