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  std::cout <<"Min="<<std::get<0>(m_data->runList.front())<<" max="<<std::get<0>(m_data->runList.back())<<std::endl;
97  }
98 
99  void RunInfoProxy::load( const boost::posix_time::ptime& low, const boost::posix_time::ptime& up ){
100  if( !m_data.get() ) return;
101 
102  // clear
103  reset();
104 
105  checkTransaction( "RunInfoProxy::load(const boost::posix_time::ptime&,const boost::posix_time::ptime&)" );
106 
108  m_session->runInfoSchema().runInfoTable().getInclusiveTimeRange( low, up, m_data->runList );
109  }
110 
112  if( m_data.get() ){
113  m_data->runList.clear();
114  }
115  }
116 
118  if( !m_session.get() ) throwException("The session is not active.",ctx );
119  if( !m_session->isTransactionActive( false ) ) throwException("The transaction is not active.",ctx );
120  }
121 
123  if( m_data.get() ){
124  return Iterator( m_data->runList.begin() );
125  }
126  return Iterator();
127  }
128 
130  if( m_data.get() ){
131  return Iterator( m_data->runList.end() );
132  }
133  return Iterator();
134  }
135 
136  // comparison functor for iov tuples: Time_t
137  struct IOVRunComp {
138 
139  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) ); }
140 
141  };
142 
143  // comparison functor for iov tuples: boost::posix_time::ptime
144  struct IOVTimeComp {
145 
146  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) ); }
147 
148  };
149 
151  if( m_data.get() ){
152  auto p = std::lower_bound( m_data->runList.begin(), m_data->runList.end(), target, IOVRunComp() );
153  return Iterator( p );
154  }
155  return Iterator();
156  }
157 
158  RunInfoProxy::Iterator RunInfoProxy::find( const boost::posix_time::ptime& target ) const {
159  if( m_data.get() ){
160  auto p = std::lower_bound( m_data->runList.begin(), m_data->runList.end(), target, IOVTimeComp() );
161  return Iterator( p );
162  }
163  return Iterator();
164  }
165 
166  //
168  Iterator it = find( target );
169  if( it == Iterator() ) throwException("No data has been found.","RunInfoProxy::get(Time_t)" );
170  if( it == end() ) throwException("The target run has not been found in the selected run range.","RunInfoProxy::get(Time_t)" );
171  return *it;
172  }
173 
174  //
175  cond::RunInfo_t RunInfoProxy::get( const boost::posix_time::ptime& target ) const {
176  Iterator it = find( target );
177  if( it == Iterator() ) throwException("No data has been found.","RunInfoProxy::get(const boost::posix_time::ptime&)" );
178  if( it == end() ) throwException("The target time has not been found in the selected time range.","RunInfoProxy::get(const boost::posix_time::ptime&)" );
179  return *it;
180  }
181 
182 
183 
184  int RunInfoProxy::size() const {
185  return m_data.get()? m_data->runList.size() : 0;
186  }
187 
188  }
189 }
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