CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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  // 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  // reset the data in memory and execute again the queries for the current tag
83  void reload();
84 
85  // clear all the iov data in memory
86  void reset();
87 
88  std::string tag() const;
89 
90  cond::TimeType timeType() const;
91 
93 
95 
97 
99 
100  std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const;
101 
102  // returns true if at least one IOV is in the sequence.
103  bool isEmpty() const;
104 
105  // 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.
106  // returns data only when a find or a load( tag, true ) have been at least called once.
107  Iterator begin() const;
108 
109  // the real end of the LOADED iov sequence subset.
110  Iterator end() const;
111 
112  // searches the DB for a valid iov containing the specified time.
113  // if the available iov sequence subset contains the target time, it does not issue a new query.
114  // otherwise, a new query will be executed using the resolved group boundaries.
116 
117  // searches the DB for a valid iov containing the specified time.
118  // if the available iov sequence subset contains the target time, it does not issue a new query.
119  // otherwise, a new query will be executed using the resolved group boundaries.
120  // throws if the target time cannot be found.
122 
123  // it does NOT use the cache, every time it performs a new query.
125 
126  // the size of the LOADED iov sequence subset. Matches the sequence size if a load( tag, true ) has been called.
127  int loadedSize() const;
128 
129  // the size of the entire iov sequence. Peforms a query at every call.
130  int sequenceSize() const;
131 
132  // for reporting
133  size_t numberOfQueries() const;
134 
135  // for debugging
136  std::pair<cond::Time_t,cond::Time_t> loadedGroup() const;
137 
138  // maybe will be removed with a re-design of the top level interface (ESSources )
139  const std::shared_ptr<SessionImpl>& session() const;
140 
141  private:
142  void checkTransaction( const std::string& ctx ) const ;
143  void fetchSequence( cond::Time_t lowerGroup, cond::Time_t higherGroup );
144 
145  private:
146  std::shared_ptr<IOVProxyData> m_data;
147  std::shared_ptr<SessionImpl> m_session;
148  };
149 
150  }
151 }
152 
153 #endif
154 
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:230
void checkTransaction(const std::string &ctx) const
Definition: IOVProxy.cc:225
cond::SynchronizationType synchronizationType() const
Definition: IOVProxy.cc:199
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:147
std::string tag() const
Definition: IOVProxy.cc:187
IOVProxy & operator=(const IOVProxy &rhs)
Definition: IOVProxy.cc:124
void load(const std::string &tag, bool full=false)
Definition: IOVProxy.cc:130
std::pair< cond::Time_t, cond::Time_t > loadedGroup() const
Definition: IOVProxy.cc:357
std::string payloadObjectType() const
Definition: IOVProxy.cc:195
bool operator!=(const Iterator &rhs) const
Definition: IOVProxy.cc:105
TimeType
Definition: Time.h:21
Iterator begin() const
Definition: IOVProxy.cc:257
Iterator & operator=(const Iterator &rhs)
Definition: IOVProxy.cc:58
std::tuple< std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const
Definition: IOVProxy.cc:211
cond::TimeType timeType() const
Definition: IOVProxy.cc:191
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:180
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:288
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:317
IOVContainer::const_iterator m_end
Definition: IOVProxy.h:56
cond::Time_t endOfValidity() const
Definition: IOVProxy.cc:203
cond::Time_t lastValidatedTime() const
Definition: IOVProxy.cc:207
std::shared_ptr< IOVProxyData > m_data
Definition: IOVProxy.h:146
SynchronizationType
Definition: Types.h:31
bool operator==(const Iterator &rhs) const
Definition: IOVProxy.cc:99
size_t numberOfQueries() const
Definition: IOVProxy.cc:353
Iterator end() const
Definition: IOVProxy.cc:265
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:361