94 ISvcLocator* svc ) : Service( name, svc ),m_MdcTrig(0),m_TofTrig(0),m_EmcTrig(0),m_MucTrig(0),m_TMTrig(0)
96 trigTableFile = std::string(getenv(
"TRIGGERROOT" ));
97 trigTableFile += std::string(
"/share/TriggerTable.txt");
98 declareProperty(
"TrigTableCon", trigTableFile);
99 declareProperty(
"TofLayerControl", m_tofLayer = 2);
100 declareProperty(
"L1TC_GATE", L1TC_GATE = 70);
101 declareProperty(
"L1TC_THRESH", L1TC_THRESH = 130);
102 declareProperty(
"L1ETOT_L", L1ETOT_L = 0x56);
103 declareProperty(
"L1ETOT_M", L1ETOT_M = 0xba);
104 declareProperty(
"L1ETOT_BR", L1ETOT_BR = 0x19a);
105 declareProperty(
"L1ETOT_EC", L1ETOT_EC = 0x19a);
106 declareProperty(
"L1EBL_BR", L1EBL_BR = 0x30);
107 declareProperty(
"L1EBL_EC", L1EBL_EC = 0x1ec);
108 declareProperty(
"L1EDIFF_BR", L1EDIFF_BR = 0xf6);
109 declareProperty(
"L1EDIFF_EC", L1EDIFF_EC = 0xe1);
110 declareProperty(
"L1BLK_GATE", L1BLK_GATE = 0x30);
111 declareProperty(
"L1EBL_Z", L1EBL_Z = 0xa4);
112 declareProperty(
"MAXMDCTRACK", MAXMDCTRACK = 4);
113 declareProperty(
"TM_ENDCAP_MODE", tm_endcap = 0);
114 declareProperty(
"Energy_Ratio", Energy_Ratio = 1.);
124 MsgStream log(
msgSvc(), name());
126 StatusCode sc = Service::initialize();
127 if( sc.isFailure() )
return sc;
131 IIncidentSvc* incsvc;
132 status = service(
"IncidentSvc", incsvc);
134 if( status.isSuccess() ){
135 incsvc -> addListener(
this,
"NewRun", priority);
139 status = service(
"RealizationSvc",tmpReal);
140 if (!status.isSuccess())
142 log << MSG::FATAL <<
" Could not initialize Realization Service" << endreq;
153 if(!m_MdcTrig) log<<MSG::FATAL<<
"can not get BesMdcTrig pointer "<<endreq;
154 if(!m_TofTrig) log<<MSG::FATAL<<
"can not get BesTofTrig pointer "<<endreq;
155 if(!m_EmcTrig) log<<MSG::FATAL<<
"can not get BesEmcTrig pointer "<<endreq;
156 if(!m_MucTrig) log<<MSG::FATAL<<
"can not get BesMucTrig pointer "<<endreq;
157 if(!m_TMTrig) log<<MSG::FATAL<<
"can not get BesTMTrig pointer "<<endreq;
160 trigCondName.clear();
164 if(m_RealizationSvc->
UseDBFlag() ==
false) {
166 infile.open(trigTableFile.c_str(),ios_base::in);
167 if(!infile) log<<MSG::FATAL<<
"can not open Trigger Table file: "<<trigTableFile<<endreq;
171 infile.getline( line, 255 );
172 }
while( line[0] !=
'C' );
176 char* token = strtok( line,
" " );
180 token = strtok(
NULL,
" " );
181 if(chan!=
"CHANNEL") trigChannel.push_back(chan);
184 }
while ( token !=
NULL );
186 infile.getline( line, 255 );
187 token = strtok( line,
" " );
191 token = strtok(
NULL,
" ");
192 num = atoi(chan.c_str());
193 channelNo.push_back(
num);
196 }
while ( token!=
NULL);
199 infile.getline( line, 255 );
200 if(line[0]==
' ')
continue;
201 if(line[0]==
'#')
break;
202 token = strtok( line,
" " );
206 token = strtok(
NULL,
" ");
207 if(chan==
"1"||chan==
"0"||chan==
"-") { trigTable.push_back(chan); }
209 trigCondName.push_back(chan);
213 }
while (token!=
NULL);
216 for(
unsigned int i=0;i<trigChannel.size();i++){ cout<<
" "<<trigChannel[i]<<
" ";}
218 for(
unsigned int i=0;i<channelNo.size();i++){ cout<<
" "<<channelNo[i]<<
" ";}
220 for(
unsigned int j=0;j<trigCondName.size();j++)
222 cout<<trigCondName[j]<<
" ";
223 for(
unsigned int i=0+j*trigChannel.size();i<trigChannel.size()+j*trigChannel.size();i++)
224 { cout<<trigTable[i]<<
" ";}
230 return StatusCode::SUCCESS;
256 MsgStream log(
msgSvc(), name() );
257 log << MSG::DEBUG <<
"handle: " << inc.type() << endreq;
258 if ( inc.type() !=
"NewRun" ){
261 log << MSG::DEBUG <<
"Begin New Run" << endreq;
264 std::vector<uint32_t> trgTable_DB = m_RealizationSvc->
getTrgTable();
267 trigCondName.clear();
271 for(
unsigned int i = 0, mask = 1; i <16; i++,mask<<=1) {
272 if(trgTable_DB[0] & mask) {
273 if(i == 9) channelNo.push_back(0);
274 else channelNo.push_back(1);
276 else channelNo.push_back(0);
277 std::ostringstream osname;
278 osname <<
"Channel_"<<i;
279 std::string name = osname.str();
280 trigChannel.push_back(name);
283 string table_tmp[16][64];
284 for(
unsigned int i = 1; i <65; i++) {
285 for(
unsigned int j = 0; j <16; j++) {
286 int bit2 = (trgTable_DB[i]>>2*j) & 0x3;
287 int row = (int) (i-1)/4;
288 int column = ((i-1)%4)*16 + j;
289 if(bit2 == 0) table_tmp[row][column] =
"1";
290 else if(bit2 == 1) table_tmp[row][column] =
"0";
291 else table_tmp[row][column] =
"-";
295 for(
int j = 0; j < 48; j++) {
296 trigCondName.push_back(COND_NAME[j]);
297 for(
int i = 0; i < 16; i++) {
298 trigTable.push_back(table_tmp[i][j]);
302 for(
unsigned int i=0;i<trigChannel.size();i++){ cout<<
" "<<trigChannel[i]<<
" ";}
304 for(
unsigned int i=0;i<channelNo.size();i++){ cout<<
" "<<channelNo[i]<<
" ";}
306 for(
unsigned int j=0;j<trigCondName.size();j++)
308 cout<<setw(15)<<trigCondName[j]<<
" ";
309 for(
unsigned int i=0+j*trigChannel.size();i<trigChannel.size()+j*trigChannel.size();i++)
310 { cout<<trigTable[i]<<
" ";}
389 for(
int i = 0; i < 16; i++) {
390 if(i < 16) m_trigChannel[i] = 0;
393 MsgStream log(
msgSvc(), name());
413 for(
unsigned int i = 0; i < 48; i++) {
414 for(
unsigned int j = 0; j < trigChannel.size(); j++) {
415 if(trigCond[i]) trigOut.push_back(1);
416 else trigOut.push_back(0);
422 for(
unsigned int i=0; i<channelNo.size(); i++)
424 if(channelNo.size() > 16) {
425 log << MSG::FATAL <<
"Trigger Channel is greater than 16!!!!!" << endreq;
426 return StatusCode::FAILURE;
432 m_trigChannel[i] = 0;
437 log<<MSG::INFO<<trigChannel[i]<<
": ";
438 for(
unsigned int j=0; j<trigCondName.size(); j++)
440 if(trigTable[i+j*channelNo.size()]==
"1"&&trigOut[i+j*channelNo.size()]==1) condition++;
441 if(trigTable[i+j*channelNo.size()]==
"0"&&trigOut[i+j*channelNo.size()]==0) condition++;
442 if(trigTable[i+j*channelNo.size()]==
"1") log<<MSG::INFO<<trigCondName[j]<<
" ";
443 if(trigTable[i+j*channelNo.size()]==
"0") log<<MSG::INFO<<
"anti_"<<trigCondName[j]<<
" ";
445 for(
unsigned int k=0; k<trigCondName.size(); k++)
447 if(trigTable[i+k*channelNo.size()]==
"1"||trigTable[i+k*channelNo.size()]==
"0") {
448 log<<MSG::INFO<<trigOut[i+k*channelNo.size()]<<
" ";
451 log<<MSG::INFO<<endreq;
452 if((condition == conditionNo) && conditionNo!=0) {
454 m_trigChannel[i] = 1;
457 m_trigChannel[i] = 0;
467 for(
int i = 0; i < 48; i++) {
469 m_trigCondition[i] = 0;
472 trigCond[0] = emc_NClus1;
473 trigCond[1] = emc_NClus2;
474 trigCond[2] = emc_BClusBB;
475 trigCond[3] = emc_EClusBB;
476 trigCond[4] = emc_Clus_Z;
477 trigCond[5] = emc_BClus_PHI;
478 trigCond[6] = emc_EClus_PHI;
479 trigCond[7] = emc_BEtot_H;
480 trigCond[8] = emc_EEtot_H;
481 trigCond[9] = emc_Etot_L;
482 trigCond[10] = emc_Etot_M;
483 trigCond[11] = emc_BL_Z;
484 trigCond[12] = emc_NBClus1;
485 trigCond[13] = emc_NEClus1;
486 trigCond[14] = emc_BL_BBLK;
487 trigCond[15] = emc_BL_EBLK;
488 trigCond[16] = tof_ETofBB;
489 trigCond[17] = tof_BTofBB;
490 trigCond[18] = tof_NETof2;
491 trigCond[19] = tof_NETof1;
492 trigCond[20] = tof_NBTof2;
493 trigCond[21] = tof_NBTof1;
494 trigCond[22] = tof_NTof1;
495 trigCond[23] = tm_CTrk_BB;
496 trigCond[24] = tm_NCTrk2;
497 trigCond[25] = tm_NCTrk1;
498 trigCond[26] = tm_BTrk_BB;
499 trigCond[27] = tm_NBTrk2;
500 trigCond[28] = tm_NBTrk1;
501 trigCond[29] = tm_ATrk_BB;
502 trigCond[30] = tm_NATrk2;
503 trigCond[31] = tm_NATrk1;
504 trigCond[32] = muc_BB3478;
505 trigCond[33] = muc_BB37;
506 trigCond[34] =
false;
507 trigCond[35] =
false;
508 trigCond[36] =
false;
509 trigCond[37] =
false;
510 trigCond[38] = mdc_STrk_BB;
511 trigCond[39] = mdc_NStrkN;
512 trigCond[40] = mdc_NStrk2;
513 trigCond[41] = mdc_NStrk1;
514 trigCond[42] = mdc_LTrk_BB;
515 trigCond[43] = mdc_NLtrkN;
516 trigCond[44] = mdc_NLtrk2;
517 trigCond[45] = mdc_NLtrk1;
518 trigCond[46] = mdc_NItrk2;
519 trigCond[47] = mdc_NItrk1;
521 MsgStream log(
msgSvc(), name());
522 if(trigCondName.size() != 48) {
523 log << MSG::FATAL <<
"The trigger condition CAN NOT be successfully read!!!" << endreq;
524 return StatusCode::FAILURE;
527 for(
unsigned int i = 0; i < 48; i++) {
528 if(trigCond[i]) m_trigCondition[i] = 1;
531 return StatusCode::SUCCESS;