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;
59  };
60 
61  public:
62  //
63  IOVProxy();
64 
65  // the only way to construct it from scratch...
66  explicit IOVProxy( const std::shared_ptr<SessionImpl>& session );
67 
68  //
69  IOVProxy( const IOVProxy& rhs );
70 
71  //
72  IOVProxy& operator=( const IOVProxy& rhs );
73 
74  // loads in memory the tag information and the iov groups
75  // full=true load the full iovSequence
76  void load( const std::string& tag, bool full=false );
77 
78  // reset the data in memory and execute again the queries for the current tag
79  void reload();
80 
81  // clear all the iov data in memory
82  void reset();
83 
84  std::string tag() const;
85 
86  cond::TimeType timeType() const;
87 
89 
91 
93 
94  // returns true if at least one IOV is in the sequence.
95  bool isEmpty() const;
96 
97  // 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.
98  // returns data only when a find or a load( tag, true ) have been at least called once.
99  Iterator begin() const;
100 
101  // the real end of the LOADED iov sequence subset.
102  Iterator end() const;
103 
104  // searches the DB for a valid iov containing the specified time.
105  // if the available iov sequence subset contains the target time, it does not issue a new query.
106  // otherwise, a new query will be executed using the resolved group boundaries.
108 
109  // searches the DB for a valid iov containing the specified time.
110  // if the available iov sequence subset contains the target time, it does not issue a new query.
111  // otherwise, a new query will be executed using the resolved group boundaries.
112  // throws if the target time cannot be found.
114 
115  // it does NOT use the cache, every time it performs a new query.
117 
118  // the size of the LOADED iov sequence subset. Matches the sequence size if a load( tag, true ) has been called.
119  int loadedSize() const;
120 
121  // the size of the entire iov sequence. Peforms a query at every call.
122  int sequenceSize() const;
123 
124  // for reporting
125  size_t numberOfQueries() const;
126 
127  // for debugging
128  std::pair<cond::Time_t,cond::Time_t> loadedGroup() const;
129 
130  // maybe will be removed with a re-design of the top level interface (ESSources )
131  const std::shared_ptr<SessionImpl>& session() const;
132 
133  private:
134  void checkTransaction( const std::string& ctx ) const ;
135  void fetchSequence( cond::Time_t lowerGroup, cond::Time_t higherGroup );
136 
137  private:
138  std::shared_ptr<IOVProxyData> m_data;
139  std::shared_ptr<SessionImpl> m_session;
140  };
141 
142  }
143 }
144 
145 #endif
146 
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:190
void checkTransaction(const std::string &ctx) const
Definition: IOVProxy.cc:185
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:139
std::string tag() const
Definition: IOVProxy.cc:161
IOVProxy & operator=(const IOVProxy &rhs)
Definition: IOVProxy.cc:117
void load(const std::string &tag, bool full=false)
Definition: IOVProxy.cc:123
std::pair< cond::Time_t, cond::Time_t > loadedGroup() const
Definition: IOVProxy.cc:301
std::string payloadObjectType() const
Definition: IOVProxy.cc:169
bool operator!=(const Iterator &rhs) const
Definition: IOVProxy.cc:98
TimeType
Definition: Time.h:21
Iterator begin() const
Definition: IOVProxy.cc:200
Iterator & operator=(const Iterator &rhs)
Definition: IOVProxy.cc:53
cond::TimeType timeType() const
Definition: IOVProxy.cc:165
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:193
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:230
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:269
IOVContainer::const_iterator m_end
Definition: IOVProxy.h:56
cond::Time_t endOfValidity() const
Definition: IOVProxy.cc:173
cond::Time_t lastValidatedTime() const
Definition: IOVProxy.cc:177
std::shared_ptr< IOVProxyData > m_data
Definition: IOVProxy.h:138
bool operator==(const Iterator &rhs) const
Definition: IOVProxy.cc:92
size_t numberOfQueries() const
Definition: IOVProxy.cc:297
Iterator end() const
Definition: IOVProxy.cc:208
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:305