CMS 3D CMS Logo

RunDCSHVDat.cc
Go to the documentation of this file.
1 #include <stdexcept>
2 #include <string>
3 #include <cmath>
4 #include <list>
5 #include <string>
6 #include <map>
7 #include <ctime>
8 
12 
13 using namespace std;
14 using namespace oracle::occi;
15 
17 {
18  m_env = nullptr;
19  m_conn = nullptr;
20  m_writeStmt = nullptr;
21  m_readStmt = nullptr;
22 
23  m_hv = 0;
24  m_hvnom = 0;
25  m_status= 0;
26  m_tstatus= 0;
27 }
28 
29 
30 
32 {
33 }
34 
35 
36 
39 {
40 
41 
42 }
43 
44 
45 
46 void RunDCSHVDat::writeDB(const EcalLogicID* ecid, const RunDCSHVDat* item, RunIOV* iov)
47  noexcept(false)
48 {
49 }
50 
51 
52 
53 void RunDCSHVDat::fetchData(map< EcalLogicID, RunDCSHVDat >* fillMap, RunIOV* iov)
54  noexcept(false)
55 {
56  fetchLastData(fillMap);
57 
58 }
59 
60 
61 
63 
64  DateHandler dh(m_env, m_conn);
65 
66  ResultSet* rset = nullptr;
67  string query="SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
68  " d.actual_vmon, h.nominal_value , d.change_date "
69  " FROM "+ getEBAccount()+".FWCAENCHANNEL d "
70  " JOIN "+ getEBAccount()+".HV_MAPPING h on h.DPID = d.DPID "
71  " join "+ getEBAccount()+".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
72  " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date " ;
73  try {
74  m_readStmt->setSQL(query);
75 
76  m_readStmt->setDate(1, dh.tmToDate(timeStart));
77 
78  rset = m_readStmt->executeQuery();
79  }
80  catch (SQLException e) {
81 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
82  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): ") + getOraMessage(&e) + " " + query));
83 #else
84  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): error code ") + std::to_string(e.getErrorCode()) + " " + query));
85 #endif
86  }
87  return rset;
88 }
89 
91 
92  DateHandler dh(m_env, m_conn);
93 
94  ResultSet* rset = nullptr;
95  string query="SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
96  " d.actual_vmon, '800' nominal_value , d.change_date "
97  " FROM "+ getEEAccount()+".FWCAENCHANNEL d "
98  " JOIN "+ getEEAccount()+".EE_HVA_MAPPING h on h.DPID = d.DPID "
99  " join "+ getEEAccount()+".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
100  " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date " ;
101  try {
102  m_readStmt->setSQL(query);
103 
104  m_readStmt->setDate(1, dh.tmToDate(timeStart));
105 
106  rset = m_readStmt->executeQuery();
107  }
108  catch (SQLException e) {
109 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
110  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): ") + getOraMessage(&e) + " " + query));
111 #else
112  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): error code ") + std::to_string(e.getErrorCode()) + " " + query));
113 #endif
114  }
115  return rset;
116 }
117 
119 
120  DateHandler dh(m_env, m_conn);
121 
122  ResultSet* rset = nullptr;
123  string query="SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
124  " d.actual_vmon, '600' nominal_value , d.change_date "
125  " FROM "+ getEEAccount()+".FWCAENCHANNEL d "
126  " JOIN "+ getEEAccount()+".EE_HVD_MAPPING h on h.DPID = d.DPID "
127  " join "+ getEEAccount()+".CHANNELVIEW cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name "
128  " AND d.change_date> :1 AND d.actual_vmon is not null order by change_date " ;
129  try {
130  m_readStmt->setSQL(query);
131 
132  m_readStmt->setDate(1, dh.tmToDate(timeStart));
133 
134  rset = m_readStmt->executeQuery();
135  }
136  catch (SQLException e) {
137 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
138  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): ") + getOraMessage(&e) + " " + query));
139 #else
140  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): error code ") + std::to_string(e.getErrorCode()) + " " + query));
141 #endif
142  }
143  return rset;
144 }
145 
146 
147 /*
148 ResultSet *RunDCSHVDat::getBarrelRset() {
149  ResultSet* rset = NULL;
150  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
151  " d.value, h.nominal_value , d.since "
152  "FROM "+ getEBAccount()+".DCSLASTVALUE_VOLTAGE_VMON d "
153  " JOIN "+ getEBAccount()+".HV_MAPPING h on "
154  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name";
155  try {
156  m_readStmt->setSQL(query);
157  rset = m_readStmt->executeQuery();
158  }
159  catch (SQLException e) {
160  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): ") + getOraMessage(&e) + " " + query));
161  }
162  return rset;
163 }
164 */
165 
167  ResultSet* rset = nullptr;
168  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
169  " d.VALUE_NUMBER, h.nominal_value , d.CHANGE_DATE "
170  "FROM "+ getEBAccount()+".FWCAENCHANNEL_LV d "
171  " JOIN "+ getEBAccount()+".HV_MAPPING h on "
172  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and DPE_NAME='ACTUAL_VMON' ";
173  try {
174  m_readStmt->setSQL(query);
175  rset = m_readStmt->executeQuery();
176  }
177  catch (SQLException e) {
178 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
179  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): ") + getOraMessage(&e) + " " + query));
180 #else
181  throw(std::runtime_error(std::string("RunDCSHVDat::getBarrelRset(): error code ") + std::to_string(e.getErrorCode()) + " " + query));
182 #endif
183  }
184  return rset;
185 }
186 
188  ResultSet* rset = nullptr;
189  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
190  " d.value_number, '800' NOMINAL_VALUE , d.CHANGE_DATE "
191  "FROM "+ getEEAccount()+".FWCAENCHANNEL_LV d "
192  " JOIN "+ getEEAccount()+".EE_HVA_MAPPING h on "
193  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and dpe_name='ACTUAL_VMON' ";
194  try {
195  m_readStmt->setSQL(query);
196  rset = m_readStmt->executeQuery();
197  }
198  catch (SQLException e) {
199 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
200  throw(std::runtime_error(std::string("RunDCSHVDat::getEndcapAnodeRset(): ") + getOraMessage(&e) + " " + query));
201 #else
202  throw(std::runtime_error(std::string("RunDCSHVDat::getEndcapAnodeRset(): error code ") + std::to_string(e.getErrorCode()) + " " + query));
203 #endif
204  }
205  return rset;
206 }
207 
209  ResultSet* rset = nullptr;
210  string query = "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
211  " d.value_number, '600' NOMINAL_VALUE , d.CHANGE_DATE "
212  "FROM "+ getEEAccount()+".FWCAENCHANNEL_LV d "
213  " JOIN "+ getEEAccount()+".EE_HVD_MAPPING h on "
214  " h.DPID = d.DPID join channelview cv on cv.logic_id=h.logic_id WHERE cv.maps_to = cv.name and dpe_name='ACTUAL_VMON' ";
215  try {
216  m_readStmt->setSQL(query);
217  rset = m_readStmt->executeQuery();
218  }
219  catch (SQLException e) {
220 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
221  throw(std::runtime_error(std::string("RunDCSHVDat::getEndcapDynodeRset(): ") + getOraMessage(&e) + " " + query));
222 #else
223  throw(std::runtime_error(std::string("RunDCSHVDat::getEndcapDynodeRset(): error code ") + std::to_string(e.getErrorCode()) + " " + query));
224 #endif
225  }
226  return rset;
227 }
228 
230  map< EcalLogicID, RunDCSHVDat >* fillMap) {
231 
232  // method for last value queries
233 
234  std::pair< EcalLogicID, RunDCSHVDat > p;
235  RunDCSHVDat dat;
236  DateHandler dh(m_env, m_conn);
237 
238  try {
239  while(rset->next()) {
240  p.first = EcalLogicID( getOraString(rset,1), // name
241  rset->getInt(2), // logic_id
242  rset->getInt(3), // id1
243  rset->getInt(4), // id2
244  rset->getInt(5), // id3
245  getOraString(rset,6)); // maps_to
246 
247  dat.setHV( rset->getFloat(7) );
248  dat.setHVNominal( rset->getFloat(8) );
249  Date sinceDate = rset->getDate(9);
250  Tm sinceTm = dh.dateToTm( sinceDate );
251  dat.setStatus(0);
252  if (p.first.getName() == "EB_HV_channel") {
253  setStatusForBarrel(dat, sinceTm);
254  } else {
255  setStatusForEndcaps(dat, sinceTm);
256  }
257  p.second = dat;
258  fillMap->insert(p);
259  }
260  }
261  catch (SQLException &e) {
262 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
263  throw(std::runtime_error(std::string("RunDCSHVDat::fetchData(): ")+getOraMessage(&e)));
264 #else
265  throw(std::runtime_error(std::string("RunDCSHVDat::fetchData(): error code ") + std::to_string(e.getErrorCode())));
266 #endif
267  }
268 }
269 
270 
271 
272 
275 
276  // std::list< std::pair< Tm, std::map< EcalLogicID, RunDCSHVDat > > >* fillMap) {
277 
278  // method for historic queries
279 
280  RunDCSHVDat dat;
281  DateHandler dh(m_env, m_conn);
282 
283 
284  try {
285  int count=-1;
286  while(rset->next()) {
287  EcalLogicID ec = EcalLogicID( getOraString(rset,1), // name
288  rset->getInt(2), // logic_id
289  rset->getInt(3), // id1
290  rset->getInt(4), // id2
291  rset->getInt(5), // id3
292  getOraString(rset,6)); // maps_to
293 
294 
295  dat.setHV( rset->getFloat(7) );
296  dat.setHVNominal( rset->getFloat(8) );
297  // Date sinceDate = rset->getDate(9);
298  // Tm sinceTm = dh.dateToTm( sinceDate );
299  // Date sinceDate = rset->getDate(9);
300  Timestamp ora_timestamp = rset->getTimestamp(9);
301  Tm sinceTm; // YYYY-MM-DD HH:MM:SS
302 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
303  sinceTm.setToString(ora_timestamp.toText("yyyy-mm-dd hh24:mi:ss",0));
304 #else
305  int year = 0;
306  unsigned int month = 0;
307  unsigned int day = 0;
308  unsigned int hour = 0;
309  unsigned int minute = 0;
310  unsigned int second = 0;
311  unsigned int fs = 0;
312  ora_timestamp.getDate(year, month, day);
313  ora_timestamp.getTime(hour, minute, second, fs);
314  const std::tm tt = {
315  .tm_sec = static_cast<int>(second),
316  .tm_min = static_cast<int>(minute),
317  .tm_hour = static_cast<int>(hour),
318  .tm_mday = static_cast<int>(day),
319  .tm_mon = static_cast<int>(month),
320  .tm_year = year - 1900
321  };
322  char tt_str[30] = { 0 };
323  if (std::strftime(tt_str, sizeof(tt_str), "%F %T", &tt)) {
324  sinceTm.setToString(std::string(tt_str));
325  } else {
326  throw std::runtime_error("RunDCSHVDat::fillTheMapByTime: failed to generate the date string");
327  }
328 #endif
329 
330  dat.setStatus(0);
331  if (ec.getName() == "EB_HV_channel") {
332  setStatusForBarrel(dat, sinceTm);
333  } else {
334  setStatusForEndcaps(dat, sinceTm);
335  }
336 
337  std::pair< EcalLogicID, RunDCSHVDat > d;
338  d.first=ec;
339  d.second=dat;
340  std::pair< Tm, std::pair< EcalLogicID, RunDCSHVDat > > p;
341  p.first=sinceTm;
342  p.second = d;
343 
345  pp.m_iData=p;
346 
347  my_data_list->push_back(pp);
348  count++;
349  if(count<100) std::cout<<"DCS DB : size:"<< my_data_list->size()<<" Tm " <<sinceTm.str()<<" "<<ec.getID1()<<" "<<ec.getID2()<<" "<<dat.getHV()<<std::endl;
350  }
351  std::cout<<"DCS DB : size:"<< my_data_list->size()<<std::endl;
352 
353 
354  }
355  catch (SQLException &e) {
356 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
357  throw(std::runtime_error(std::string("RunDCSHVDat::fetchData(): ")+getOraMessage(&e)));
358 #else
359  throw(std::runtime_error(std::string("RunDCSHVDat::fetchData(): error code ") + std::to_string(e.getErrorCode())));
360 #endif
361  }
362 }
363 
365  Tm t_now_gmt;
366 
367  t_now_gmt.setToCurrentGMTime();
368  int t_now_gmt_micros = t_now_gmt.microsTime();
369  return t_now_gmt_micros;
370 }
371 
372 
373 
374 void RunDCSHVDat::setStatusForBarrel(RunDCSHVDat &dat, const Tm& sinceTm) {
375  int t_now_gmt_micros = nowMicroseconds();
376 
377  float hv_diff=dat.getHV() - dat.getHVNominal();
378  if(hv_diff<0) hv_diff=-hv_diff;
379  if (hv_diff*1000 > maxHVDifferenceEB) {
380  dat.setStatus(HVNOTNOMINAL);
381  }
382  if (dat.getHV()*1000 < minHV) {
383  dat.setStatus(HVOFF);
384  }
385 
386  int result=0;
387  long long d= (t_now_gmt_micros - sinceTm.microsTime()) ;
388  if (d> maxDifference) {
389  result= -d/1000000 ;
390  }
391  dat.setTimeStatus(result);
392 
393 
394 }
395 
396 void RunDCSHVDat::setStatusForEndcaps(RunDCSHVDat &dat, const Tm& sinceTm) {
397  int t_now_gmt_micros = nowMicroseconds();
398 
399  if (fabs(dat.getHV() - dat.getHVNominal())*1000 > maxHVDifferenceEE) {
400  dat.setStatus(HVNOTNOMINAL);
401  }
402  if (dat.getHV()*1000 < minHV) {
403  dat.setStatus(HVOFF);
404  }
405 
406  int result=0;
407  long long d= (t_now_gmt_micros - sinceTm.microsTime()) ;
408  if (d> maxDifference) {
409  result= -d/1000000 ;
410  }
411  dat.setTimeStatus(result);
412 }
413 
414 void RunDCSHVDat::fetchLastData(map< EcalLogicID, RunDCSHVDat >* fillMap )
415  noexcept(false)
416 {
417  this->checkConnection();
418 
419  fillMap->clear();
420 
421  try {
422  std::pair< EcalLogicID, RunDCSHVDat > p;
423  RunDCSHVDat dat;
424 
425  ResultSet* rset = getBarrelRset();
426 
427  fillTheMap(rset, fillMap);
428  rset = getEndcapAnodeRset();
429 
430  fillTheMap(rset, fillMap);
431  rset = getEndcapDynodeRset();
432 
433  fillTheMap(rset, fillMap);
434  }
435  catch (SQLException &e) {
436 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
437  throw(std::runtime_error(std::string("RunDCSHVDat::fetchData(): ")+getOraMessage(&e)));
438 #else
439  throw(std::runtime_error(std::string("RunDCSHVDat::fetchData(): error code ") + std::to_string(e.getErrorCode())));
440 #endif
441  }
442 }
443 
444 void RunDCSHVDat::fetchHistoricalData(std::list< std::pair<Tm, std::map< EcalLogicID, RunDCSHVDat > > >* fillMap, const Tm& timeStart )
445  noexcept(false)
446 {
447  this->checkConnection();
448 
449  fillMap->clear();
450 
451  std::list< DataReducer<RunDCSHVDat>::MyData<RunDCSHVDat> > my_data_list;
452 
453 
454  try {
455 
456  std::pair< EcalLogicID, RunDCSHVDat > p;
457  RunDCSHVDat dat;
458 
459  ResultSet* rset1 = getBarrelRset(timeStart);
460  fillTheMapByTime(rset1, &my_data_list);
461 
462  ResultSet* rset2 = getEndcapAnodeRset(timeStart);
463  fillTheMapByTime(rset2, &my_data_list);
464 
465  ResultSet* rset3 = getEndcapDynodeRset(timeStart);
466  fillTheMapByTime(rset3, &my_data_list);
467 
468 
470  my_dr.setDataList(my_data_list);
471  my_dr.getReducedDataList(fillMap);
472 
473 
474  }
475  catch (SQLException &e) {
476 #if defined(_GLIBCXX_USE_CXX11_ABI) && (_GLIBCXX_USE_CXX11_ABI == 0)
477  throw(std::runtime_error(std::string("RunDCSHVDat::fetchData(): ")+getOraMessage(&e)));
478 #else
479  throw(std::runtime_error(std::string("RunDCSHVDat::fetchData(): error code ") + std::to_string(e.getErrorCode())));
480 #endif
481  }
482 }
void setDataList(std::list< MyData< T > > _list)
Definition: DataReducer.h:60
oracle::occi::ResultSet ResultSet
Definition: RunDCSHVDat.h:17
float getHVNominal() const
Definition: RunDCSHVDat.h:39
void setStatusForEndcaps(RunDCSHVDat &, const Tm &)
Definition: RunDCSHVDat.cc:396
ResultSet * getEndcapDynodeRset()
Definition: RunDCSHVDat.cc:208
void writeDB(const EcalLogicID *ecid, const RunDCSHVDat *item, RunIOV *iov) noexcept(false)
Definition: RunDCSHVDat.cc:46
ResultSet * getEndcapAnodeRset()
Definition: RunDCSHVDat.cc:187
#define noexcept
ResultSet * getBarrelRset()
Definition: RunDCSHVDat.cc:166
void fetchHistoricalData(std::list< std::pair< Tm, std::map< EcalLogicID, RunDCSHVDat > > > *fillMap, const Tm &timeStart) noexcept(false)
Definition: RunDCSHVDat.cc:444
void setToCurrentGMTime()
Definition: Tm.cc:177
void fetchData(std::map< EcalLogicID, RunDCSHVDat > *fillMap, RunIOV *iov) noexcept(false)
Definition: RunDCSHVDat.cc:53
~RunDCSHVDat() override
Definition: RunDCSHVDat.cc:31
void setStatusForBarrel(RunDCSHVDat &, const Tm &)
Definition: RunDCSHVDat.cc:374
int getID2() const
Definition: EcalLogicID.cc:51
Definition: query.py:1
uint64_t microsTime() const
Definition: Tm.cc:126
U second(std::pair< T, U > const &p)
std::string getName() const
Definition: EcalLogicID.cc:36
int getID1() const
Definition: EcalLogicID.cc:46
oracle::occi::Date tmToDate(const Tm &inTm) const
Definition: DateHandler.cc:20
void getReducedDataList(std::list< std::pair< Tm, DataMap > > *my_new_list)
Definition: DataReducer.h:67
void fetchLastData(std::map< EcalLogicID, RunDCSHVDat > *fillMap) noexcept(false)
Definition: RunDCSHVDat.cc:414
void prepareWrite() noexcept(false) override
Definition: RunDCSHVDat.cc:37
void setTimeStatus(int t)
Definition: RunDCSHVDat.h:42
void setToString(const std::string s) noexcept(false)
Definition: Tm.cc:193
void setStatus(int t)
Definition: RunDCSHVDat.h:36
void setHVNominal(float t)
Definition: RunDCSHVDat.h:37
void fillTheMapByTime(ResultSet *rset, std::list< DataReducer< RunDCSHVDat >::MyData< RunDCSHVDat > > *my_data_list)
Definition: RunDCSHVDat.cc:273
std::string str() const
Definition: Tm.cc:89
def day(string)
Definition: getRunInfo.py:11
void fillTheMap(ResultSet *, std::map< EcalLogicID, RunDCSHVDat > *)
Definition: RunDCSHVDat.cc:229
int nowMicroseconds()
Definition: RunDCSHVDat.cc:364
void setHV(float t)
Definition: RunDCSHVDat.h:35
dh
Definition: cuy.py:353
Definition: RunIOV.h:13
Tm dateToTm(oracle::occi::Date &date) const
Definition: DateHandler.cc:31
Definition: Tm.h:13
float getHV() const
Definition: RunDCSHVDat.h:38
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run