CMS 3D CMS Logo

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