CMS 3D CMS Logo

RunInfoProxy.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
11  public:
12 
14  runList(){
15  }
16 
17  // the data loaded
19  };
20 
22  m_current(){
23  }
24 
25  RunInfoProxy::Iterator::Iterator( RunInfoData::const_iterator current ):
26  m_current( current ){
27  }
28 
30  m_current( rhs.m_current ){
31  }
32 
34  if( this != &rhs ){
35  m_current = rhs.m_current;
36  }
37  return *this;
38  }
39 
41  return cond::RunInfo_t( *m_current );
42  }
43 
45  m_current++;
46  return *this;
47  }
48 
50  Iterator tmp( *this );
51  operator++();
52  return tmp;
53  }
54 
55  bool RunInfoProxy::Iterator::operator==( const Iterator& rhs ) const {
56  if( m_current != rhs.m_current ) return false;
57  return true;
58  }
59 
60  bool RunInfoProxy::Iterator::operator!=( const Iterator& rhs ) const {
61  return !operator==( rhs );
62  }
63 
65  m_data(),
66  m_session(){
67  }
68 
69  RunInfoProxy::RunInfoProxy( const std::shared_ptr<SessionImpl>& session ):
70  m_data( new RunInfoProxyData ),
71  m_session( session ){
72  }
73 
75  m_data( rhs.m_data ),
76  m_session( rhs.m_session ){
77  }
78 
80  m_data = rhs.m_data;
81  m_session = rhs.m_session;
82  return *this;
83  }
84 
85  //
87  if( !m_data.get() ) return;
88 
89  // clear
90  reset();
91 
92  checkTransaction( "RunInfoProxy::load(Time_t,Time_t)" );
93 
95  m_session->runInfoSchema().runInfoTable().getInclusiveRunRange( low, up, m_data->runList );
96  }
97 
98  void RunInfoProxy::load( const boost::posix_time::ptime& low, const boost::posix_time::ptime& up ){
99  if( !m_data.get() ) return;
100 
101  // clear
102  reset();
103 
104  checkTransaction( "RunInfoProxy::load(const boost::posix_time::ptime&,const boost::posix_time::ptime&)" );
105 
107  m_session->runInfoSchema().runInfoTable().getInclusiveTimeRange( low, up, m_data->runList );
108  }
109 
111  if( m_data.get() ){
112  m_data->runList.clear();
113  }
114  }
115 
117  if( !m_session.get() ) throwException("The session is not active.",ctx );
118  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
119  }
120 
122  if( m_data.get() ){
123  return Iterator( m_data->runList.begin() );
124  }
125  return Iterator();
126  }
127 
129  if( m_data.get() ){
130  return Iterator( m_data->runList.end() );
131  }
132  return Iterator();
133  }
134 
135  // comparison functor for iov tuples: Time_t
136  struct IOVRunComp {
137 
138  bool operator()( const std::tuple<cond::Time_t,boost::posix_time::ptime,boost::posix_time::ptime>& x, const cond::Time_t& y ){ return ( y > std::get<0>(x) ); }
139 
140  };
141 
142  // comparison functor for iov tuples: boost::posix_time::ptime
143  struct IOVTimeComp {
144 
145  bool operator()( const std::tuple<cond::Time_t,boost::posix_time::ptime,boost::posix_time::ptime>& x, const boost::posix_time::ptime& y ){ return ( y > std::get<2>(x) ); }
146 
147  };
148 
150  if( m_data.get() ){
151  auto p = std::lower_bound( m_data->runList.begin(), m_data->runList.end(), target, IOVRunComp() );
152  return Iterator( p );
153  }
154  return Iterator();
155  }
156 
157  RunInfoProxy::Iterator RunInfoProxy::find( const boost::posix_time::ptime& target ) const {
158  if( m_data.get() ){
159  auto p = std::lower_bound( m_data->runList.begin(), m_data->runList.end(), target, IOVTimeComp() );
160  return Iterator( p );
161  }
162  return Iterator();
163  }
164 
165  //
167  Iterator it = find( target );
168  if( it == Iterator() ) throwException("No data has been found.","RunInfoProxy::get(Time_t)" );
169  if( it == end() ) throwException("The target run has not been found in the selected run range.","RunInfoProxy::get(Time_t)" );
170  return *it;
171  }
172 
173  //
174  cond::RunInfo_t RunInfoProxy::get( const boost::posix_time::ptime& target ) const {
175  Iterator it = find( target );
176  if( it == Iterator() ) throwException("No data has been found.","RunInfoProxy::get(const boost::posix_time::ptime&)" );
177  if( it == end() ) throwException("The target time has not been found in the selected time range.","RunInfoProxy::get(const boost::posix_time::ptime&)" );
178  return *it;
179  }
180 
181 
182 
183  int RunInfoProxy::size() const {
184  return m_data.get()? m_data->runList.size() : 0;
185  }
186 
187  }
188 }
Definition: BitonicSort.h:8
bool operator()(const std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > &x, const boost::posix_time::ptime &y)
void load(Time_t low, Time_t up)
Definition: RunInfoProxy.cc:86
bool operator()(const std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > &x, const cond::Time_t &y)
std::shared_ptr< SessionImpl > m_session
Definition: RunInfoProxy.h:103
RunInfoProxy::RunInfoData runList
Definition: RunInfoProxy.cc:18
RunInfoData::const_iterator m_current
Definition: RunInfoProxy.h:53
unsigned long long Time_t
Definition: Time.h:16
bool operator==(const Iterator &rhs) const
Definition: RunInfoProxy.cc:55
std::vector< std::tuple< Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > RunInfoData
Definition: RunInfoProxy.h:28
RunInfoProxy & operator=(const RunInfoProxy &rhs)
Definition: RunInfoProxy.cc:79
cond::RunInfo_t get(Time_t target) const
bool operator!=(const Iterator &rhs) const
Definition: RunInfoProxy.cc:60
Iterator find(Time_t target) const
Iterator & operator=(const Iterator &rhs)
Definition: RunInfoProxy.cc:33
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Definition: plugin.cc:24
void checkTransaction(const std::string &ctx)
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14
std::shared_ptr< RunInfoProxyData > m_data
Definition: RunInfoProxy.h:102