CMS 3D CMS Logo

MonRunList.cc
Go to the documentation of this file.
1 #include <stdexcept>
3 
10 
11 using namespace std;
12 using namespace oracle::occi;
13 
14 MonRunList::MonRunList() { m_conn = nullptr; }
15 
17 
19  if (tag != m_runTag) {
20  m_runTag = tag;
21  }
22 }
24  if (tag != m_monrunTag) {
25  m_monrunTag = tag;
26  }
27 }
28 
29 RunTag MonRunList::getRunTag() const { return m_runTag; }
30 MonRunTag MonRunList::getMonRunTag() const { return m_monrunTag; }
31 
32 std::vector<MonRunIOV> MonRunList::getRuns() { return m_vec_monruniov; }
33 
35  this->checkConnection();
36  int nruns = 0;
37 
38  m_runTag.setConnection(m_env, m_conn);
39  int tagID = m_runTag.fetchID();
40  cout << "tag id=" << tagID << endl;
41  if (!tagID) {
42  return;
43  }
44  m_monrunTag.setConnection(m_env, m_conn);
45  int montagID = m_monrunTag.fetchID();
46  cout << "mon tag id=" << montagID << endl;
47  if (!montagID) {
48  return;
49  }
50 
51  try {
52  Statement* stmt0 = m_conn->createStatement();
53  stmt0->setSQL(
54  "SELECT count(mon_run_iov.iov_id) FROM mon_run_iov, run_iov "
55  "WHERE mon_run_iov.run_iov_id= run_iov.iov_id and run_iov.tag_id = :tag_id and mon_run_iov.tag_id=:montag_id ");
56  stmt0->setInt(1, tagID);
57  stmt0->setInt(2, montagID);
58 
59  ResultSet* rset0 = stmt0->executeQuery();
60  if (rset0->next()) {
61  nruns = rset0->getInt(1);
62  }
63  m_conn->terminateStatement(stmt0);
64 
65  cout << "nruns=" << nruns << endl;
66 
67  m_vec_monruniov.reserve(nruns);
68 
69  Statement* stmt = m_conn->createStatement();
70  stmt->setSQL(
71  "SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, mon_run_iov.tag_id, mon_run_iov.run_iov_id, "
72  "mon_run_iov.subrun_num, mon_run_iov.subrun_start, mon_run_iov.subrun_end, mon_run_iov.iov_id FROM run_iov, "
73  "mon_run_iov "
74  "WHERE mon_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id order by run_iov.run_num, "
75  "mon_run_iov.subrun_num ASC ");
76  stmt->setInt(1, tagID);
77 
78  DateHandler dh(m_env, m_conn);
79  Tm runStart;
80  Tm runEnd;
81  Tm lrunStart;
82  Tm lrunEnd;
83 
84  ResultSet* rset = stmt->executeQuery();
85  int i = 0;
86  while (i < nruns) {
87  rset->next();
88  int runNum = rset->getInt(1);
89  Date startDate = rset->getDate(2);
90  Date endDate = rset->getDate(3);
91  //int ltag = rset->getInt(4);
92  int lid = rset->getInt(5);
93  int subrun = rset->getInt(6);
94  Date monstartDate = rset->getDate(7);
95  Date monendDate = rset->getDate(8);
96  int liov_id = rset->getInt(9);
97 
98  runStart = dh.dateToTm(startDate);
99  runEnd = dh.dateToTm(endDate);
100  lrunStart = dh.dateToTm(monstartDate);
101  lrunEnd = dh.dateToTm(monendDate);
102 
103  RunIOV r;
104  r.setRunNumber(runNum);
105  r.setRunStart(runStart);
106  r.setRunEnd(runEnd);
107  r.setRunTag(m_runTag);
108  r.setID(lid);
109 
110  MonRunIOV lr;
111  // da correggere qui
112  lr.setRunIOV(r);
113  lr.setSubRunNumber(subrun);
114  lr.setSubRunStart(lrunStart);
115  lr.setSubRunEnd(lrunEnd);
116  lr.setMonRunTag(m_monrunTag);
117  lr.setID(liov_id);
118  m_vec_monruniov.push_back(lr);
119 
120  i++;
121  }
122 
123  m_conn->terminateStatement(stmt);
124  } catch (SQLException& e) {
125  throw(std::runtime_error("RunIOV::fetchID: " + e.getMessage()));
126  }
127 }
128 
129 void MonRunList::fetchRuns(int min_run, int max_run) noexcept(false) {
130  this->checkConnection();
131  int nruns = 0;
132 
133  m_runTag.setConnection(m_env, m_conn);
134  int tagID = m_runTag.fetchID();
135  cout << "tag id=" << tagID << endl;
136  if (!tagID) {
137  return;
138  }
139  m_monrunTag.setConnection(m_env, m_conn);
140  int montagID = m_monrunTag.fetchID();
141  cout << "mon tag id=" << montagID << endl;
142  if (!montagID) {
143  return;
144  }
145 
146  int my_min_run = min_run - 1;
147  int my_max_run = max_run + 1;
148  try {
149  Statement* stmt0 = m_conn->createStatement();
150  stmt0->setSQL(
151  "SELECT count(mon_run_iov.iov_id) FROM mon_run_iov, run_iov "
152  "WHERE mon_run_iov.run_iov_id= run_iov.iov_id "
153  "and run_iov.tag_id = :tag_id and mon_run_iov.tag_id=:montag_id "
154  " and run_iov.run_num> :min_run and run_iov.run_num< :max_run ");
155  stmt0->setInt(1, tagID);
156  stmt0->setInt(2, montagID);
157  stmt0->setInt(3, my_min_run);
158  stmt0->setInt(4, my_max_run);
159 
160  ResultSet* rset0 = stmt0->executeQuery();
161  if (rset0->next()) {
162  nruns = rset0->getInt(1);
163  }
164  m_conn->terminateStatement(stmt0);
165 
166  cout << "nruns=" << nruns << endl;
167 
168  m_vec_monruniov.reserve(nruns);
169 
170  Statement* stmt = m_conn->createStatement();
171  stmt->setSQL(
172  "SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, mon_run_iov.tag_id, mon_run_iov.run_iov_id, "
173  "mon_run_iov.subrun_num, mon_run_iov.subrun_start, mon_run_iov.subrun_end, mon_run_iov.iov_id FROM run_iov, "
174  "mon_run_iov "
175  "WHERE mon_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id "
176  " and mon_run_iov.tag_id=:montag_id "
177  " and run_iov.run_num> :min_run and run_iov.run_num< :max_run "
178  " order by run_iov.run_num, mon_run_iov.subrun_num ASC ");
179  stmt->setInt(1, tagID);
180  stmt->setInt(2, montagID);
181  stmt->setInt(3, my_min_run);
182  stmt->setInt(4, my_max_run);
183 
184  DateHandler dh(m_env, m_conn);
185  Tm runStart;
186  Tm runEnd;
187  Tm lrunStart;
188  Tm lrunEnd;
189 
190  ResultSet* rset = stmt->executeQuery();
191  int i = 0;
192  while (i < nruns) {
193  rset->next();
194  int runNum = rset->getInt(1);
195  Date startDate = rset->getDate(2);
196  Date endDate = rset->getDate(3);
197  // int ltag = rset->getInt(4);
198  int lid = rset->getInt(5);
199  int subrun = rset->getInt(6);
200  Date monstartDate = rset->getDate(7);
201  Date monendDate = rset->getDate(8);
202  int liov_id = rset->getInt(9);
203 
204  runStart = dh.dateToTm(startDate);
205  runEnd = dh.dateToTm(endDate);
206  lrunStart = dh.dateToTm(monstartDate);
207  lrunEnd = dh.dateToTm(monendDate);
208 
209  RunIOV r;
210  r.setRunNumber(runNum);
211  r.setRunStart(runStart);
212  r.setRunEnd(runEnd);
213  r.setRunTag(m_runTag);
214  r.setID(lid);
215 
216  MonRunIOV lr;
217  // da correggere qui
218  lr.setRunIOV(r);
219  lr.setSubRunNumber(subrun);
220  lr.setSubRunStart(lrunStart);
221  lr.setSubRunEnd(lrunEnd);
222  lr.setMonRunTag(m_monrunTag);
223  lr.setID(liov_id);
224  m_vec_monruniov.push_back(lr);
225 
226  i++;
227  }
228 
229  m_conn->terminateStatement(stmt);
230  } catch (SQLException& e) {
231  throw(std::runtime_error("RunIOV::fetchID: " + e.getMessage()));
232  }
233 }
234 
235 void MonRunList::fetchLastNRuns(int max_run, int n_runs) noexcept(false) {
236  // fetch the last n_runs that come just before max_run (including max_run)
237 
238  this->checkConnection();
239 
240  m_runTag.setConnection(m_env, m_conn);
241  int tagID = m_runTag.fetchID();
242  cout << "tag id=" << tagID << endl;
243  if (!tagID) {
244  return;
245  }
246  m_monrunTag.setConnection(m_env, m_conn);
247  int montagID = m_monrunTag.fetchID();
248  cout << "mon tag id=" << montagID << endl;
249  if (!montagID) {
250  return;
251  }
252 
253  int my_max_run = max_run + 1;
254  try {
255  int nruns = n_runs;
256  m_vec_monruniov.reserve(nruns);
257 
258  Statement* stmt = m_conn->createStatement();
259  stmt->setSQL(
260  "select run_num, run_start, run_end, tag_id, run_iov_id, subrun_num, subrun_start, subrun_end, mon_iov_id from "
261  "(SELECT run_iov.run_num, run_iov.run_start, run_iov.run_end, mon_run_iov.tag_id, mon_run_iov.run_iov_id, "
262  "mon_run_iov.subrun_num, mon_run_iov.subrun_start, mon_run_iov.subrun_end, mon_run_iov.iov_id as mon_iov_id "
263  "FROM run_iov, mon_run_iov "
264  "WHERE mon_run_iov.run_iov_id=run_iov.iov_id and run_iov.tag_id = :tag_id "
265  " and mon_run_iov.tag_id=:montag_id "
266  " and run_iov.run_num< :max_run "
267  " order by run_iov.run_num DESC ) where rownum< :n_runs order by run_num DESC ");
268  stmt->setInt(1, tagID);
269  stmt->setInt(2, montagID);
270  stmt->setInt(3, my_max_run);
271  stmt->setInt(4, n_runs);
272 
273  DateHandler dh(m_env, m_conn);
274  Tm runStart;
275  Tm runEnd;
276  Tm lrunStart;
277  Tm lrunEnd;
278 
279  ResultSet* rset = stmt->executeQuery();
280  int i = 0;
281  while (i < nruns) {
282  rset->next();
283  int runNum = rset->getInt(1);
284  Date startDate = rset->getDate(2);
285  Date endDate = rset->getDate(3);
286  // int ltag = rset->getInt(4);
287  int lid = rset->getInt(5);
288  int subrun = rset->getInt(6);
289  Date monstartDate = rset->getDate(7);
290  Date monendDate = rset->getDate(8);
291  int liov_id = rset->getInt(9);
292 
293  runStart = dh.dateToTm(startDate);
294  runEnd = dh.dateToTm(endDate);
295  lrunStart = dh.dateToTm(monstartDate);
296  lrunEnd = dh.dateToTm(monendDate);
297 
298  RunIOV r;
299  r.setRunNumber(runNum);
300  r.setRunStart(runStart);
301  r.setRunEnd(runEnd);
302  r.setRunTag(m_runTag);
303  r.setID(lid);
304 
305  MonRunIOV lr;
306  // da correggere qui
307  lr.setRunIOV(r);
308  lr.setSubRunNumber(subrun);
309  lr.setSubRunStart(lrunStart);
310  lr.setSubRunEnd(lrunEnd);
311  lr.setMonRunTag(m_monrunTag);
312  lr.setID(liov_id);
313  m_vec_monruniov.push_back(lr);
314 
315  i++;
316  }
317 
318  m_conn->terminateStatement(stmt);
319  } catch (SQLException& e) {
320  throw(std::runtime_error("MonRunList::fetchLastNRuns: " + e.getMessage()));
321  }
322 }
void setRunStart(const Tm &start)
Definition: RunIOV.cc:33
RunTag getRunTag() const
Definition: MonRunList.cc:29
Definition: RunTag.h:13
void setRunIOV(const RunIOV &iov)
Definition: MonRunIOV.cc:36
void fetchLastNRuns(int max_run, int n_runs) noexcept(false)
Definition: MonRunList.cc:235
void setRunTag(const RunTag &tag)
Definition: RunIOV.cc:51
void setRunTag(const RunTag &tag)
Definition: MonRunList.cc:18
void setRunNumber(run_t run)
Definition: RunIOV.cc:22
~MonRunList() override
Definition: MonRunList.cc:16
void setSubRunEnd(const Tm &end)
Definition: MonRunIOV.cc:63
void setSubRunNumber(subrun_t subrun)
Definition: MonRunIOV.cc:45
MonRunTag getMonRunTag() const
Definition: MonRunList.cc:30
void setSubRunStart(const Tm &start)
Definition: MonRunIOV.cc:54
#define noexcept
std::vector< MonRunIOV > getRuns()
Definition: MonRunList.cc:32
void fetchRuns() noexcept(false)
Definition: MonRunList.cc:34
void setMonRunTag(const MonRunTag &tag)
Definition: MonRunIOV.cc:27
void setMonRunTag(const MonRunTag &tag)
Definition: MonRunList.cc:23
void setRunEnd(const Tm &end)
Definition: RunIOV.cc:42
dh
Definition: cuy.py:355
Definition: RunIOV.h:13
Tm dateToTm(oracle::occi::Date &date) const
Definition: DateHandler.cc:28
Definition: Tm.h:13
void setID(int id)
Definition: RunIOV.cc:29
void setID(int id)
Definition: MonRunIOV.cc:25