12 : m_name(ps.getUntrackedParameter<std::
string>(
"name",
"EcalDCSHandler")) {
14 std::cout <<
"EcalDCS Source handler constructor\n" << std::endl;
33 std::cout <<
"==========printDataSet()" << std::endl;
34 if (dataset->size() == 0) {
35 std::cout <<
"No data in map!" << std::endl;
41 typedef std::map< EcalLogicID, RunDCSHVDat >::const_iterator CI;
42 for (CI
p = dataset->begin();
p != dataset->end(); ++
p) {
53 std::cout <<
"========================" << std::endl;
61 std::cout <<
"==========printDataSet()" << std::endl;
62 if (dataset->size() == 0) {
63 std::cout <<
"No data in map!" << std::endl;
69 typedef std::map< EcalLogicID, RunDCSLVDat >::const_iterator CI;
70 for (CI
p = dataset->begin();
p != dataset->end(); ++
p) {
81 std::cout <<
"========================" << std::endl;
87 uint16_t hv_off_dbstatus = ( dbStatus & (1 << pos ) ) ;
88 if(hv_off_dbstatus>0) hv_off_dbstatus=1;
89 return hv_off_dbstatus;
96 uint16_t hv_on_dbstatus=0;
97 uint16_t hv_nomi_on_dbstatus=0;
106 if(mode == 0 || mode == 1) {
107 for (
int i=0;
i<16;
i++) {
109 temp = temp | (1<<
i) ;
111 temp = temp | (0<<
i);
114 result= dbStatus &
temp ;
117 for (
int i=0;
i<16;
i++) {
119 temp = temp | (1<<
i) ;
121 temp = temp | (0<<
i);
124 result= dbStatus &
temp ;
134 uint16_t lv_on_dbstatus=0;
135 uint16_t lv_nomi_on_dbstatus=0;
141 if(lv_off_dbstatus>0) lv_off_dbstatus=1;
142 if(lv_nomi_off_dbstatus>0) lv_nomi_off_dbstatus=1;
146 for (
int i=0;
i<16;
i++) {
148 temp = temp | (1<<
i) ;
150 temp = temp | ( 0 <<
i );
155 result= dbStatus &
temp ;
165 if (dataset->size() == 0) {
166 std::cout <<
"No data in std::map!" << std::endl;
172 typedef std::map< EcalLogicID, RunDCSHVDat >::const_iterator CI ;
174 for (CI
p = dataset->begin();
p != dataset->end(); ++
p) {
180 if(ecid.
getName()==
"EB_HV_channel"){
185 limits= HVLogicIDToDetID(sm,chan);
191 for(
int ik=i1; ik<=i2; ik++){
196 uint16_t dbStatus = 0;
197 if ( it != dcs_temp->
end() ) {
198 dbStatus = it->getStatusCode();
201 uint16_t new_dbStatus= updateHV(&hv, dbStatus, modo);
202 if(new_dbStatus != dbStatus ) result=
true;
204 dcs_temp->
setValue( ebid, new_dbStatus );
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;
219 limits= HVEELogicIDToDetID(dee,chan);
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;
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;
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;
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;
259 if(ecid.
getName()==
"EE_HVD_channel") modo=2;
261 for(
int ik=i1; ik<=i2; ik++){
262 for(
int ip=j1; ip<=j2; ip++){
263 bool not_excluded=
true;
265 for (
int l=0;
l<6;
l++){
266 if(ik== ex_x[
l] && ip== ex_y[
l] ) not_excluded=
false;
274 uint16_t dbStatus = 0;
275 if ( it != dcs_temp->
end() ) {
276 dbStatus = it->getStatusCode();
279 uint16_t new_dbStatus= updateHV(&hv, dbStatus, modo);
280 if(new_dbStatus != dbStatus ) result=
true;
282 dcs_temp->
setValue( eeid, new_dbStatus );
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;
293 for (
int l=0;
l<6;
l++){
300 uint16_t dbStatus = 0;
301 if ( it != dcs_temp->
end() ) {
302 dbStatus = it->getStatusCode();
304 uint16_t new_dbStatus= updateHV(&hv, dbStatus,modo);
305 if(new_dbStatus != dbStatus ) result=
true;
307 dcs_temp->
setValue( eeid, new_dbStatus );
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;
334 int ilocal=(i-1)-sm*4;
336 if(ilocal==0 || ilocal==1) hv_chan=1;
337 if(ilocal==2 || ilocal==3) hv_chan=2;
339 if(ilocal==0 || ilocal==1) hv_chan=2;
340 if(ilocal==2 || ilocal==3) hv_chan=1;
345 hv_chan=(j-1)*2+hv_chan;
347 hv_chan=(sm-1)*34+hv_chan -1 ;
357 if(dee==1 || dee==2) iz=1;
363 if(dee==1 && chan==1) {
366 }
else if(dee==2 && chan==1) {
369 }
else if(dee==3 && chan==1) {
372 }
else if(dee==4 && chan==1) {
375 }
else if(dee==1 && chan==2) {
378 }
else if(dee==2 && chan==2) {
381 }
else if(dee==3 && chan==2) {
384 }
else if(dee==4 && chan==2) {
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;
427 if(iz==1) ioffset=(sm-1)*4;
428 if(iz==-1) ioffset=(sm-18-1)*4;
448 if(sm>0 && sm <= 18) iz=1;
487 if(iz==1) ioffset=(sm-1)*4;
488 if(iz==-1) ioffset=(sm-18-1)*4;
507 if (dataset->size() == 0) {
508 std::cout <<
"No data in map!" << std::endl;
514 typedef std::map< EcalLogicID, RunDCSLVDat >::const_iterator CI;
515 for (CI
p = dataset->begin();
p != dataset->end(); ++
p) {
520 if(ecid.
getName()==
"EB_LV_channel"){
526 limits= LVLogicIDToDetID(sm,chan);
533 for(
int ik=i1; ik<=i2; ik++){
534 for(
int j=j1;
j<=j2;
j++){
538 uint16_t dbStatus = 0;
539 if ( it != dcs_temp->
end() ) {
540 dbStatus = it->getStatusCode();
542 uint16_t new_dbStatus= updateLV(&lv, dbStatus);
543 if(new_dbStatus != dbStatus ) result=
true;
544 dcs_temp->
setValue( ebid, new_dbStatus );
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;
563 int n=my_EELVchan.size();
565 for (
int ixt=0; ixt<
n; ixt++) {
566 if(my_EELVchan[ixt].getID1()==dee && my_EELVchan[ixt].getID2()==chan){
568 int ilogic=my_EELVchan[ixt].getLogicID();
570 if(ilogic == 2012058060 || ilogic == 2010060058
571 || ilogic == 2012043041 || ilogic == 2010041043) {
572 std::cout<<
"crystal " << ilogic <<
" in the corner ignored" << std::endl;
575 int iz= (ilogic/1000000)-2010;
578 if(iz != 1 && iz!= -1)
std::cout<<
"BAD z"<< std::endl;
580 int iy=ilogic- int(ilogic/1000)*1000;
582 int ix=(ilogic- int(ilogic/1000000)*1000000 -iy)/1000;
584 int ixtower= ((ix-1)/5) +1;
585 int iytower= ((iy-1)/5) +1;
587 if(ixtower<1 || ixtower>20 || iytower <1 || iytower >20)
588 std::cout<<
"BAD x/y"<<ilogic<<
"/"<< ixtower<<
"/"<<iytower<< std::endl;
593 uint16_t dbStatus = 0;
594 if ( it != dcs_temp->
end() ) {
595 dbStatus = it->getStatusCode();
598 uint16_t new_dbStatus= updateLV(&lv, dbStatus);
599 if(new_dbStatus != dbStatus ) result=
true;
600 dcs_temp->
setValue( eeid, new_dbStatus );
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;
628 bool lot_of_printout=
false;
629 std::cout <<
"------- Ecal DCS - > getNewObjects\n";
631 std::ostringstream
ss;
634 unsigned long long max_since= 1;
636 max_since=
tagInfo().lastInterval.first;
637 std::cout <<
"max_since : " << max_since << std::endl;
638 Ref dcs_db = lastPayload();
639 std::cout <<
"retrieved last payload " << std::endl;
646 for(
int k=0 ;
k<2;
k++ ) {
649 for(
int i=1 ;
i<73;
i++) {
650 for(
int j=1 ;
j<18;
j++) {
654 uint16_t dbStatus = 0;
655 dbStatus =(dcs_db->barrel( ebid.
hashedIndex())).getStatusCode();
659 if ( it != dcs_db->end() ) {
661 std::cout<<
"*** error channel not found: j/i="<<
j<<
"/"<<
i << std::endl;
664 dcs_temp->
setValue( ebid, dbStatus );
671 for(
int k=0 ;
k<2;
k++ ) {
674 for(
int i=1 ;
i<21;
i++) {
675 for(
int j=1 ;
j<21;
j++) {
681 uint16_t dbStatus = 0;
682 if ( it != dcs_db->end() ) {
683 dbStatus = it->getStatusCode();
685 dcs_temp->
setValue( eeid, dbStatus );
696 std::cout <<
"Connection done" << std::endl;
700 std::cout <<
" Problem with OMDS: connection parameters " <<m_sid <<
"/"<<m_user<<std::endl;
706 std::cout <<
"Retrieving last run from ONLINE DB ... " << std::endl;
707 std::map<EcalLogicID, RunDat> rundat;
709 run_t runmax=10000000;
711 econn->fetchValidDataSet(&rundat , &rp, location_p5 ,runmax);
713 unsigned long long irun=(
unsigned long long) rp.
getRunNumber();
718 if(max_since< irun) {
723 std::cout <<
"Retrieving endcap channel list from ONLINE DB ... " << std::endl;
725 std::vector<EcalLogicID> my_EELVchan= econn->getEcalLogicIDSetOrdered(
"EE_crystal_number", 1,4,
727 "EE_LV_channel", 12 ) ;
729 std::cout <<
"done endcap channel list ... " << std::endl;
734 std::map<EcalLogicID, RunDCSHVDat>
dataset;
736 econn->fetchDataSet(&dataset, r);
738 if (!dataset.size()) {
739 throw(std::runtime_error(
"Zero rows read back"));
743 if(lot_of_printout)
std::cout <<
"read OK" << std::endl;
744 if(lot_of_printout) printHVDataSet(&dataset,10);
746 std::map<EcalLogicID, RunDCSLVDat> dataset_lv;
747 econn->fetchDataSet(&dataset_lv, r);
749 if (!dataset_lv.size()) {
750 throw(std::runtime_error(
"Zero rows read back"));
752 if(lot_of_printout)
std::cout <<
"read OK" << std::endl;
753 if(lot_of_printout) printLVDataSet(&dataset_lv);
755 bool somediff_hv= insertHVDataSetToOffline(&dataset, dcs_temp );
756 bool somediff_lv= insertLVDataSetToOffline(&dataset_lv, dcs_temp, my_EELVchan );
758 if(somediff_hv || somediff_lv) {
769 std::cout <<
"Generating popcon record for run " << irun <<
"..." << std::flush;
777 ss <<
"Run=" << irun <<
"_DCSchanged_"<<std::endl;
779 m_userTextLog = ss.str()+
";";
786 std::cout<<
"Run DCS record was the same as previous run " << std::endl;
787 ss <<
"Run=" << irun <<
"_DCSchanged_"<<std::endl;
788 m_userTextLog = ss.str()+
";";
905 std::cout <<
"Ecal - > end of getNewObjects -----------\n";
static bool validDetId(int ix, int iy, int iz)
T getParameter(std::string const &) const
EcalDCSHandler(edm::ParameterSet const &)
float getHVNominal() const
edm::Ref< Container > Ref
const_iterator end() const
static const int HVEEDSTATUS
uint16_t OffDBStatus(uint16_t dbStatus, int pos)
static const int HVSTATUS
uint16_t updateLV(RunDCSLVDat *lv, uint16_t dbStatus) const
int hashedIndex() const
get a compact index for arrays [TODO: NEEDS WORK]
int * LVLogicIDToDetID(int, int) const
int * HVEELogicIDToDetID(int, int) const
static const int HVNOTNOMINAL
void setValue(const uint32_t id, const Item &item)
static const int LVSTATUS
const_iterator find(uint32_t rawId) const
uint32_t rawId() const
get the raw id
std::string getName() const
void printLVDataSet(const std::map< EcalLogicID, RunDCSLVDat > *dataset, int) const
int * HVLogicIDToDetID(int, int) const
float getLVNominal() const
EcalDCSTowerStatusMap EcalDCSTowerStatus
static const int HVNOMINALSTATUS
bool insertLVDataSetToOffline(const std::map< EcalLogicID, RunDCSLVDat > *dataset, EcalDCSTowerStatus *dcs_temp, const std::vector< EcalLogicID > &) const
int detIDToLogicID(int, int, int)
void printHVDataSet(const std::map< EcalLogicID, RunDCSHVDat > *dataset, int) const
static const int HVEEDNOMINALSTATUS
run_t getRunNumber() const
static const int LVNOTNOMINAL
static bool validDetId(int iz, EcalSubdetector sd, int i, int j)
check if a valid index combination
bool insertHVDataSetToOffline(const std::map< EcalLogicID, RunDCSHVDat > *dataset, EcalDCSTowerStatus *dcs_temp) const
static const int LVNOMINALSTATUS
std::vector< Item >::const_iterator const_iterator
uint16_t updateHV(RunDCSHVDat *hv, uint16_t dbStatus, int modo=0) const