CMS 3D CMS Logo

EcalDCSHandler.cc
Go to the documentation of this file.
4 
7 
8 #include <iostream>
9 
11  : m_name(ps.getUntrackedParameter<std::string>("name", "EcalDCSHandler")) {
12  std::cout << "EcalDCS Source handler constructor\n" << std::endl;
13  m_firstRun = (unsigned long)atoi(ps.getParameter<std::string>("firstRun").c_str());
14  m_lastRun = (unsigned long)atoi(ps.getParameter<std::string>("lastRun").c_str());
15  m_sid = ps.getParameter<std::string>("OnlineDBSID");
16  m_user = ps.getParameter<std::string>("OnlineDBUser");
17  m_pass = ps.getParameter<std::string>("OnlineDBPassword");
18 
19  std::cout << m_sid << "/" << m_user << std::endl;
20 }
21 
23 
24 void popcon::EcalDCSHandler::printHVDataSet(const std::map<EcalLogicID, RunDCSHVDat>* dataset, int limit = 0) const {
25  std::cout << "==========printDataSet()" << std::endl;
26  if (dataset->empty()) {
27  std::cout << "No data in map!" << std::endl;
28  }
29  EcalLogicID ecid;
30  RunDCSHVDat hv;
31 
32  int count = 0;
33  typedef std::map<EcalLogicID, RunDCSHVDat>::const_iterator CI;
34  for (CI p = dataset->begin(); p != dataset->end(); ++p) {
35  count++;
36  if (limit && count > limit) {
37  return;
38  }
39  ecid = p->first;
40  hv = p->second;
41 
42  std::cout << "SM: " << ecid.getID1() << std::endl;
43  std::cout << "Channel: " << ecid.getID2() << std::endl;
44  std::cout << "HV: " << hv.getHV() << std::endl;
45  std::cout << "HV nominal: " << hv.getHVNominal() << std::endl;
46  std::cout << "HV status: " << hv.getStatus() << std::endl;
47  std::cout << "========================" << std::endl;
48  }
49  std::cout << std::endl;
50 }
51 
52 void popcon::EcalDCSHandler::printLVDataSet(const std::map<EcalLogicID, RunDCSLVDat>* dataset, int limit = 0) const {
53  std::cout << "==========printDataSet()" << std::endl;
54  if (dataset->empty()) {
55  std::cout << "No data in map!" << std::endl;
56  }
57  EcalLogicID ecid;
58  RunDCSLVDat lv;
59 
60  int count = 0;
61  typedef std::map<EcalLogicID, RunDCSLVDat>::const_iterator CI;
62  for (CI p = dataset->begin(); p != dataset->end(); ++p) {
63  count++;
64  if (limit && count > limit) {
65  return;
66  }
67  ecid = p->first;
68  lv = p->second;
69 
70  std::cout << "SM: " << ecid.getID1() << std::endl;
71  std::cout << "Channel: " << ecid.getID2() << std::endl;
72  std::cout << "LV: " << lv.getLV() << std::endl;
73  std::cout << "LV nominal: " << lv.getLVNominal() << std::endl;
74  std::cout << "LV status: " << lv.getStatus() << std::endl;
75  std::cout << "========================" << std::endl;
76  }
77  std::cout << std::endl;
78 }
79 
80 uint16_t popcon::EcalDCSHandler::OffDBStatus(uint16_t dbStatus, int pos) {
81  uint16_t hv_off_dbstatus = (dbStatus & (1 << pos));
82  if (hv_off_dbstatus > 0)
83  hv_off_dbstatus = 1;
84  return hv_off_dbstatus;
85 }
86 
87 uint16_t popcon::EcalDCSHandler::updateHV(RunDCSHVDat* hv, uint16_t dbStatus, int mode) const {
88  // mode ==0 EB , mode==1 EE Anode , mode==2 EE Dynode
89 
90  uint16_t result = 0;
91  uint16_t hv_on_dbstatus = 0;
92  uint16_t hv_nomi_on_dbstatus = 0;
93 
95  hv_nomi_on_dbstatus = 1;
96  if (hv->getStatus() == RunDCSHVDat::HVOFF)
97  hv_on_dbstatus = 1;
98 
99  uint16_t temp = 0;
100 
101  if (mode == 0 || mode == 1) {
102  for (int i = 0; i < 16; i++) {
104  temp = temp | (1 << i);
105  } else {
106  temp = temp | (0 << i);
107  }
108  }
109  result = dbStatus & temp;
110  result = (result | (hv_on_dbstatus << EcalDCSTowerStatusHelper::HVSTATUS)) |
111  (hv_nomi_on_dbstatus << EcalDCSTowerStatusHelper::HVNOMINALSTATUS);
112  } else {
113  for (int i = 0; i < 16; i++) {
115  temp = temp | (1 << i);
116  } else {
117  temp = temp | (0 << i);
118  }
119  }
120  result = dbStatus & temp;
121  result = (result | (hv_on_dbstatus << EcalDCSTowerStatusHelper::HVEEDSTATUS)) |
122  (hv_nomi_on_dbstatus << EcalDCSTowerStatusHelper::HVEEDNOMINALSTATUS);
123  }
124 
125  return result;
126 }
127 
128 uint16_t popcon::EcalDCSHandler::updateLV(RunDCSLVDat* lv, uint16_t dbStatus) const {
129  uint16_t result = 0;
130  uint16_t lv_on_dbstatus = 0;
131  uint16_t lv_nomi_on_dbstatus = 0;
133  lv_nomi_on_dbstatus = 1;
134  if (lv->getStatus() == RunDCSLVDat::LVOFF)
135  lv_on_dbstatus = 1;
136 
137  uint16_t temp = 0;
138  for (int i = 0; i < 16; i++) {
140  temp = temp | (1 << i);
141  } else {
142  temp = temp | (0 << i);
143  }
144  }
145 
146  result = dbStatus & temp;
147  result = (result | (lv_on_dbstatus << EcalDCSTowerStatusHelper::LVSTATUS)) |
148  (lv_nomi_on_dbstatus << EcalDCSTowerStatusHelper::LVNOMINALSTATUS);
149 
150  return result;
151 }
152 
153 bool popcon::EcalDCSHandler::insertHVDataSetToOffline(const std::map<EcalLogicID, RunDCSHVDat>* dataset,
154  EcalDCSTowerStatus* dcs_temp) const {
155  bool result = false;
156  if (dataset->empty()) {
157  std::cout << "No data in std::map!" << std::endl;
158  }
159  EcalLogicID ecid;
160  RunDCSHVDat hv;
161 
162  typedef std::map<EcalLogicID, RunDCSHVDat>::const_iterator CI;
163 
164  for (CI p = dataset->begin(); p != dataset->end(); ++p) {
165  ecid = p->first;
166  hv = p->second;
167 
168  if (ecid.getName() == "EB_HV_channel") {
169  int sm = ecid.getID1();
170  int chan = ecid.getID2();
171 
172  int* limits = nullptr;
173  limits = HVLogicIDToDetID(sm, chan);
174  int iz = limits[0];
175  int i1 = limits[1];
176  int i2 = limits[2];
177  int j = limits[3];
178 
179  for (int ik = i1; ik <= i2; ik++) {
181  EcalTrigTowerDetId ebid(iz, EcalBarrel, j, ik);
182  EcalDCSTowerStatus::const_iterator it = dcs_temp->find(ebid.rawId());
183 
184  uint16_t dbStatus = 0;
185  if (it != dcs_temp->end()) {
186  dbStatus = it->getStatusCode();
187  }
188  int modo = 0;
189  uint16_t new_dbStatus = updateHV(&hv, dbStatus, modo);
190  if (new_dbStatus != dbStatus)
191  result = true;
192 
193  dcs_temp->setValue(ebid, new_dbStatus);
194 
195  if (new_dbStatus != dbStatus) {
196  std::cout << "SM/chan:" << sm << "/" << chan << " new db status =" << new_dbStatus << " old " << dbStatus
197  << " HV: " << hv.getHV() << "/" << hv.getHVNominal() << std::endl;
198  }
199  }
200  }
201  delete[] limits;
202  } else {
203  // endcaps
204  int dee = ecid.getID1();
205  int chan = ecid.getID2();
206 
207  int* limits = nullptr;
208  limits = HVEELogicIDToDetID(dee, chan);
209  int iz = limits[0];
210  int i1 = limits[1];
211  int i2 = limits[2];
212  int j1 = limits[3];
213  int j2 = limits[4];
214 
215  int ex_x[6];
216  int ex_y[6];
217  if (dee == 1) {
218  ex_x[0] = 4;
219  ex_y[0] = 8;
220  ex_x[1] = 4;
221  ex_y[1] = 9;
222  ex_x[2] = 4;
223  ex_y[2] = 10;
224  ex_x[3] = 5;
225  ex_y[3] = 9;
226  ex_x[4] = 5;
227  ex_y[4] = 10;
228  ex_x[5] = 6;
229  ex_y[5] = 10;
230  } else if (dee == 2) {
231  ex_x[0] = 17;
232  ex_y[0] = 11;
233  ex_x[1] = 17;
234  ex_y[1] = 12;
235  ex_x[2] = 17;
236  ex_y[2] = 13;
237  ex_x[3] = 16;
238  ex_y[3] = 11;
239  ex_x[4] = 16;
240  ex_y[4] = 12;
241  ex_x[5] = 15;
242  ex_y[5] = 11;
243  } else if (dee == 3) {
244  ex_x[0] = 17;
245  ex_y[0] = 8;
246  ex_x[1] = 17;
247  ex_y[1] = 9;
248  ex_x[2] = 17;
249  ex_y[2] = 10;
250  ex_x[3] = 16;
251  ex_y[3] = 9;
252  ex_x[4] = 16;
253  ex_y[4] = 10;
254  ex_x[5] = 15;
255  ex_y[5] = 10;
256  } else if (dee == 4) {
257  ex_x[0] = 4;
258  ex_y[0] = 11;
259  ex_x[1] = 4;
260  ex_y[1] = 12;
261  ex_x[2] = 4;
262  ex_y[2] = 13;
263  ex_x[3] = 5;
264  ex_y[3] = 11;
265  ex_x[4] = 5;
266  ex_y[4] = 12;
267  ex_x[5] = 6;
268  ex_y[5] = 11;
269  } else {
270  throw cms::Exception("Invalid EcalLogicID") << "Unknown ECAL Endcap Dee number " << dee;
271  }
272 
273  int modo = 1;
274  if (ecid.getName() == "EE_HVD_channel")
275  modo = 2;
276 
277  for (int ik = i1; ik <= i2; ik++) {
278  for (int ip = j1; ip <= j2; ip++) {
279  bool not_excluded = true;
280  if (chan == 2) { // channel 2 has half a dee minus 6 towers
281  for (int l = 0; l < 6; l++) {
282  if (ik == ex_x[l] && ip == ex_y[l])
283  not_excluded = false;
284  }
285  }
286  if (not_excluded) {
287  if (EcalScDetId::validDetId(ik, ip, iz)) {
288  EcalScDetId eeid(ik, ip, iz);
289  EcalDCSTowerStatus::const_iterator it = dcs_temp->find(eeid.rawId());
290 
291  uint16_t dbStatus = 0;
292  if (it != dcs_temp->end()) {
293  dbStatus = it->getStatusCode();
294  }
295  // FIXME - UPDATE HV A and D
296  uint16_t new_dbStatus = updateHV(&hv, dbStatus, modo);
297  if (new_dbStatus != dbStatus)
298  result = true;
299 
300  dcs_temp->setValue(eeid, new_dbStatus);
301 
302  if (new_dbStatus != dbStatus) {
303  std::cout << "Dee/chan:" << dee << "/" << chan << " new db status =" << new_dbStatus << " old "
304  << dbStatus << " HV: " << hv.getHV() << "/" << hv.getHVNominal() << std::endl;
305  } // if (new_dbStatus != dbStatus)
306  } // if (EcalScDetId::validDetId(ik, ip, iz))
307  } // if (not_excluded)
308  } // for (int ip = j1; ip <= j2; ip++)
309  } // for (int ik = i1; ik <= i2; ik++)
310  if (chan == 1) { // channel 1 has half a dee plus 6 more towers
311  for (int l = 0; l < 6; l++) {
312  int ik = ex_x[l];
313  int ip = ex_y[l];
314  if (EcalScDetId::validDetId(ik, ip, iz)) {
315  EcalScDetId eeid(ik, ip, iz);
316  EcalDCSTowerStatus::const_iterator it = dcs_temp->find(eeid.rawId());
317 
318  uint16_t dbStatus = 0;
319  if (it != dcs_temp->end()) {
320  dbStatus = it->getStatusCode();
321  }
322  uint16_t new_dbStatus = updateHV(&hv, dbStatus, modo);
323  if (new_dbStatus != dbStatus)
324  result = true;
325 
326  dcs_temp->setValue(eeid, new_dbStatus);
327 
328  if (new_dbStatus != dbStatus) {
329  std::cout << "Dee/chan:" << dee << "/" << chan << " new db status =" << new_dbStatus << " old "
330  << dbStatus << " HV: " << hv.getHV() << "/" << hv.getHVNominal() << std::endl;
331  }
332  }
333  }
334  }
335 
336  delete[] limits;
337  }
338  }
339  return result;
340 }
341 
343  // returns the number from 0 to 1223 from SM1 to 36 from ch 1 to 34
344 
345  int sm = 0;
346  int hv_chan = 0;
347 
348  sm = (i - 1) / 4;
349  if (iz < 0)
350  sm = sm + 18;
351 
352  int ilocal = (i - 1) - sm * 4;
353  if (iz < 0) {
354  if (ilocal == 0 || ilocal == 1)
355  hv_chan = 1;
356  if (ilocal == 2 || ilocal == 3)
357  hv_chan = 2;
358  } else {
359  if (ilocal == 0 || ilocal == 1)
360  hv_chan = 2;
361  if (ilocal == 2 || ilocal == 3)
362  hv_chan = 1;
363  }
364 
365  sm = sm + 1;
366 
367  hv_chan = (j - 1) * 2 + hv_chan;
368 
369  hv_chan = (sm - 1) * 34 + hv_chan - 1;
370 
371  return hv_chan;
372 }
373 
375  int iz = -1;
376  if (dee == 1 || dee == 2)
377  iz = 1;
378  int ix1 = 1;
379  int ix2 = 1;
380  int iy1 = 1;
381  int iy2 = 1;
382 
383  if (dee == 1 && chan == 1) {
384  ix1 = 1;
385  ix2 = 10;
386  iy1 = 11;
387  iy2 = 20;
388  } else if (dee == 2 && chan == 1) {
389  ix1 = 11;
390  ix2 = 20;
391  iy1 = 1;
392  iy2 = 10;
393  } else if (dee == 3 && chan == 1) {
394  ix1 = 11;
395  ix2 = 20;
396  iy1 = 11;
397  iy2 = 20;
398  } else if (dee == 4 && chan == 1) {
399  ix1 = 1;
400  ix2 = 10;
401  iy1 = 1;
402  iy2 = 10;
403  } else if (dee == 1 && chan == 2) {
404  ix1 = 1;
405  ix2 = 10;
406  iy1 = 1;
407  iy2 = 10;
408  } else if (dee == 2 && chan == 2) {
409  ix1 = 11;
410  ix2 = 20;
411  iy1 = 11;
412  iy2 = 20;
413  } else if (dee == 3 && chan == 2) {
414  ix1 = 11;
415  ix2 = 20;
416  iy1 = 1;
417  iy2 = 10;
418  } else if (dee == 4 && chan == 2) {
419  ix1 = 1;
420  ix2 = 10;
421  iy1 = 11;
422  iy2 = 20;
423  }
424 
425  int* result = new int[5];
426 
427  result[0] = iz;
428  result[1] = ix1;
429  result[2] = ix2;
430  result[3] = iy1;
431  result[4] = iy2;
432  return result;
433 }
434 
436  // returns the numbers iz, i1, i2 and j1, j2 on which to loop for the towers
437 
438  int iz = -1;
439  if (sm > 0 && sm <= 18)
440  iz = 1;
441  int j = (chan - 1) / 2 + 1;
442  int i_local_hv = (chan - 1) - (j - 1) * 2 + 1; // this gives 1 for odd channels and 2 for even channels
443  int i1 = 0;
444  int i2 = 0;
445  if (iz > 0) { // EB plus phi turns opposite to HV numbering
446  if (i_local_hv == 1) {
447  i1 = 3;
448  i2 = 4;
449  } else {
450  i1 = 1;
451  i2 = 2;
452  }
453  } else { // EB minus phi turns as HV numbering
454  if (i_local_hv == 1) {
455  i1 = 1;
456  i2 = 2;
457  } else {
458  i1 = 3;
459  i2 = 4;
460  }
461  }
462  int ioffset = 0;
463  if (iz == 1)
464  ioffset = (sm - 1) * 4;
465  if (iz == -1)
466  ioffset = (sm - 18 - 1) * 4;
467  i1 = i1 + ioffset;
468  i2 = i2 + ioffset;
469 
470  int* result = new int[5];
471 
472  result[0] = iz;
473  result[1] = i1;
474  result[2] = i2;
475  result[3] = j;
476  result[4] = j;
477 
478  return result;
479 }
480 
482  // returns the numbers iz, i1, i2 and j1, j2 on which to loop for the towers
483 
484  int iz = -1;
485  if (sm > 0 && sm <= 18)
486  iz = 1;
487 
488  int j1 = 0;
489  int j2 = 0;
490  int i1 = 0;
491  int i2 = 0;
492 
493  if (chan == 1) {
494  i1 = 1;
495  i2 = 4;
496  j1 = 1;
497  j2 = 1;
498  } else {
499  int ch2 = (chan / 2) * 2;
500  if (ch2 == chan) {
501  j1 = chan;
502  } else {
503  j1 = chan - 1;
504  }
505  j2 = j1 + 1;
506  if (iz > 0) { // EB plus phi turns opposite to LV numbering
507  if (ch2 == chan) {
508  i1 = 3;
509  i2 = 4;
510  } else {
511  i1 = 1;
512  i2 = 2;
513  }
514  } else { // EB minus phi turns as LV numbering
515  if (ch2 == chan) {
516  i1 = 1;
517  i2 = 2;
518  } else {
519  i1 = 3;
520  i2 = 4;
521  }
522  }
523  }
524  int ioffset = 0;
525  if (iz == 1)
526  ioffset = (sm - 1) * 4;
527  if (iz == -1)
528  ioffset = (sm - 18 - 1) * 4;
529  i1 = i1 + ioffset;
530  i2 = i2 + ioffset;
531 
532  int* result = new int[5];
533  result[0] = iz;
534  result[1] = i1;
535  result[2] = i2;
536  result[3] = j1;
537  result[4] = j2;
538 
539  return result;
540 }
541 
542 bool popcon::EcalDCSHandler::insertLVDataSetToOffline(const std::map<EcalLogicID, RunDCSLVDat>* dataset,
543  EcalDCSTowerStatus* dcs_temp,
544  const std::vector<EcalLogicID>& my_EELVchan) const {
545  bool result = false;
546  if (dataset->empty()) {
547  std::cout << "No data in map!" << std::endl;
548  }
549  EcalLogicID ecid;
550  RunDCSLVDat lv;
551 
552  typedef std::map<EcalLogicID, RunDCSLVDat>::const_iterator CI;
553  for (CI p = dataset->begin(); p != dataset->end(); ++p) {
554  ecid = p->first;
555  lv = p->second;
556 
557  if (ecid.getName() == "EB_LV_channel") {
558  int sm = ecid.getID1();
559  int chan = ecid.getID2();
560 
561  int* limits = nullptr;
562  limits = LVLogicIDToDetID(sm, chan);
563  int iz = limits[0];
564  int i1 = limits[1];
565  int i2 = limits[2];
566  int j1 = limits[3];
567  int j2 = limits[4];
568 
569  for (int ik = i1; ik <= i2; ik++) {
570  for (int j = j1; j <= j2; j++) {
572  EcalTrigTowerDetId ebid(iz, EcalBarrel, j, ik);
573  EcalDCSTowerStatus::const_iterator it = dcs_temp->find(ebid.rawId());
574  uint16_t dbStatus = 0;
575  if (it != dcs_temp->end()) {
576  dbStatus = it->getStatusCode();
577  }
578  uint16_t new_dbStatus = updateLV(&lv, dbStatus);
579  if (new_dbStatus != dbStatus)
580  result = true;
581  dcs_temp->setValue(ebid, new_dbStatus);
582 
583  if (new_dbStatus != dbStatus) {
584  std::cout << "SM/chan:" << sm << "/" << chan << " new db status =" << new_dbStatus << " old " << dbStatus
585  << " LV: " << lv.getLV() << "/" << lv.getLVNominal() << std::endl;
586  }
587  }
588  }
589  }
590  delete[] limits;
591 
592  } else {
593  // endcaps
594  int dee = ecid.getID1();
595  int chan = ecid.getID2();
596  int n = my_EELVchan.size();
597 
598  for (int ixt = 0; ixt < n; ixt++) {
599  if (my_EELVchan[ixt].getID1() == dee && my_EELVchan[ixt].getID2() == chan) {
600  int ilogic = my_EELVchan[ixt].getLogicID();
601 
602  if (ilogic == 2012058060 || ilogic == 2010060058 || ilogic == 2012043041 || ilogic == 2010041043) {
603  std::cout << "crystal " << ilogic << " in the corner ignored" << std::endl;
604  } else {
605  int iz = (ilogic / 1000000) - 2010;
606  if (iz == 0)
607  iz = -1;
608  if (iz == 2)
609  iz = 1;
610  if (iz != 1 && iz != -1)
611  std::cout << "BAD z" << std::endl;
612 
613  int iy = ilogic - int(ilogic / 1000) * 1000;
614 
615  int ix = (ilogic - int(ilogic / 1000000) * 1000000 - iy) / 1000;
616 
617  int ixtower = ((ix - 1) / 5) + 1;
618  int iytower = ((iy - 1) / 5) + 1;
619 
620  if (ixtower < 1 || ixtower > 20 || iytower < 1 || iytower > 20)
621  std::cout << "BAD x/y" << ilogic << "/" << ixtower << "/" << iytower << std::endl;
622 
623  if (EcalScDetId::validDetId(ixtower, iytower, iz)) {
624  EcalScDetId eeid(ixtower, iytower, iz);
625  EcalDCSTowerStatus::const_iterator it = dcs_temp->find(eeid.rawId());
626  uint16_t dbStatus = 0;
627  if (it != dcs_temp->end()) {
628  dbStatus = it->getStatusCode();
629  }
630 
631  uint16_t new_dbStatus = updateLV(&lv, dbStatus);
632  if (new_dbStatus != dbStatus)
633  result = true;
634  dcs_temp->setValue(eeid, new_dbStatus);
635 
636  // std::cout <<"Dee/chan:"<<dee<<"/"<<chan <<" new db status ="<< new_dbStatus << " old "<<dbStatus<<" LV: "<< lv.getLV()<<"/"<<lv.getLVNominal()<<" ilogic/x/y " <<ilogic<<"/"<< ixtower<<"/"<<iytower<<std::endl;
637 
638  if (new_dbStatus != dbStatus) {
639  std::cout << "Dee/chan:" << dee << "/" << chan << " new db status =" << new_dbStatus << " old "
640  << dbStatus << " LV: " << lv.getLV() << "/" << lv.getLVNominal() << std::endl;
641  }
642  }
643  }
644  }
645  }
646 
647  } // end of endcaps
648  }
649  return result;
650 }
651 
653  bool lot_of_printout = false;
654  std::cout << "------- Ecal DCS - > getNewObjects\n";
655 
656  std::ostringstream ss;
657  ss << "ECAL ";
658 
659  unsigned long long max_since = 1;
660 
661  // we copy the last valid record to a temporary object
662  EcalDCSTowerStatus* dcs_temp = new EcalDCSTowerStatus();
663  if (tagInfo().size) {
664  max_since = tagInfo().lastInterval.since;
665  Ref dcs_db = lastPayload();
666  std::cout << "retrieved last payload " << std::endl;
667 
668  // barrel
669  int iz = 0;
670  for (int k = 0; k < 2; k++) {
671  if (k == 0)
672  iz = -1;
673  if (k == 1)
674  iz = 1;
675  for (int i = 1; i < 73; i++) {
676  for (int j = 1; j < 18; j++) {
678  EcalTrigTowerDetId ebid(iz, EcalBarrel, j, i);
679 
680  uint16_t dbStatus = 0;
681  dbStatus = (dcs_db->barrel(ebid.hashedIndex())).getStatusCode();
682 
683  EcalDCSTowerStatus::const_iterator it = dcs_db->find(ebid.rawId());
684  if (it != dcs_db->end()) {
685  } else {
686  std::cout << "*** error channel not found: j/i=" << j << "/" << i << std::endl;
687  }
688  dcs_temp->setValue(ebid, dbStatus);
689  }
690  }
691  }
692  }
693 
694  // endcap
695  for (int k = 0; k < 2; k++) {
696  if (k == 0)
697  iz = -1;
698  if (k == 1)
699  iz = +1;
700  for (int i = 1; i < 21; i++) {
701  for (int j = 1; j < 21; j++) {
702  if (EcalScDetId::validDetId(i, j, iz)) {
703  EcalScDetId eeid(i, j, iz);
704 
705  EcalDCSTowerStatus::const_iterator it = dcs_db->find(eeid.rawId());
706 
707  uint16_t dbStatus = 0;
708  if (it != dcs_db->end()) {
709  dbStatus = it->getStatusCode();
710  }
711  dcs_temp->setValue(eeid, dbStatus);
712  }
713  }
714  }
715  }
716  } // check if there is already a payload
717  else {
718  int iz = -1;
719  for (int k = 0; k < 2; k++) {
720  if (k == 1)
721  iz = 1;
722  // barrel
723  for (int i = 1; i < 73; i++) {
724  for (int j = 1; j < 18; j++) {
726  EcalTrigTowerDetId ebid(iz, EcalBarrel, j, i);
727  dcs_temp->setValue(ebid, 0);
728  }
729  }
730  }
731  // endcap
732  for (int i = 1; i < 21; i++) {
733  for (int j = 1; j < 21; j++) {
734  if (EcalScDetId::validDetId(i, j, iz)) {
735  EcalScDetId eeid(i, j, iz);
736  dcs_temp->setValue(eeid, 0);
737  }
738  }
739  }
740  }
741  }
742  std::cout << "max_since : " << max_since << std::endl;
743 
744  // now read the actual status from the online DB
745  econn = new EcalCondDBInterface(m_sid, m_user, m_pass);
746  std::cout << "Connection done" << std::endl;
747 
748  if (!econn) {
749  std::cout << " Problem with OMDS: connection parameters " << m_sid << "/" << m_user << std::endl;
750  throw cms::Exception("OMDS not available");
751  }
752 
753  std::cout << "Retrieving last run from ONLINE DB ... " << std::endl;
754  std::map<EcalLogicID, RunDat> rundat;
755  RunIOV rp;
756  run_t runmax = 10000000;
757  std::string location_p5 = "P5_Co";
758  econn->fetchValidDataSet(&rundat, &rp, location_p5, runmax);
759 
760  unsigned long long irun = (unsigned long long)rp.getRunNumber();
761 
762  // just for testing purposes
763  // irun= max_since+1;
764 
765  if (max_since < irun) {
766  // get the map of the EE LV channels to EE crystals
767 
768  std::cout << "Retrieving endcap channel list from ONLINE DB ... " << std::endl;
769 
770  std::vector<EcalLogicID> my_EELVchan = econn->getEcalLogicIDSetOrdered(
771  "EE_crystal_number", 1, 4, 1, 200, EcalLogicID::NULLID, EcalLogicID::NULLID, "EE_LV_channel", 12);
772 
773  std::cout << "done endcap channel list ... " << std::endl;
774 
775  // retrieve from last value data record
776  // always call this method at first run
777 
778  std::map<EcalLogicID, RunDCSHVDat> dataset;
779  RunIOV* r = nullptr;
780  econn->fetchDataSet(&dataset, r);
781 
782  if (dataset.empty()) {
783  throw(std::runtime_error("Zero rows read back"));
784  }
785 
786  if (lot_of_printout)
787  std::cout << "read OK" << std::endl;
788  if (lot_of_printout)
789  printHVDataSet(&dataset, 10);
790 
791  std::map<EcalLogicID, RunDCSLVDat> dataset_lv;
792  econn->fetchDataSet(&dataset_lv, r);
793 
794  if (dataset_lv.empty()) {
795  throw(std::runtime_error("Zero rows read back"));
796  }
797  if (lot_of_printout)
798  std::cout << "read OK" << std::endl;
799  if (lot_of_printout)
800  printLVDataSet(&dataset_lv);
801 
802  bool somediff_hv = insertHVDataSetToOffline(&dataset, dcs_temp);
803  bool somediff_lv = insertLVDataSetToOffline(&dataset_lv, dcs_temp, my_EELVchan);
804 
805  if (somediff_hv || somediff_lv) {
806  /* Tm t_now_gmt;
807  t_now_gmt.setToCurrentGMTime();
808  uint64_t tsincetemp= t_now_gmt.microsTime()/1000000 ;
809  uint64_t tsince = tsincetemp<< 32;
810  std::cout << "Generating popcon record for time " << tsincetemp << "..." << std::flush;
811 
812  */
813 
814  std::cout << "Generating popcon record for run " << irun << "..." << std::flush;
815 
816  // this is for timestamp
817  // m_to_transfer.push_back(std::make_pair((EcalDCSTowerStatus*)dcs_temp,tsince));
818  // ss << "Time=" << t_now_gmt.str() << "_DCSchanged_"<<std::endl;
819 
820  // this is for run number
821  m_to_transfer.push_back(std::make_pair((EcalDCSTowerStatus*)dcs_temp, irun));
822  ss << "Run=" << irun << "_DCSchanged_" << std::endl;
823 
824  m_userTextLog = ss.str() + ";";
825 
826  } else {
827  // Tm t_now_gmt;
828  // t_now_gmt.setToCurrentGMTime();
829 
830  std::cout << "Run " << irun << " DCS record was the same as previous run " << std::endl;
831  ss << "Run=" << irun << "_DCSchanged_" << std::endl;
832  m_userTextLog = ss.str() + ";";
833 
834  delete dcs_temp;
835  }
836 
837  /*
838 
839  } else {
840 
841  // here we fetch historical data
842 
843  uint64_t t_max_val= ((max_since >> 32 ) +2)*1000000 ; // time in microseconds (2 seconds more than old data)
844 
845  Tm t_test(t_max_val);
846 
847  std::list< std::pair< Tm, std::map< EcalLogicID, RunDCSHVDat > > > dataset;
848  econn->fetchDCSDataSet(&dataset, t_test);
849 
850  if (!dataset.size()) {
851  std::cout<< " DCS query retrieved zero lines "<< std::endl;
852  } else {
853 
854  int num_dcs=0;
855  std::list< std::pair< Tm, std::map< EcalLogicID, RunDCSHVDat > > >::iterator it;
856  for (it=dataset.begin(); it!=dataset.end(); ++it){
857  std::pair< Tm, std::map< EcalLogicID, RunDCSHVDat > > a_pair =(*it);
858  Tm t_pair=a_pair.first;
859  std::map< EcalLogicID, RunDCSHVDat > a_map = a_pair.second;
860  num_dcs=num_dcs+a_map.size();
861 
862  bool somediff_hv= insertHVDataSetToOffline(&a_map, dcs_temp );
863 
864 
865  if(somediff_hv ) {
866  std::cout << "some diff" << std::endl;
867  // we have to copy this record to offline
868  // we copy dcs_temp to dcs_pop
869  EcalDCSTowerStatus* dcs_pop = new EcalDCSTowerStatus();
870 
871  // barrel
872  int iz=0;
873  for(int k=0 ; k<2; k++ ) {
874  if(k==0) iz=-1;
875  if(k==1) iz= 1;
876  for(int i=1 ; i<73; i++) {
877  for(int j=1 ; j<18; j++) {
878  if (EcalTrigTowerDetId::validDetId(iz,EcalBarrel,j,i )){
879  EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
880 
881  uint16_t dbStatus = 0;
882  dbStatus =(dcs_temp->barrel( ebid.hashedIndex())).getStatusCode();
883 
884  EcalDCSTowerStatus::const_iterator it =dcs_temp->find(ebid.rawId());
885  if ( it != dcs_temp->end() ) {
886  } else {
887  std::cout<<"*** error channel not found: j/i="<<j<<"/"<<i << std::endl;
888  }
889 
890  dcs_pop->setValue( ebid, dbStatus );
891  }
892  }
893  }
894  }
895 
896  // endcap
897  for(int k=0 ; k<2; k++ ) {
898  if(k==0) iz=-1;
899  if(k==1) iz=+1;
900  for(int i=1 ; i<21; i++) {
901  for(int j=1 ; j<21; j++) {
902  if (EcalScDetId::validDetId(i,j,iz )){
903  EcalScDetId eeid(i,j,iz);
904 
905  EcalDCSTowerStatus::const_iterator it =dcs_temp->find(eeid.rawId());
906 
907  uint16_t dbStatus = 0;
908  if ( it != dcs_temp->end() ) {
909  dbStatus = it->getStatusCode();
910  }
911  dcs_pop->setValue( eeid, dbStatus );
912  }
913  }
914  }
915  }
916 
917  uint64_t tsincetemp= t_pair.microsTime()/1000000 ;
918 
919  uint64_t tsince = tsincetemp<< 32;
920  Tm tnew(t_pair.microsTime());
921 
922  std::cout << "Generating popcon record for time " << tsince << "HRF time " << tnew.str() << "..." << std::flush;
923 
924  m_to_transfer.push_back(std::make_pair((EcalDCSTowerStatus*)dcs_pop,tsince));
925 
926  ss << "Time=" << tnew.str() << "_DCSchanged_"<<std::endl;
927  m_userTextLog = ss.str()+";";
928 
929 
930 
931 
932  }
933  }
934 
935 
936 
937  std::cout << " num DCS = "<< num_dcs << std::endl;
938  }
939 
940 
941 
942  delete dcs_temp;
943  */
944  }
945 
946  delete econn;
947  std::cout << "Ecal - > end of getNewObjects -----------\n";
948 }
static bool validDetId(int ix, int iy, int iz)
Definition: EcalScDetId.cc:59
EcalDCSHandler(edm::ParameterSet const &)
int * HVEELogicIDToDetID(int, int) const
int run_t
Definition: CaliIOV.h:11
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
int hashedIndex() const
get a compact index for arrays [TODO: NEEDS WORK]
bool insertLVDataSetToOffline(const std::map< EcalLogicID, RunDCSLVDat > *dataset, EcalDCSTowerStatus *dcs_temp, const std::vector< EcalLogicID > &) const
int getID1() const
Definition: EcalLogicID.cc:30
int * HVLogicIDToDetID(int, int) const
std::string getName() const
Definition: EcalLogicID.cc:26
uint16_t OffDBStatus(uint16_t dbStatus, int pos)
uint16_t updateHV(RunDCSHVDat *hv, uint16_t dbStatus, int modo=0) const
void getNewObjects() override
int getID2() const
Definition: EcalLogicID.cc:32
void printLVDataSet(const std::map< EcalLogicID, RunDCSLVDat > *dataset, int) const
run_t getRunNumber() const
Definition: RunIOV.cc:31
static const int HVNOTNOMINAL
Definition: RunDCSHVDat.h:24
void setValue(const uint32_t id, const Item &item)
int * LVLogicIDToDetID(int, int) const
float getLV() const
Definition: RunDCSLVDat.h:37
int getStatus() const
Definition: RunDCSHVDat.h:40
EcalDCSTowerStatusMap EcalDCSTowerStatus
float getHV() const
Definition: RunDCSHVDat.h:38
int detIDToLogicID(int, int, int)
bool insertHVDataSetToOffline(const std::map< EcalLogicID, RunDCSHVDat > *dataset, EcalDCSTowerStatus *dcs_temp) const
unsigned long m_firstRun
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ix(uint32_t id)
static const int LVOFF
Definition: RunDCSLVDat.h:24
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const_iterator find(uint32_t rawId) const
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
unsigned long m_lastRun
static const int HVOFF
Definition: RunDCSHVDat.h:25
static const int LVNOTNOMINAL
Definition: RunDCSLVDat.h:23
std::unique_ptr< EcalDCSTowerStatus > Ref
static bool validDetId(int iz, EcalSubdetector sd, int i, int j)
check if a valid index combination
static const int NULLID
Definition: EcalLogicID.h:35
float getHVNominal() const
Definition: RunDCSHVDat.h:39
uint16_t updateLV(RunDCSLVDat *lv, uint16_t dbStatus) const
float getLVNominal() const
Definition: RunDCSLVDat.h:38
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t iy(uint32_t id)
std::vector< Item >::const_iterator const_iterator
void printHVDataSet(const std::map< EcalLogicID, RunDCSHVDat > *dataset, int) const
Definition: RunIOV.h:13
int getStatus() const
Definition: RunDCSLVDat.h:39