test
CMS 3D CMS Logo

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