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  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
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:135
cond::persistency::RunInfoProxy::Iterator::m_current
RunInfoData::const_iterator m_current
Definition: RunInfoProxy.h:54
cond::persistency::IOVRunComp
Definition: RunInfoProxy.cc:120
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:129
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:112
cond::persistency::IOVTimeComp
Definition: RunInfoProxy.cc:128
cond::persistency::RunInfoProxy::Iterator::operator!=
bool operator!=(const Iterator &rhs) const
Definition: RunInfoProxy.cc:50
cond::persistency::RunInfoProxy::reset
void reset()
Definition: RunInfoProxy.cc:92
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:105
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:152
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:172
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:121
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:98
cond::persistency::RunInfoProxyData::RunInfoProxyData
RunInfoProxyData()
Definition: RunInfoProxy.cc:12
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
up
Definition: BitonicSort.h:7