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, IOVContainer::const_iterator end,
38  Iterator( const Iterator& rhs );
39 
40  //
41  Iterator& operator=( const Iterator& rhs );
42 
43  // returns a VALUE not a reference!
45 
46  //
48  Iterator operator++(int);
49 
50  //
51  bool operator==( const Iterator& rhs ) const;
52  bool operator!=( const Iterator& rhs ) const;
53 
54  private:
55  IOVContainer::const_iterator m_current;
56  IOVContainer::const_iterator m_end;
60  };
61 
62  public:
63  //
64  IOVProxy();
65 
66  // the only way to construct it from scratch...
67  explicit IOVProxy( const std::shared_ptr<SessionImpl>& session );
68 
69  //
70  IOVProxy( const IOVProxy& rhs );
71 
72  //
73  IOVProxy& operator=( const IOVProxy& rhs );
74 
75  // loads in memory the tag information and the iov groups
76  // full=true load the full iovSequence
77  void load( const std::string& tag, bool full=false );
78 
79  // loads in memory the tag information and the iov groups
80  void load( const std::string& tag, const boost::posix_time::ptime& snapshottime, bool full=false );
81 
82  // loads an IOV range in memory
83  void loadRange( const std::string& tag, const cond::Time_t& begin, const cond::Time_t& end );
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, const boost::posix_time::ptime& snapshottime );
87 
88  // reset the data in memory and execute again the queries for the current tag
89  void reload();
90 
91  // clear all the iov data in memory
92  void reset();
93 
94  std::string tag() const;
95 
96  cond::TimeType timeType() const;
97 
99 
101 
102  cond::Time_t endOfValidity() const;
103 
105 
106  std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const;
107 
108  // returns true if at least one IOV is in the sequence.
109  bool isEmpty() const;
110 
111  // 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.
112  // returns data only when a find or a load( tag, true ) have been at least called once.
113  Iterator begin() const;
114 
115  // the real end of the LOADED iov sequence subset.
116  Iterator end() const;
117 
118  // searches the DB for a valid iov containing the specified time.
119  // if the available iov sequence subset contains the target time, it does not issue a new query.
120  // otherwise, a new query will be executed using the resolved group boundaries.
122 
123  // searches the DB for a valid iov containing the specified time.
124  // if the available iov sequence subset contains the target time, it does not issue a new query.
125  // otherwise, a new query will be executed using the resolved group boundaries.
126  // throws if the target time cannot be found.
128 
129  // it does NOT use the cache, every time it performs a new query.
131 
132  // the size of the LOADED iov sequence subset. Matches the sequence size if a load( tag, true ) has been called.
133  int loadedSize() const;
134 
135  // the size of the entire iov sequence. Peforms a query at every call.
136  int sequenceSize() const;
137 
138  // for reporting
139  size_t numberOfQueries() const;
140 
141  // for debugging
142  std::pair<cond::Time_t,cond::Time_t> loadedGroup() const;
143 
144  // maybe will be removed with a re-design of the top level interface (ESSources )
145  const std::shared_ptr<SessionImpl>& session() const;
146 
147  private:
148  void checkTransaction( const std::string& ctx ) const ;
149  void fetchSequence( cond::Time_t lowerGroup, cond::Time_t higherGroup );
150 
151  private:
152  std::shared_ptr<IOVProxyData> m_data;
153  std::shared_ptr<SessionImpl> m_session;
154  };
155 
156  }
157 }
158 
159 #endif
160 
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:266
void checkTransaction(const std::string &ctx) const
Definition: IOVProxy.cc:261
cond::SynchronizationType synchronizationType() const
Definition: IOVProxy.cc:235
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:153
std::string tag() const
Definition: IOVProxy.cc:223
void load(const std::string &tag, bool full=false)
Definition: IOVProxy.cc:132
std::pair< cond::Time_t, cond::Time_t > loadedGroup() const
Definition: IOVProxy.cc:382
std::string payloadObjectType() const
Definition: IOVProxy.cc:231
bool operator!=(const Iterator &rhs) const
Definition: IOVProxy.cc:107
TimeType
Definition: Time.h:21
Iterator begin() const
Definition: IOVProxy.cc:289
Iterator & operator=(const Iterator &rhs)
Definition: IOVProxy.cc:60
std::tuple< std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const
Definition: IOVProxy.cc:247
cond::TimeType timeType() const
Definition: IOVProxy.cc:227
unsigned long long Time_t
Definition: Time.h:16
IOVContainer::const_iterator m_current
Definition: IOVProxy.h:55
std::vector< std::tuple< cond::Time_t, cond::Hash > > IOVContainer
Definition: IOVProxy.h:30
Definition: GenABIO.cc:168
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:320
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:349
IOVContainer::const_iterator m_end
Definition: IOVProxy.h:56
cond::Time_t endOfValidity() const
Definition: IOVProxy.cc:239
void loadRange(const std::string &tag, const cond::Time_t &begin, const cond::Time_t &end)
Definition: IOVProxy.cc:170
cond::Time_t lastValidatedTime() const
Definition: IOVProxy.cc:243
std::shared_ptr< IOVProxyData > m_data
Definition: IOVProxy.h:152
Definition: plugin.cc:24
SynchronizationType
Definition: Types.h:29
bool operator==(const Iterator &rhs) const
Definition: IOVProxy.cc:101
size_t numberOfQueries() const
Definition: IOVProxy.cc:378
Iterator end() const
Definition: IOVProxy.cc:297
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:386