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_IOVService_IOVProxy_h
2 #define CondCore_IOVService_IOVProxy_h
3 
5 
9 
10 //
11 #include <boost/shared_ptr.hpp>
12 #include <boost/iterator/transform_iterator.hpp>
13 #include <boost/iterator/counting_iterator.hpp>
14 
15 namespace cond {
16 
17  class IOVSequence;
18 
19  struct IOVProxyData {
20  explicit IOVProxyData( cond::DbSession& dbs ) :
21  dbSession(dbs),
22  data(),
23  token(""){
24  }
25 
27  const std::string & tok) :
28  dbSession(dbs),
29  data(),
30  token(tok){
31  refresh();
32  }
33 
35  }
36 
37  void refresh();
38  void refresh( cond::DbSession& dbs );
39 
40  std::pair<int,int> range( cond::Time_t since, cond::Time_t till );
41 
43  boost::shared_ptr<cond::IOVSequence> data;
45  };
46 
48  public:
50  m_since(cond::invalidTime),
51  m_till(cond::invalidTime),
52  m_token("") {}
53 
55  m_since(is),
56  m_till(it),
57  m_token(itoken) {}
58 
59  void set(cond::Time_t is, cond::Time_t it, std::string const& itoken) {
60  m_since=is;
61  m_till=it;
62  m_token=itoken;
63  }
64 
65  void set(IOVSequence const & v, int i);
66 
67  cond::Time_t since() const {
68  return m_since;
69  }
70 
71  cond::Time_t till() const {
72  return m_till;
73  }
74 
75  std::string const & token() const {
76  return m_token;
77  }
78 
79  private:
83  };
84 
85  class IterHelp {
86  public:
88  IterHelp() : lowBound(0),iov(0){}
91 
92  result_type const & operator()(int i) const {
93  if (iov) {
95  tmp.set(*iov,i);
96  cond::Time_t since = tmp.since();
97  if( since < lowBound ) since = lowBound;
98  elem.set( since, tmp.till(), tmp.token() );
99  }
100  return elem;
101  }
102 
103  private:
105  IOVSequence const * iov;
107  };
108 
109  typedef boost::transform_iterator<IterHelp,boost::counting_iterator<int> > iov_range_iterator;
110 
111  class IOVRange {
112  public:
113 
115 
116  public:
117  IOVRange();
118 
119  // selection = 0 for the full sample, +n for the head(n), -n for the tail(n)
120  IOVRange( const boost::shared_ptr<IOVProxyData>& iov, cond::Time_t since, cond::Time_t till, int selection=0 );
121  // selection = 0 for the full sample, +n for the head(n), -n for the tail(n)
122  IOVRange( const boost::shared_ptr<IOVProxyData>& iov, int selection );
123 
124  IOVRange( const IOVRange& rhs );
125 
126  IOVRange& operator=( const IOVRange& rhs );
127 
129  return boost::make_transform_iterator(boost::counting_iterator<int>(m_low),
131  }
132 
133  const_iterator end() const {
134  // returns: 0 if not inizialized (m_low=m_high=-1)
135  // m_high + 1 = m_low + size elsewhere (since size = m_high - m_low + 1)
136  int index = m_high + 1;
137  return boost::make_transform_iterator(boost::counting_iterator<int>(index),
139  }
140 
142 
143  IOVElementProxy front() const;
144 
145  IOVElementProxy back() const;
146 
147  size_t size() const;
148 
149  private:
150  boost::shared_ptr<IOVProxyData> m_iov;
151  int m_low;
152  int m_high;
154  };
155 
156  /* IOV as the user wants it
157  */
158  class IOVProxy {
159  public:
161 
162  public:
163  IOVProxy();
164 
165  ~IOVProxy();
166 
167  explicit IOVProxy(cond::DbSession& dbSession);
168 
169  IOVProxy(cond::DbSession& dbSession, const std::string & token );
170 
171  IOVProxy( boost::shared_ptr<IOVProxyData>& data );
172 
173  IOVProxy( const IOVProxy& rhs );
174 
175  IOVProxy& operator=( const IOVProxy& rhs );
176 
177  void load( const std::string & token );
178 
179  bool refresh();
180  bool refresh( cond::DbSession& newSession );
181 
182  const std::string& token();
183 
184  bool isValid( cond::Time_t currenttime );
185 
186  std::pair<cond::Time_t, cond::Time_t> validity( cond::Time_t currenttime );
187 
189  return boost::make_transform_iterator(boost::counting_iterator<int>(0),
190  IterHelp(*m_iov));
191  }
192 
193  const_iterator end() const {
194  int index = size();
195  return boost::make_transform_iterator(boost::counting_iterator<int>(index),
196  IterHelp(*m_iov));
197  }
198 
199  // find
201 
202  // limit to the first n
203  IOVRange head(int n) const;
204 
205  // limit to the last n
206  IOVRange tail(int n) const;
207 
208  IOVRange range(cond::Time_t since, cond::Time_t till) const;
209 
210  IOVRange rangeHead(cond::Time_t since, cond::Time_t till, int n) const;
211 
212  IOVRange rangeTail(cond::Time_t since, cond::Time_t till, int n) const;
213 
214  int size() const;
215 
216  IOVSequence const & iov() const;
217 
218  TimeType timetype() const;
219 
220  cond::Time_t firstSince() const;
221 
222  cond::Time_t lastTill() const;
223 
224  std::set<std::string> const& payloadClasses() const;
225 
226  std::string comment() const;
227 
228  int revision() const;
229 
230  cond::Time_t timestamp() const;
231 
233  return SequenceState(iov());
234  }
235 
236  DbSession& db() const;
237 
238  private:
239  boost::shared_ptr<IOVProxyData> m_iov;
240 
241  };
242 }
243 
244 #endif // CondCore_IOVService_IOVProxy_h
IOVElementProxy(cond::Time_t is, cond::Time_t it, std::string const &itoken)
Definition: IOVProxy.h:54
const_iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:144
int i
Definition: DBlmapReader.cc:9
cond::Time_t firstSince() const
Definition: IOVProxy.cc:284
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > iov_range_iterator
Definition: IOVProxy.h:109
IOVRange rangeTail(cond::Time_t since, cond::Time_t till, int n) const
Definition: IOVProxy.cc:250
cond::Time_t m_since
Definition: IOVProxy.h:80
std::string comment() const
Definition: IOVProxy.cc:298
cond::Time_t timestamp() const
Definition: IOVProxy.cc:307
DbSession & db() const
Definition: IOVProxy.cc:311
selection
main part
Definition: corrVsCorr.py:98
std::pair< cond::Time_t, cond::Time_t > validity(cond::Time_t currenttime)
Definition: IOVProxy.cc:223
TimeType timetype() const
Definition: IOVProxy.cc:280
const_iterator begin() const
Definition: IOVProxy.h:128
IOVRange range(cond::Time_t since, cond::Time_t till) const
Definition: IOVProxy.cc:239
const_iterator begin() const
Definition: IOVProxy.h:188
IOVProxyData(cond::DbSession &dbs)
Definition: IOVProxy.h:20
cond::Time_t till() const
Definition: IOVProxy.h:71
const_iterator end() const
Definition: IOVProxy.h:193
boost::shared_ptr< IOVProxyData > m_iov
Definition: IOVProxy.h:150
TimeType
Definition: Time.h:21
cond::Time_t m_till
Definition: IOVProxy.h:81
IOVElementProxy elem
Definition: IOVProxy.h:106
IOVElementProxy front() const
Definition: IOVProxy.cc:152
cond::Time_t lowBound
Definition: IOVProxy.h:104
IOVProxyData(cond::DbSession &dbs, const std::string &tok)
Definition: IOVProxy.h:26
const_iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:264
unsigned long long Time_t
Definition: Time.h:16
tuple iov
Definition: o2o.py:307
void set(cond::Time_t is, cond::Time_t it, std::string const &itoken)
Definition: IOVProxy.h:59
std::string const & token() const
Definition: IOVProxy.h:75
IOVElementProxy result_type
Definition: IOVProxy.h:87
IOVRange rangeHead(cond::Time_t since, cond::Time_t till, int n) const
Definition: IOVProxy.cc:244
std::string m_token
Definition: IOVProxy.h:82
const Time_t invalidTime(0)
IOVSequence const & iov() const
Definition: IOVProxy.cc:276
cond::Time_t m_lowBound
Definition: IOVProxy.h:153
int revision() const
Definition: IOVProxy.cc:303
IOVProxy & operator=(const IOVProxy &rhs)
Definition: IOVProxy.cc:192
const std::string & token()
Definition: IOVProxy.cc:214
std::pair< int, int > range(cond::Time_t since, cond::Time_t till)
Definition: IOVProxy.cc:20
const_iterator end() const
Definition: IOVProxy.h:133
int size() const
Definition: IOVProxy.cc:272
bool refresh()
Definition: IOVProxy.cc:202
iov_range_iterator const_iterator
Definition: IOVProxy.h:114
cond::Time_t lastTill() const
Definition: IOVProxy.cc:288
size_t size() const
Definition: IOVProxy.cc:162
cond::Time_t since() const
Definition: IOVProxy.h:67
IOVSequence const * iov
Definition: IOVProxy.h:105
boost::shared_ptr< IOVProxyData > m_iov
Definition: IOVProxy.h:239
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::set< std::string > const & payloadClasses() const
Definition: IOVProxy.cc:293
boost::shared_ptr< cond::IOVSequence > data
Definition: IOVProxy.h:43
SequenceState state() const
Definition: IOVProxy.h:232
IOVRange head(int n) const
Definition: IOVProxy.cc:256
result_type const & operator()(int i) const
Definition: IOVProxy.h:92
std::string token
Definition: IOVProxy.h:44
iov_range_iterator const_iterator
Definition: IOVProxy.h:160
bool isValid(cond::Time_t currenttime)
Definition: IOVProxy.cc:218
IOVElementProxy back() const
Definition: IOVProxy.cc:157
IOVRange tail(int n) const
Definition: IOVProxy.cc:260
IOVRange & operator=(const IOVRange &rhs)
Definition: IOVProxy.cc:136
cond::DbSession dbSession
Definition: IOVProxy.h:42
void load(const std::string &token)
Definition: IOVProxy.cc:197