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  // value semantics. to be used WITHIN the parent session transaction ( therefore the session should be kept alive ).
28  class IOVProxy {
29  public:
30  typedef std::vector<std::tuple<cond::Time_t, cond::Hash> > IOVContainer;
31  // more or less compliant with typical iterator semantics...
32  class Iterator : public std::iterator<std::input_iterator_tag, cond::Iov_t> {
33  public:
34  //
35  Iterator();
36  Iterator(IOVContainer::const_iterator current,
37  IOVContainer::const_iterator end,
39  cond::Time_t lastTill,
41  Iterator(const Iterator& rhs);
42 
43  //
44  Iterator& operator=(const Iterator& rhs);
45 
46  // returns a VALUE not a reference!
48 
49  //
51  Iterator operator++(int);
52 
53  //
54  bool operator==(const Iterator& rhs) const;
55  bool operator!=(const Iterator& rhs) const;
56 
57  private:
58  IOVContainer::const_iterator m_current;
59  IOVContainer::const_iterator m_end;
63  };
64 
65  public:
66  //
67  IOVProxy();
68 
69  // the only way to construct it from scratch...
70  explicit IOVProxy(const std::shared_ptr<SessionImpl>& session);
71 
72  //
73  IOVProxy(const IOVProxy& rhs);
74 
75  //
76  IOVProxy& operator=(const IOVProxy& rhs);
77 
78  // loads in memory the tag information and the iov groups
79  // full=true load the full iovSequence
80  void load(const std::string& tag, bool full = false);
81 
82  // loads in memory the tag information and the iov groups
83  void load(const std::string& tag, const boost::posix_time::ptime& snapshottime, bool full = false);
84 
85  // loads an IOV range in memory
86  void loadRange(const std::string& tag, const cond::Time_t& begin, const cond::Time_t& end);
87 
88  // loads an IOV range in memory
89  void loadRange(const std::string& tag,
90  const cond::Time_t& begin,
91  const cond::Time_t& end,
92  const boost::posix_time::ptime& snapshottime);
93 
94  // reset the data in memory and execute again the queries for the current tag
95  void reload();
96 
97  // clear all the iov data in memory
98  void reset();
99 
100  std::string tag() const;
101 
102  cond::TimeType timeType() const;
103 
105 
107 
108  cond::Time_t endOfValidity() const;
109 
111 
112  std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime> getMetadata() const;
113 
114  // returns true if at least one IOV is in the sequence.
115  bool isEmpty() const;
116 
117  // 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.
118  // returns data only when a find or a load( tag, true ) have been at least called once.
119  Iterator begin() const;
120 
121  // the real end of the LOADED iov sequence subset.
122  Iterator end() const;
123 
124  // searches the DB for a valid iov containing the specified time.
125  // if the available iov sequence subset contains the target time, it does not issue a new query.
126  // otherwise, a new query will be executed using the resolved group boundaries.
128 
129  // searches the DB for a valid iov containing the specified time.
130  // if the available iov sequence subset contains the target time, it does not issue a new query.
131  // otherwise, a new query will be executed using the resolved group boundaries.
132  // throws if the target time cannot be found.
134 
135  // it does NOT use the cache, every time it performs a new query.
137 
138  // the size of the LOADED iov sequence subset. Matches the sequence size if a load( tag, true ) has been called.
139  int loadedSize() const;
140 
141  // the size of the entire iov sequence. Peforms a query at every call.
142  int sequenceSize() const;
143 
144  // for reporting
145  size_t numberOfQueries() const;
146 
147  // for debugging
148  std::pair<cond::Time_t, cond::Time_t> loadedGroup() const;
149 
150  // maybe will be removed with a re-design of the top level interface (ESSources )
151  const std::shared_ptr<SessionImpl>& session() const;
152 
153  private:
154  void checkTransaction(const std::string& ctx) const;
155  void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup);
156 
157  private:
158  std::shared_ptr<IOVProxyData> m_data;
159  std::shared_ptr<SessionImpl> m_session;
160  };
161 
162  } // namespace persistency
163 } // namespace cond
164 
165 #endif
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:258
void checkTransaction(const std::string &ctx) const
Definition: IOVProxy.cc:251
cond::SynchronizationType synchronizationType() const
Definition: IOVProxy.cc:224
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:159
std::string tag() const
Definition: IOVProxy.cc:218
void load(const std::string &tag, bool full=false)
Definition: IOVProxy.cc:116
std::pair< cond::Time_t, cond::Time_t > loadedGroup() const
Definition: IOVProxy.cc:383
std::string payloadObjectType() const
Definition: IOVProxy.cc:222
bool operator!=(const Iterator &rhs) const
Definition: IOVProxy.cc:102
TimeType
Definition: Time.h:19
Iterator begin() const
Definition: IOVProxy.cc:282
Iterator & operator=(const Iterator &rhs)
Definition: IOVProxy.cc:53
std::tuple< std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const
Definition: IOVProxy.cc:234
cond::TimeType timeType() const
Definition: IOVProxy.cc:220
unsigned long long Time_t
Definition: Time.h:14
IOVContainer::const_iterator m_current
Definition: IOVProxy.h:58
Definition: GenABIO.cc:168
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:322
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:352
IOVContainer::const_iterator m_end
Definition: IOVProxy.h:59
cond::Time_t endOfValidity() const
Definition: IOVProxy.cc:228
void loadRange(const std::string &tag, const cond::Time_t &begin, const cond::Time_t &end)
Definition: IOVProxy.cc:159
cond::Time_t lastValidatedTime() const
Definition: IOVProxy.cc:230
std::shared_ptr< IOVProxyData > m_data
Definition: IOVProxy.h:158
Definition: plugin.cc:23
SynchronizationType
Definition: Types.h:27
bool operator==(const Iterator &rhs) const
Definition: IOVProxy.cc:94
std::vector< std::tuple< cond::Time_t, cond::Hash > > IOVContainer
Definition: IOVProxy.h:30
size_t numberOfQueries() const
Definition: IOVProxy.cc:381
Iterator end() const
Definition: IOVProxy.cc:293
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:388