CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IOVProxy.cc
Go to the documentation of this file.
4 
5 #include <iostream>
7  if( token.empty() ) return;
9  // loading the lazy-loading Queryable vector...
10  data->loadAll();
11  //**** temporary for the schema transition
12  if( dbSession.isOldSchema() ){
14  data->swapTokens( parser );
15  }
16 }
17 
19  dbSession = newSession;
20  refresh();
21 }
22 
23 std::pair<int,int> cond::IOVProxyData::range( cond::Time_t since,
24  cond::Time_t till ){
25  int low = -1;
26  int high = -1;
27  if( data->iovs().size() ){
28  cond::Time_t firstSince = data->iovs().front().sinceTime();
29  if( till >= firstSince ){
30  low = (since < firstSince) ? 0 :
31  data->find(since)-data->iovs().begin();
32  high = data->find(till) - data->iovs().begin();
33  high = std::min( high+1,(int)data->iovs().size())-1;
34  }
35  }
36  return std::make_pair( low, high );
37 }
38 
40  if (ii>=(int)v.iovs().size() || ii<0) {
42  return;
43  }
44  size_t i =ii;
45  m_token = v.iovs()[i].token();
46  m_since = v.iovs()[i].sinceTime();
47  if(i+1==v.iovs().size()) {
48  m_till = v.lastTill();
49  return;
50  }
51  cond::UnpackedTime unpackedTime;
52  cond::Time_t totalNanoseconds;
53  cond::Time_t totalSecondsInNanoseconds;
54  switch (v.timeType()) {
55  case timestamp:
56  //unpacking
57  unpackedTime = cond::time::unpack(v.iovs()[i+1].sinceTime());
58  //number of seconds in nanoseconds (avoid multiply and divide by 1e09)
59  totalSecondsInNanoseconds = ((cond::Time_t)unpackedTime.first)*1000000000;
60  //total number of nanoseconds
61  totalNanoseconds = totalSecondsInNanoseconds + ((cond::Time_t)(unpackedTime.second));
62  //now decrementing of 1 nanosecond
63  totalNanoseconds--;
64  //now repacking (just change the value of the previous pair)
65  unpackedTime.first = (unsigned int) (totalNanoseconds/1000000000);
66  unpackedTime.second = (unsigned int)(totalNanoseconds - (cond::Time_t)unpackedTime.first*1000000000);
67  m_till = cond::time::pack(unpackedTime);
68  break;
69  default:
70  m_till = v.iovs()[i+1].sinceTime()-1;
71  }
72 }
73 
75  lowBound(0),
76  iov(&(*impl.data)),
77  elem(){
78 }
80  lowBound(lb),
81  iov(&(*impl.data)),
82  elem(){
83 }
84 
86  m_iov(),
87  m_low(-1),
88  m_high(-1),
89  m_lowBound(0){
90 }
91 
92 cond::IOVRange::IOVRange( const boost::shared_ptr<IOVProxyData>& iov,
93  cond::Time_t since,
94  cond::Time_t till,
95  int selection ):
96  m_iov( iov ),
97  m_low( -1 ),
98  m_high( -1 ),
99  m_lowBound(0){
100  std::pair<int,int> rg = m_iov->range( since, till );
101  m_low = rg.first;
102  m_high = rg.second;
103  if( selection > 0 ){
104  m_low = rg.first;
105  m_high = std::min( rg.first-selection-1, rg.second );
106  } else if( selection < 0 ){
107  m_low = std::max( rg.second-selection+1,rg.first);
108  m_high = rg.second;
109  }
110  cond::Time_t tlow = m_iov->data->iovs()[m_low].sinceTime();
111  if( since < tlow ) since = tlow;
112  m_lowBound = since;
113 }
114 
115 cond::IOVRange::IOVRange( const boost::shared_ptr<IOVProxyData>& iov,
116  int selection ):
117  m_iov(iov),
118  m_low(-1),
119  m_high(-1),
120  m_lowBound(0){
121  int sz = iov->data->iovs().size();
122  m_low = 0;
123  m_high = sz-1;
124  if( selection > 0 ){
125  m_high = std::min( selection, sz-1 );
126  } else if( selection < 0 ){
127  m_low = sz+selection;
128  if(m_low < 0) m_low = 0;
129  }
130 }
131 
133  m_iov( rhs.m_iov ),
134  m_low( rhs.m_low ),
135  m_high( rhs.m_high ),
136  m_lowBound( rhs.m_lowBound){
137 }
138 
140  m_iov = rhs.m_iov;
141  m_low = rhs.m_low;
142  m_high = rhs.m_high;
143  m_lowBound = rhs.m_lowBound;
144  return *this;
145 }
146 
148  int n = m_iov->data->find(time)-m_iov->data->iovs().begin();
149  return (n<m_low || m_high<n ) ?
150  end() :
151  boost::make_transform_iterator(boost::counting_iterator<int>(n),
152  IterHelp(*m_iov, m_lowBound));
153 }
154 
156  IterHelp helper(*m_iov, m_lowBound);
157  return helper( m_low );
158 }
159 
161  IterHelp helper(*m_iov, m_lowBound);
162  return helper( m_high );
163 }
164 
165 size_t cond::IOVRange::size() const {
166  size_t sz = 0;
167  if( m_high>=0 && m_low>=0 ) sz = m_high-m_low+1;
168  return sz;
169 }
170 
172  m_iov(){
173 }
174 
176 }
177 
179  m_iov(new IOVProxyData(dbSession)){
180 }
181 
183  const std::string & token):
184  m_iov(new IOVProxyData(dbSession,token)){
185 }
186 
187 cond::IOVProxy::IOVProxy( const boost::shared_ptr<IOVProxyData>& data ):
188  m_iov( data ){
189 }
190 
192  m_iov( rhs.m_iov ){
193 }
194 
196  m_iov = rhs.m_iov;
197  return *this;
198 }
199 
200 void cond::IOVProxy::load( const std::string & token){
201  m_iov->token = token;
202  m_iov->refresh();
203 }
204 
206  int oldsize = size();
207  m_iov->refresh();
208  return oldsize<size();
209 }
210 
212  int oldsize = size();
213  m_iov->refresh( newSession );
214  return oldsize<size();
215 }
216 
218  return m_iov->token;
219 }
220 
222  return ( currenttime >= iov().firstSince() &&
223  currenttime <= iov().lastTill() );
224 }
225 
226 std::pair<cond::Time_t, cond::Time_t> cond::IOVProxy::validity( cond::Time_t currenttime ){
227  cond::Time_t since = iov().lastTill();
228  cond::Time_t till = iov().lastTill();
229  IOVSequence::const_iterator iter=iov().find(currenttime);
230  if (iter!=iov().iovs().end()) {
231  since=iter->sinceTime();
232  iter++;
233  if (iter!=iov().iovs().end())
234  till = iter->sinceTime()-1;
235  }
236  return std::pair<cond::Time_t, cond::Time_t>(since,till);
237 }
238 
240  cond::Time_t till) const {
241  return IOVRange( m_iov, since, till );
242 }
243 
245  cond::Time_t till,
246  int n) const {
247  return IOVRange( m_iov, since, till, n );
248 }
249 
251  cond::Time_t till,
252  int n) const {
253  return IOVRange( m_iov, since, till, -n );
254 }
255 
257  return IOVRange( m_iov, n );
258 }
259 
261  return IOVRange( m_iov, -n );
262 }
263 
265  int n = iov().find(time)-iov().iovs().begin();
266  return ( n<0 || n>size() ) ?
267  end() :
268  boost::make_transform_iterator(boost::counting_iterator<int>(n),
269  IterHelp(*m_iov));
270 }
271 
272 int cond::IOVProxy::size() const {
273  return iov().iovs().size();
274 }
275 
277  if( !m_iov->data.get() ) throwException( "No data found.", "IOVProxy::iov" );
278  return *(m_iov->data);
279 }
280 
282  return iov().timeType();
283 }
284 
286  return iov().firstSince();
287 }
288 
290  return iov().lastTill();
291 }
292 
293 std::set<std::string> const&
295  return iov().payloadClasses();
296 }
297 
300  return iov().comment();
301 }
302 
303 int
305  return iov().revision();
306 }
307 
309  return iov().timestamp();
310 }
311 
313  return m_iov->dbSession;
314 }
315 
316 
317 
const_iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:147
int i
Definition: DBlmapReader.cc:9
cond::Time_t lastTill() const
Definition: IOVSequence.h:65
IOVSequence const & iov() const
Definition: IOVProxy.cc:276
std::pair< cond::Time_t, cond::Time_t > validity(cond::Time_t currenttime)
Definition: IOVProxy.cc:226
IOVRange range(cond::Time_t since, cond::Time_t till) const
Definition: IOVProxy.cc:239
Container const & iovs() const
Definition: IOVSequence.cc:76
selection
main part
Definition: corrVsCorr.py:98
void load(const std::string &token)
Definition: IOVProxy.cc:200
std::set< std::string > const & payloadClasses() const
Definition: IOVProxy.cc:294
cond::Time_t pack(cond::UnpackedTime iValue)
IOVRange head(int n) const
Definition: IOVProxy.cc:256
int ii
Definition: cuy.py:588
Container::const_iterator const_iterator
Definition: IOVSequence.h:29
boost::shared_ptr< IOVProxyData > m_iov
Definition: IOVProxy.h:150
TimeType
Definition: Time.h:21
IOVElementProxy front() const
Definition: IOVProxy.cc:155
IOVRange tail(int n) const
Definition: IOVProxy.cc:260
unsigned long long Time_t
Definition: Time.h:16
bool isValid(cond::Time_t currenttime)
Definition: IOVProxy.cc:221
cond::Time_t lastTill() const
Definition: IOVProxy.cc:289
tuple iov
Definition: o2o.py:307
void set(cond::Time_t is, cond::Time_t it, std::string const &itoken)
Definition: IOVProxy.h:59
int size() const
Definition: IOVProxy.cc:272
IOVRange rangeHead(cond::Time_t since, cond::Time_t till, int n) const
Definition: IOVProxy.cc:244
IOVProxy & operator=(const IOVProxy &rhs)
Definition: IOVProxy.cc:195
const Time_t invalidTime(0)
int revision() const
Definition: IOVProxy.cc:304
#define end
Definition: vmac.h:37
T min(T a, T b)
Definition: MathUtil.h:58
cond::Time_t m_lowBound
Definition: IOVProxy.h:153
bool refresh()
Definition: IOVProxy.cc:205
std::pair< int, int > range(cond::Time_t since, cond::Time_t till)
Definition: IOVProxy.cc:23
void throwException(std::string const &message, std::string const &methodName)
Definition: Exception.cc:17
iov_range_iterator const_iterator
Definition: IOVProxy.h:114
bool isOldSchema()
Definition: DbSession.cc:230
cond::Time_t timestamp() const
Definition: IOVProxy.cc:308
IOVRange rangeTail(cond::Time_t since, cond::Time_t till, int n) const
Definition: IOVProxy.cc:250
size_t size() const
Definition: IOVProxy.cc:165
cond::Time_t firstSince() const
Definition: IOVProxy.cc:285
boost::shared_ptr< IOVProxyData > m_iov
Definition: IOVProxy.h:239
std::pair< unsigned int, unsigned int > UnpackedTime
Definition: Time.h:17
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
TimeType timetype() const
Definition: IOVProxy.cc:281
boost::shared_ptr< cond::IOVSequence > data
Definition: IOVProxy.h:43
std::string token
Definition: IOVProxy.h:44
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:126
ora::Database & storage()
Definition: DbSession.cc:215
const_iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:264
const std::string & token()
Definition: IOVProxy.cc:217
tuple size
Write out results.
iov_range_iterator const_iterator
Definition: IOVProxy.h:160
std::string comment() const
Definition: IOVProxy.cc:299
IOVElementProxy back() const
Definition: IOVProxy.cc:160
cond::TimeType timeType() const
Definition: IOVSequence.h:60
IOVRange & operator=(const IOVRange &rhs)
Definition: IOVProxy.cc:139
cond::DbSession dbSession
Definition: IOVProxy.h:42
cond::UnpackedTime unpack(cond::Time_t iValue)
DbSession & db()
Definition: IOVProxy.cc:312