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