CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
22  RunInfoProxy::Iterator::Iterator(const Iterator& rhs) : m_current(rhs.m_current) {}
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 
57  RunInfoProxy::RunInfoProxy(const RunInfoProxy& rhs) : m_data(rhs.m_data), m_session(rhs.m_session) {}
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 
75  std::string dummy;
76  if (!m_session->runInfoSchema().runInfoTable().getInclusiveRunRange(low, up, m_data->runList)) {
77  throwException("No runs have been found in the range (" + std::to_string(low) + "," + std::to_string(up) + ")",
78  "RunInfoProxy::load(Time_t,Time_t)");
79  }
80  }
81 
82  void RunInfoProxy::load(const boost::posix_time::ptime& low, const boost::posix_time::ptime& up) {
83  if (!m_data.get())
84  return;
85 
86  // clear
87  reset();
88 
89  checkTransaction("RunInfoProxy::load(const boost::posix_time::ptime&,const boost::posix_time::ptime&)");
90 
91  std::string dummy;
92  if (!m_session->runInfoSchema().runInfoTable().getInclusiveTimeRange(low, up, m_data->runList)) {
93  throwException("No runs have been found in the interval (" + boost::posix_time::to_simple_string(low) + "," +
94  boost::posix_time::to_simple_string(up) + ")",
95  "RunInfoProxy::load(boost::posix_time::ptime&,const boost::posix_time::ptime&)");
96  }
97  }
98 
100  if (m_data.get()) {
101  m_data->runList.clear();
102  }
103  }
104 
106  if (!m_session.get())
107  throwException("The session is not active.", ctx);
108  if (!m_session->isTransactionActive(false))
109  throwException("The transaction is not active.", ctx);
110  }
111 
113  if (m_data.get()) {
114  return Iterator(m_data->runList.begin());
115  }
116  return Iterator();
117  }
118 
120  if (m_data.get()) {
121  return Iterator(m_data->runList.end());
122  }
123  return Iterator();
124  }
125 
126  // comparison functor for iov tuples: Time_t
127  struct IOVRunComp {
128  bool operator()(const std::tuple<cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime>& x,
129  const cond::Time_t& y) {
130  return (y > std::get<0>(x));
131  }
132  };
133 
134  // comparison functor for iov tuples: boost::posix_time::ptime
135  struct IOVTimeComp {
136  bool operator()(const std::tuple<cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime>& x,
137  const boost::posix_time::ptime& y) {
138  return (y > std::get<2>(x));
139  }
140  };
141 
143  if (m_data.get()) {
144  auto p = std::lower_bound(m_data->runList.begin(), m_data->runList.end(), target, IOVRunComp());
145  return Iterator(p);
146  }
147  return Iterator();
148  }
149 
150  RunInfoProxy::Iterator RunInfoProxy::find(const boost::posix_time::ptime& target) const {
151  if (m_data.get()) {
152  auto p = std::lower_bound(m_data->runList.begin(), m_data->runList.end(), target, IOVTimeComp());
153  return Iterator(p);
154  }
155  return Iterator();
156  }
157 
158  //
160  Iterator it = find(target);
161  if (it == Iterator())
162  throwException("No data has been found.", "RunInfoProxy::get(Time_t)");
163  if (it == end())
164  throwException("The target run has not been found in the selected run range.", "RunInfoProxy::get(Time_t)");
165  return *it;
166  }
167 
168  //
169  cond::RunInfo_t RunInfoProxy::get(const boost::posix_time::ptime& target) const {
170  Iterator it = find(target);
171  if (it == Iterator())
172  throwException("No data has been found.", "RunInfoProxy::get(const boost::posix_time::ptime&)");
173  if (it == end())
174  throwException("The target time has not been found in the selected time range.",
175  "RunInfoProxy::get(const boost::posix_time::ptime&)");
176  return *it;
177  }
178 
179  int RunInfoProxy::size() const { return m_data.get() ? m_data->runList.size() : 0; }
180 
181  } // namespace persistency
182 } // 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
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
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
__host__ __device__ constexpr RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
void checkTransaction(const std::string &ctx)
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