CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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.
78  Iterator find(cond::Time_t time) const;
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 
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  cond::Iov_t getInterval(cond::Time_t time, cond::Time_t defaultIovSize);
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
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:302
void checkTransaction(const std::string &ctx) const
Definition: IOVProxy.cc:295
cond::TagInfo_t iovSequenceInfo() const
Definition: IOVProxy.cc:267
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:165
IOVProxy & operator=(const IOVProxy &rhs)
Definition: IOVProxy.cc:133
Iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:101
std::unique_ptr< IOVContainer > m_array
Definition: IOVProxy.h:87
std::pair< cond::Time_t, cond::Time_t > loadedGroup() const
Definition: IOVProxy.cc:419
std::vector< std::tuple< cond::Time_t, cond::Hash > > IOVContainer
Definition: IOVProxy.h:25
Iterator begin() const
Definition: IOVProxy.cc:97
std::tuple< std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const
Definition: IOVProxy.cc:282
Iterator end() const
Definition: IOVProxy.cc:99
unsigned long long Time_t
Definition: Time.h:14
const cond::Tag_t & tagInfo() const
Definition: IOVProxy.cc:95
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:327
size_t size() const
Definition: IOVProxy.cc:103
std::shared_ptr< IOVProxyData > m_data
Definition: IOVProxy.h:164
void load(const std::string &tag)
Definition: IOVProxy.cc:139
IOVContainer::const_iterator m_current
Definition: IOVProxy.h:60
IOVArray selectRange(const cond::Time_t &begin, const cond::Time_t &end)
Definition: IOVProxy.cc:197
cond::Tag_t tagInfo() const
Definition: IOVProxy.cc:253
string end
Definition: dataset.py:937
bool operator==(const Iterator &rhs) const
Definition: IOVProxy.cc:73
size_t numberOfQueries() const
Definition: IOVProxy.cc:417
IOVArray & operator=(const IOVArray &rhs)
Definition: IOVProxy.cc:89
Iterator & operator=(const Iterator &rhs)
Definition: IOVProxy.cc:35
bool operator!=(const Iterator &rhs) const
Definition: IOVProxy.cc:81
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:424