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 
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 
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 
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
cond::persistency::RunInfoProxy::Iterator::Iterator
Iterator()
Definition: RunInfoProxy.cc:18
cond::persistency::RunInfoProxy::RunInfoProxy
RunInfoProxy()
Definition: RunInfoProxy.cc:52
cond::persistency::RunInfoProxy::find
Iterator find(Time_t target) const
Definition: RunInfoProxy.cc:142
cond::persistency::RunInfoProxy::Iterator::m_current
RunInfoData::const_iterator m_current
Definition: RunInfoProxy.h:54
cond::persistency::IOVRunComp
Definition: RunInfoProxy.cc:127
cond::persistency::RunInfoProxy::load
void load(Time_t low, Time_t up)
Definition: RunInfoProxy.cc:66
cond::persistency::IOVTimeComp::operator()
bool operator()(const std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > &x, const boost::posix_time::ptime &y)
Definition: RunInfoProxy.cc:136
RunInfoProxy.h
cond::persistency::RunInfoProxy
Definition: RunInfoProxy.h:26
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
cond::persistency::RunInfoProxy::m_session
std::shared_ptr< SessionImpl > m_session
Definition: RunInfoProxy.h:104
cond::persistency::RunInfoProxy::end
Iterator end() const
Definition: RunInfoProxy.cc:119
cond::persistency::IOVTimeComp
Definition: RunInfoProxy.cc:135
cond::persistency::RunInfoProxy::Iterator::operator!=
bool operator!=(const Iterator &rhs) const
Definition: RunInfoProxy.cc:50
cond::persistency::RunInfoProxy::reset
void reset()
Definition: RunInfoProxy.cc:99
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
cms::Iterator
TGeoIterator Iterator
Definition: DDFilteredView.h:49
cond::persistency::RunInfoProxy::begin
Iterator begin() const
Definition: RunInfoProxy.cc:112
cond::persistency::RunInfoProxyData::runList
RunInfoProxy::RunInfoData runList
Definition: RunInfoProxy.cc:15
SessionImpl.h
cond::persistency::RunInfoProxy::RunInfoData
std::vector< std::tuple< Time_t, boost::posix_time::ptime, boost::posix_time::ptime > > RunInfoData
Definition: RunInfoProxy.h:28
cond::persistency::RunInfoProxy::operator=
RunInfoProxy & operator=(const RunInfoProxy &rhs)
Definition: RunInfoProxy.cc:59
cond::persistency::RunInfoProxy::Iterator
Definition: RunInfoProxy.h:32
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond
Definition: plugin.cc:23
operator==
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
Definition: QGLikelihoodObject.h:49
cond::persistency::RunInfoProxy::Iterator::operator==
bool operator==(const Iterator &rhs) const
Definition: RunInfoProxy.cc:44
cond::persistency::RunInfoProxy::get
cond::RunInfo_t get(Time_t target) const
Definition: RunInfoProxy.cc:159
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
cond::persistency::RunInfoProxy::Iterator::operator*
cond::RunInfo_t operator*()
Definition: RunInfoProxy.cc:31
cond::persistency::RunInfoProxy::Iterator::operator=
Iterator & operator=(const Iterator &rhs)
Definition: RunInfoProxy.cc:24
cond::RunInfo_t
Definition: Types.h:139
cond::persistency::RunInfoProxyData
Definition: RunInfoProxy.cc:10
cond::persistency::RunInfoProxy::size
int size() const
Definition: RunInfoProxy.cc:179
cond::persistency::RunInfoProxy::Iterator::operator++
Iterator & operator++()
Definition: RunInfoProxy.cc:33
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
filterCSVwithJSON.target
target
Definition: filterCSVwithJSON.py:32
cond::persistency::IOVRunComp::operator()
bool operator()(const std::tuple< cond::Time_t, boost::posix_time::ptime, boost::posix_time::ptime > &x, const cond::Time_t &y)
Definition: RunInfoProxy.cc:128
cond::persistency::RunInfoProxy::m_data
std::shared_ptr< RunInfoProxyData > m_data
Definition: RunInfoProxy.h:103
dummy
Definition: DummySelector.h:38
cond::persistency::RunInfoProxy::checkTransaction
void checkTransaction(const std::string &ctx)
Definition: RunInfoProxy.cc:105
cond::persistency::RunInfoProxyData::RunInfoProxyData
RunInfoProxyData()
Definition: RunInfoProxy.cc:12
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
up
Definition: BitonicSort.h:7