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.
2 #include "SessionImpl.h"
3 
4 namespace cond {
5 
6  namespace persistency {
7 
8  // implementation details...
9  // only hosting data in this case
10  class IOVProxyData {
11  public:
12 
14  iovSequence(){
15  }
16 
17  // tag data
24  // iov data
27  std::vector<cond::Time_t> sinceGroups;
29  size_t numberOfQueries = 0;
30  };
31 
33  m_current(),
34  m_end(),
35  m_timeType( cond::invalid ),
36  m_endOfValidity(cond::time::MAX_VAL) {
37  }
38 
39  IOVProxy::Iterator::Iterator( IOVContainer::const_iterator current, IOVContainer::const_iterator end,
41  m_current( current ),
42  m_end( end ),
43  m_timeType( timeType ),
44  m_endOfValidity( endOfValidity ){
45  }
46 
48  m_current( rhs.m_current ),
49  m_end( rhs.m_end ),
50  m_timeType( rhs.m_timeType ),
51  m_endOfValidity( rhs.m_endOfValidity ){
52  }
53 
55  if( this != &rhs ){
56  m_current = rhs.m_current;
57  m_end = rhs.m_end;
58  m_timeType = rhs.m_timeType;
59  m_endOfValidity = rhs.m_endOfValidity;
60  }
61  return *this;
62  }
63 
65  cond::Iov_t retVal;
66  retVal.since = std::get<0>(*m_current);
67  auto next = m_current;
68  next++;
69 
70  // default is the end of validity when set...
71  retVal.till = m_endOfValidity;
72  // for the till, the next element has to be verified!
73  if( next != m_end ){
74 
75  // the till has to be calculated according to the time type ( because of the packing for some types )
76  retVal.till = cond::time::tillTimeFromNextSince( std::get<0>(*next), m_timeType );
77  }
78  retVal.payloadId = std::get<1>(*m_current);
79  return retVal;
80  }
81 
83  m_current++;
84  return *this;
85  }
86 
88  Iterator tmp( *this );
89  operator++();
90  return tmp;
91  }
92 
93  bool IOVProxy::Iterator::operator==( const Iterator& rhs ) const {
94  if( m_current != rhs.m_current ) return false;
95  if( m_end != rhs.m_end ) return false;
96  return true;
97  }
98 
99  bool IOVProxy::Iterator::operator!=( const Iterator& rhs ) const {
100  return !operator==( rhs );
101  }
102 
104  m_data(),
105  m_session(){
106  }
107 
108  IOVProxy::IOVProxy( const std::shared_ptr<SessionImpl>& session ):
109  m_data( new IOVProxyData ),
110  m_session( session ){
111  }
112 
114  m_data( rhs.m_data ),
115  m_session( rhs.m_session ){
116  }
117 
119  m_data = rhs.m_data;
120  m_session = rhs.m_session;
121  return *this;
122  }
123 
124  void IOVProxy::load( const std::string& tag, bool full ){
125  // clear
126  reset();
127 
128  checkTransaction( "IOVProxy::load" );
129  std::string dummy;
130  if(!m_session->iovSchema().tagTable().select( tag, m_data->timeType, m_data->payloadType, m_data->synchronizationType,
131  m_data->endOfValidity, dummy, m_data->lastValidatedTime ) ){
132  throwException( "Tag \""+tag+"\" has not been found in the database.","IOVProxy::load");
133  }
134  m_data->tag = tag;
135 
136  // now get the iov sequence when required
137  if( full ) {
138 
139  // load the full iov sequence in this case!
140  m_session->iovSchema().iovTable().selectLatest( m_data->tag, m_data->iovSequence );
141  m_data->groupLowerIov = cond::time::MIN_VAL;
142  m_data->groupHigherIov = cond::time::MAX_VAL;
143  } else {
144  m_session->iovSchema().iovTable().selectGroups( m_data->tag, m_data->sinceGroups );
145  }
146  }
147 
149  if(m_data.get() && !m_data->tag.empty()) load( m_data->tag );
150  }
151 
153  if( m_data.get() ){
154  m_data->groupLowerIov = cond::time::MAX_VAL;
155  m_data->groupHigherIov = cond::time::MIN_VAL;
156  m_data->sinceGroups.clear();
157  m_data->iovSequence.clear();
158  m_data->numberOfQueries = 0;
159  }
160  }
161 
163  return m_data.get() ? m_data->tag : std::string("");
164  }
165 
167  return m_data.get() ? m_data->timeType : cond::invalid;
168  }
169 
171  return m_data.get() ? m_data->payloadType : std::string("");
172  }
173 
175  return m_data.get() ? m_data->synchronizationType : cond::SYNCHRONIZATION_UNKNOWN;
176  }
177 
179  return m_data.get() ? m_data->endOfValidity : cond::time::MIN_VAL;
180  }
181 
183  return m_data.get() ? m_data->lastValidatedTime : cond::time::MIN_VAL;
184  }
185 
186  std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime > IOVProxy::getMetadata() const {
187  if(!m_data.get()) throwException( "No tag has been loaded.","IOVProxy::getMetadata()");
188  checkTransaction( "IOVProxy::getMetadata" );
189  std::tuple<std::string, boost::posix_time::ptime, boost::posix_time::ptime > ret;
190  if(!m_session->iovSchema().tagTable().getMetadata( m_data->tag, std::get<0>( ret ), std::get<1>( ret ), std::get<2>( ret ) ) ){
191  throwException( "Metadata for tag \""+m_data->tag+"\" have not been found in the database.","IOVProxy::getMetadata()");
192  }
193  return ret;
194  }
195 
196  bool IOVProxy::isEmpty() const {
197  return m_data.get() ? ( m_data->sinceGroups.size()==0 && m_data->iovSequence.size()==0 ) : true;
198  }
199 
200  void IOVProxy::checkTransaction( const std::string& ctx ) const {
201  if( !m_session.get() ) throwException("The session is not active.",ctx );
202  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
203  }
204 
205  void IOVProxy::fetchSequence( cond::Time_t lowerGroup, cond::Time_t higherGroup ){
206  m_data->iovSequence.clear();
207  m_session->iovSchema().iovTable().selectLatestByGroup( m_data->tag, lowerGroup, higherGroup, m_data->iovSequence );
208 
209  if( m_data->iovSequence.empty() ){
210  m_data->groupLowerIov = cond::time::MAX_VAL;
211  m_data->groupHigherIov = cond::time::MIN_VAL;
212  } else {
213  if( lowerGroup > cond::time::MIN_VAL ) {
214  m_data->groupLowerIov = std::get<0>( m_data->iovSequence.front() );
215  } else {
216  m_data->groupLowerIov = cond::time::MIN_VAL;
217  }
218  if( higherGroup < cond::time::MAX_VAL ) {
219  m_data->groupHigherIov = std::get<0>(m_data->iovSequence.back());
220  } else {
221  m_data->groupHigherIov = cond::time::MAX_VAL;
222  }
223  }
224 
225  m_data->numberOfQueries++;
226  }
227 
229  if( m_data.get() ){
230  return Iterator( m_data->iovSequence.begin(), m_data->iovSequence.end(),
231  m_data->timeType, m_data->endOfValidity );
232  }
233  return Iterator();
234  }
235 
237  if( m_data.get() ){
238  return Iterator( m_data->iovSequence.end(), m_data->iovSequence.end(), m_data->timeType, m_data->endOfValidity );
239  }
240  return Iterator();
241  }
242 
243  // comparison functor for iov tuples: Time_t only and Time_t,string
244  struct IOVComp {
245 
246  bool operator()( const cond::Time_t& x, const cond::Time_t& y ){ return (x < y); }
247 
248  bool operator()( const cond::Time_t& x, const std::tuple<cond::Time_t,cond::Hash>& y ){ return ( x < std::get<0>(y) ); }
249  };
250 
251  // function to search in the vector the target time
252  template <typename T> typename std::vector<T>::const_iterator search( const cond::Time_t& val, const std::vector<T>& container ){
253  if( !container.size() ) return container.end();
254  auto p = std::upper_bound( container.begin(), container.end(), val, IOVComp() );
255  return (p!= container.begin()) ? p-1 : container.end();
256  }
257 
259  checkTransaction( "IOVProxy::find" );
260  // first check the available iov cache:
261  // case 0 empty cache ( the first request )
262 
293  // only one page...
294  if( m_data->groupLowerIov == cond::time::MAX_VAL ){
296  }
297 
298  // the current iov set is a good one...
299  auto iIov = search( time, m_data->iovSequence );
300  return Iterator( iIov, m_data->iovSequence.end(), m_data->timeType, m_data->endOfValidity );
301  }
302 
304  Iterator valid = find( time );
305  if( valid == end() ){
306  throwException( "Can't find a valid interval for the specified time.","IOVProxy::getInterval");
307  }
308  return *valid;
309  }
310 
312  checkTransaction( "IOVProxy::getLast" );
314  if( m_session->iovSchema().iovTable().getLastIov( m_data->tag, ret.since, ret.payloadId ) ){
316  }
317  return ret;
318  }
319 
320  int IOVProxy::loadedSize() const {
321  return m_data.get()? m_data->iovSequence.size() : 0;
322  }
323 
325  checkTransaction( "IOVProxy::sequenceSize" );
326  size_t ret = 0;
327  m_session->iovSchema().iovTable().getSize( m_data->tag, ret );
328  return ret;
329  }
330 
331  size_t IOVProxy::numberOfQueries() const {
332  return m_data.get()? m_data->numberOfQueries : 0;
333  }
334 
335  std::pair<cond::Time_t,cond::Time_t> IOVProxy::loadedGroup() const {
336  return m_data.get()? std::make_pair( m_data->groupLowerIov, m_data->groupHigherIov ): std::make_pair( cond::time::MAX_VAL, cond::time::MIN_VAL );
337  }
338 
339  const std::shared_ptr<SessionImpl>& IOVProxy::session() const {
340  return m_session;
341  }
342 
343  }
344 
345 }
void fetchSequence(cond::Time_t lowerGroup, cond::Time_t higherGroup)
Definition: IOVProxy.cc:205
void checkTransaction(const std::string &ctx) const
Definition: IOVProxy.cc:200
cond::SynchronizationType synchronizationType() const
Definition: IOVProxy.cc:174
std::shared_ptr< SessionImpl > m_session
Definition: IOVProxy.h:143
bool operator()(const cond::Time_t &x, const std::tuple< cond::Time_t, cond::Hash > &y)
Definition: IOVProxy.cc:248
std::string tag() const
Definition: IOVProxy.cc:162
bool operator()(const cond::Time_t &x, const cond::Time_t &y)
Definition: IOVProxy.cc:246
IOVProxy & operator=(const IOVProxy &rhs)
Definition: IOVProxy.cc:118
void load(const std::string &tag, bool full=false)
Definition: IOVProxy.cc:124
Time_t since
Definition: Types.h:51
const Time_t MIN_VAL(0)
std::pair< cond::Time_t, cond::Time_t > loadedGroup() const
Definition: IOVProxy.cc:335
std::string payloadObjectType() const
Definition: IOVProxy.cc:170
bool operator!=(const Iterator &rhs) const
Definition: IOVProxy.cc:99
IOVProxy::IOVContainer iovSequence
Definition: IOVProxy.cc:28
TimeType
Definition: Time.h:21
Iterator begin() const
Definition: IOVProxy.cc:228
Iterator & operator=(const Iterator &rhs)
Definition: IOVProxy.cc:54
std::tuple< std::string, boost::posix_time::ptime, boost::posix_time::ptime > getMetadata() const
Definition: IOVProxy.cc:186
cond::TimeType timeType() const
Definition: IOVProxy.cc:166
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
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
Definition: GenABIO.cc:180
Iterator find(cond::Time_t time)
Definition: IOVProxy.cc:258
Hash payloadId
Definition: Types.h:53
cond::Iov_t getInterval(cond::Time_t time)
Definition: IOVProxy.cc:303
IOVContainer::const_iterator m_end
Definition: IOVProxy.h:56
cond::Time_t endOfValidity() const
Definition: IOVProxy.cc:178
cond::Time_t lastValidatedTime() const
Definition: IOVProxy.cc:182
std::shared_ptr< IOVProxyData > m_data
Definition: IOVProxy.h:142
Time_t tillTimeFromNextSince(Time_t nextSince, TimeType timeType)
Definition: Time.cc:33
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
SynchronizationType
Definition: Types.h:31
cond::SynchronizationType synchronizationType
Definition: IOVProxy.cc:21
Definition: DDAxes.h:10
bool operator==(const Iterator &rhs) const
Definition: IOVProxy.cc:93
std::vector< cond::Time_t > sinceGroups
Definition: IOVProxy.cc:27
size_t numberOfQueries() const
Definition: IOVProxy.cc:331
const Time_t MAX_VAL(std::numeric_limits< Time_t >::max())
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11
Iterator end() const
Definition: IOVProxy.cc:236
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:252
Time_t till
Definition: Types.h:52
const std::shared_ptr< SessionImpl > & session() const
Definition: IOVProxy.cc:339