CMS 3D CMS Logo

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