BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
BesGlobalTrigSvc.cxx
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool /
3////
4////---------------------------------------------------------------------------/
5////
6////Description:
7////Author: Caogf
8////Created: Feb, 2006
9////Modified:
10////Comment:
11////
12//
13#include "GaudiKernel/AlgFactory.h"
14#include "GaudiKernel/SvcFactory.h"
15#include "GaudiKernel/ISvcLocator.h"
16#include "GaudiKernel/MsgStream.h"
17#include "GaudiKernel/Incident.h"
18#include "GaudiKernel/IIncidentSvc.h"
19#include "GaudiKernel/IDataProviderSvc.h"
20#include "GaudiKernel/DataObject.h"
21#include "GaudiKernel/SmartDataPtr.h"
22#include "GaudiKernel/Bootstrap.h"
23
25#include "Trigger/BesMdcTrig.h"
26#include "Trigger/BesTofTrig.h"
27#include "Trigger/BesEmcTrig.h"
28#include "Trigger/BesMucTrig.h"
29#include "Trigger/BesTMTrig.h"
30#include "CLHEP/Units/PhysicalConstants.h"
31#include <iostream>
32#include <fstream>
33#include <string>
34using namespace CLHEP;
35using namespace std;
36
37const std::string BesGlobalTrigSvc::COND_NAME[] = {
38 "NClus1",
39 "NClus2",
40 "BClusBB",
41 "EClusBB",
42 "Clus_Z",
43 "BClus_PHI",
44 "EClus_PHI",
45 "BEtot_H",
46 "EEtot_H",
47 "Etot_L",
48 "Etot_M",
49 "BL_Z",
50 "NBClus1",
51 "NEClus1",
52 "BL_BBLK",
53 "BL_EBLK",
54 "ETofBB",
55 "BTofBB",
56 "NETof2",
57 "NETof1",
58 "NBTof2",
59 "NBTof1",
60 "NTof1",
61 "CTrk_BB",
62 "NCTrk2",
63 "NCTrk1",
64 "BTrk_BB",
65 "NBTrk2",
66 "NBTrk1",
67 "ATrk_BB",
68 "NATrk2",
69 "NATrk1",
70 "MUONBB3478",
71 "MUONBB37",
72 "NotDefined",
73 "NotDefined",
74 "NotDefined",
75 "NotDefined",
76 "STrk_BB",
77 "NStrkN",
78 "NStrk2",
79 "NStrk1",
80 "LTrk_BB",
81 "NLtrkN",
82 "NLtrk2",
83 "NLtrk1",
84 "NItrk2",
85 "NItrk1"
86};
87
88// Instantiation of a static factory class used by clients to create
89// instances of this service
90//static SvcFactory<BesGlobalTrigSvc> s_factory;
91//const ISvcFactory& BesGlobalTrigSvcFactory = s_factory;
92
93BesGlobalTrigSvc::BesGlobalTrigSvc( const std::string& name,
94 ISvcLocator* svc ) : Service( name, svc ),m_MdcTrig(0),m_TofTrig(0),m_EmcTrig(0),m_MucTrig(0),m_TMTrig(0)
95{
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); //0xba(run10584),0x190,0x10a(run9571)
104 declareProperty("L1ETOT_BR", L1ETOT_BR = 0x19a);//0x216,0x19a
105 declareProperty("L1ETOT_EC", L1ETOT_EC = 0x19a);//0x1bd,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.);
115}
117{
118}
119//=============================================================================
120// Initialize
121//=============================================================================
123{
124 MsgStream log(msgSvc(), name());
125
126 StatusCode sc = Service::initialize();
127 if( sc.isFailure() ) return sc;
128
129 StatusCode status;
130 // Get the references to the services that are needed by the ApplicationMgr itself
131 IIncidentSvc* incsvc;
132 status = service("IncidentSvc", incsvc);
133 int priority = 100;
134 if( status.isSuccess() ){
135 incsvc -> addListener(this, "NewRun", priority);
136 }
137
138 IRealizationSvc *tmpReal;
139 status = service("RealizationSvc",tmpReal);
140 if (!status.isSuccess())
141 {
142 log << MSG::FATAL << " Could not initialize Realization Service" << endreq;
143 } else {
144 m_RealizationSvc=dynamic_cast<RealizationSvc*>(tmpReal);
145 }
146
147 m_MdcTrig = new BesMdcTrig();
148 m_TofTrig = new BesTofTrig();
149 m_EmcTrig = new BesEmcTrig();
150 m_MucTrig = new BesMucTrig();
151 m_TMTrig = new BesTMTrig();
152
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;
158
159 trigChannel.clear();
160 trigCondName.clear();
161 trigTable.clear();
162 channelNo.clear();
163
164 if(m_RealizationSvc->UseDBFlag() == false) {
165 ifstream infile;
166 infile.open(trigTableFile.c_str(),ios_base::in);
167 if(!infile) log<<MSG::FATAL<<"can not open Trigger Table file: "<<trigTableFile<<endreq;
168 char line[ 255 ];
169 // Skip the header
170 do{
171 infile.getline( line, 255 );
172 } while( line[0] != 'C' );
173 //the name of each trigger channel
174 std::string chan;
175 int num;
176 char* token = strtok( line, " " );
177 do{
178 if ( token ) {
179 chan = token;
180 token = strtok( NULL, " " );
181 if(chan!="CHANNEL") trigChannel.push_back(chan);
182 }
183 else continue;
184 }while ( token != NULL );
185 //use this trigger channel, yes or no ?
186 infile.getline( line, 255 );
187 token = strtok( line, " " );
188 do{
189 if( token ) {
190 chan = token;
191 token = strtok(NULL, " ");
192 num = atoi(chan.c_str());
193 channelNo.push_back(num);
194 }
195 else continue;
196 }while ( token!=NULL);
197
198 while(infile) {
199 infile.getline( line, 255 );
200 if(line[0]==' ') continue;
201 if(line[0]=='#') break;
202 token = strtok( line, " " );
203 do{
204 if(token) {
205 chan = token;
206 token = strtok(NULL," ");
207 if(chan=="1"||chan=="0"||chan=="-") { trigTable.push_back(chan); }
208 else {
209 trigCondName.push_back(chan);
210 }
211 }
212 else continue;
213 }while (token!=NULL);
214 }
215
216 for(unsigned int i=0;i<trigChannel.size();i++){ cout<<" "<<trigChannel[i]<<" ";}
217 cout<<endl;
218 for(unsigned int i=0;i<channelNo.size();i++){ cout<<" "<<channelNo[i]<<" ";}
219 cout<<endl;
220 for(unsigned int j=0;j<trigCondName.size();j++)
221 {
222 cout<<trigCondName[j]<<" ";
223 for(unsigned int i=0+j*trigChannel.size();i<trigChannel.size()+j*trigChannel.size();i++)
224 { cout<<trigTable[i]<<" ";}
225 cout<<endl;
226 }
227 infile.close();
228 }
229
230 return StatusCode::SUCCESS;
231}
232
234{
235 MsgStream log( msgSvc(), name() );
236 log << MSG::INFO << "Service finalized successfully" << endreq;
237 return StatusCode::SUCCESS;
238}
239
240//=============================================================================
241// QueryInterface
242//=============================================================================
243StatusCode BesGlobalTrigSvc::queryInterface( const InterfaceID& riid,
244 void** ppvInterface )
245{
246 if ( IBesGlobalTrigSvc::interfaceID().versionMatch(riid) ) {
247 *ppvInterface = (IBesGlobalTrigSvc*)this;
248 }else{
249 return Service::queryInterface(riid, ppvInterface);
250 }
251 addRef();
252 return StatusCode::SUCCESS;
253}
254
255void BesGlobalTrigSvc::handle(const Incident& inc) {
256 MsgStream log( msgSvc(), name() );
257 log << MSG::DEBUG << "handle: " << inc.type() << endreq;
258 if ( inc.type() != "NewRun" ){
259 return;
260 }
261 log << MSG::DEBUG << "Begin New Run" << endreq;
262 if(m_RealizationSvc->UseDBFlag() == true && m_RealizationSvc->ifReadTrg() == true) {
263
264 std::vector<uint32_t> trgTable_DB = m_RealizationSvc->getTrgTable();
265
266 trigChannel.clear();
267 trigCondName.clear();
268 trigTable.clear();
269 channelNo.clear();
270
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);
275 }
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);
281 }
282
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] = "-";
292 }
293 }
294
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]);
299 }
300 }
301 //print
302 for(unsigned int i=0;i<trigChannel.size();i++){ cout<<" "<<trigChannel[i]<<" ";}
303 cout<<endl;
304 for(unsigned int i=0;i<channelNo.size();i++){ cout<<" "<<channelNo[i]<<" ";}
305 cout<<endl;
306 for(unsigned int j=0;j<trigCondName.size();j++)
307 {
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]<<" ";}
311 cout<<endl;
312 }
313 }
314
315}
316
318 L1ETOT_L = m_RealizationSvc->getVthEtotL();
319 return L1ETOT_L;
320}
321
323 L1ETOT_M = m_RealizationSvc->getVthEtotM();
324 return L1ETOT_M;
325}
326
328 L1ETOT_BR = m_RealizationSvc->getVthBEtotH();
329 return L1ETOT_BR;
330}
331
333 L1ETOT_EC = m_RealizationSvc->getVthEEtotH();
334 return L1ETOT_EC;
335}
336
338 L1EBL_BR = m_RealizationSvc->getVthBalBLK();
339 return L1EBL_BR;
340}
341
343 L1EBL_EC = m_RealizationSvc->getVthBalEEMC();
344 return L1EBL_EC;
345}
346
348 L1EDIFF_BR = m_RealizationSvc->getVthDiffB();
349 return L1EDIFF_BR;
350}
351
353 L1EDIFF_EC = m_RealizationSvc->getVthDiffE();
354 return L1EDIFF_EC;
355}
356
358 L1BLK_GATE = m_RealizationSvc->getVthBalBLK();
359 return L1BLK_GATE;
360}
361
363 L1EBL_Z = m_RealizationSvc->getVthBLZ();
364 return L1EBL_Z;
365}
366
368 if(m_MdcTrig) m_MdcTrig->startMdcTrig();
369}
370
372 if(m_TofTrig) m_TofTrig->startTofTrig();
373}
374
376 if(m_EmcTrig) m_EmcTrig->startEmcTrig();
377}
378
380 if(m_TMTrig) m_TMTrig->startTMTrig();
381}
382
384{
385 //initialize
386 ifpass = false;
387 trigOut.clear();
388
389 for(int i = 0; i < 16; i++) {
390 if(i < 16) m_trigChannel[i] = 0;
391 }
392
393 MsgStream log(msgSvc(), name());
394
395 //get Muc trigger information
396 muc_vlayerSeg = m_MucTrig->getNlayerSeg();
397
398 muc_nlayerEE = m_MucTrig->getNlayerPart(0);
399 muc_nlayerBR = m_MucTrig->getNlayerPart(1);
400 muc_nlayerWE = m_MucTrig->getNlayerPart(2);
401 muc_vhitLayer = m_MucTrig->getNhitLayer();
402 muc_vhitSeg = m_MucTrig->getNhitSeg();
403 muc_nhitEE = m_MucTrig->getNhitPart(0);
404 muc_nhitBR = m_MucTrig->getNhitPart(1);
405 muc_nhitWE = m_MucTrig->getNhitPart(2);
406 muc_nhitTotal = m_MucTrig->getNhitTotal();
407
408 //set trigger condition id
409 StatusCode status;
410 //StatusCode status = setTrigCondition();
411
412 //make out trigger conditon table;
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);
417 }
418 }
419
420 //compare trigger table and trigger output
421
422 for(unsigned int i=0; i<channelNo.size(); i++)
423 {
424 if(channelNo.size() > 16) {
425 log << MSG::FATAL <<"Trigger Channel is greater than 16!!!!!" << endreq;
426 return StatusCode::FAILURE;
427 }
428 int condition = 0;
429 int conditionNo = 0;
430 if(channelNo[i]==0)
431 {
432 m_trigChannel[i] = 0; //data structure member in TDS
433 continue;
434 }
435 else
436 {
437 log<<MSG::INFO<<trigChannel[i]<<": ";
438 for(unsigned int j=0; j<trigCondName.size(); j++)
439 {
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]<<" ";
444 }
445 for(unsigned int k=0; k<trigCondName.size(); k++)
446 {
447 if(trigTable[i+k*channelNo.size()]=="1"||trigTable[i+k*channelNo.size()]=="0") {
448 log<<MSG::INFO<<trigOut[i+k*channelNo.size()]<<" ";
449 conditionNo++; }
450 }
451 log<<MSG::INFO<<endreq;
452 if((condition == conditionNo) && conditionNo!=0) {
453 ifpass = true;
454 m_trigChannel[i] = 1; //data structure member in TDS
455 }
456 else {
457 m_trigChannel[i] = 0; //data structure member in TDS
458 }
459 }
460 }
461
462 return status;
463}
464
466{
467 for(int i = 0; i < 48; i++) {
468 trigCond[i] = false;
469 m_trigCondition[i] = 0;
470 }
471
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;
520
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;
525 }
526
527 for(unsigned int i = 0; i < 48; i++) {
528 if(trigCond[i]) m_trigCondition[i] = 1; //data structure member in TDS
529 }
530
531 return StatusCode::SUCCESS;
532}
IMessageSvc * msgSvc()
#define NULL
void startEmcTrig()
Definition: BesEmcTrig.cxx:39
StatusCode GlobalTrig()
virtual StatusCode initialize()
Initialise the service (Inherited Service overrides)
BesGlobalTrigSvc(const std::string &name, ISvcLocator *svc)
virtual StatusCode finalize()
Finalise the service.
void handle(const Incident &)
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
StatusCode setTrigCondition()
void startMdcTrig()
Definition: BesMdcTrig.cxx:35
std::vector< int > getNlayerSeg()
Definition: BesMucTrig.cxx:271
int getNlayerPart(int part)
Definition: BesMucTrig.cxx:309
std::vector< int > getNhitLayer()
Definition: BesMucTrig.cxx:338
int getNhitTotal()
Definition: BesMucTrig.cxx:405
int getNhitPart(int i)
Definition: BesMucTrig.cxx:396
std::vector< int > getNhitSeg()
Definition: BesMucTrig.cxx:368
void startTMTrig()
Definition: BesTMTrig.cxx:230
void startTofTrig()
Definition: BesTofTrig.cxx:33
static const InterfaceID & interfaceID()
std::vector< uint32_t > getTrgTable()