BOSS 8.0.0
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/Bootstrap.h"
15#include "GaudiKernel/DataObject.h"
16#include "GaudiKernel/IDataProviderSvc.h"
17#include "GaudiKernel/IIncidentSvc.h"
18#include "GaudiKernel/ISvcLocator.h"
19#include "GaudiKernel/Incident.h"
20#include "GaudiKernel/MsgStream.h"
21#include "GaudiKernel/SmartDataPtr.h"
22#include "GaudiKernel/SvcFactory.h"
23
24#include "CLHEP/Units/PhysicalConstants.h"
25#include "Trigger/BesEmcTrig.h"
27#include "Trigger/BesMdcTrig.h"
28#include "Trigger/BesMucTrig.h"
29#include "Trigger/BesTMTrig.h"
30#include "Trigger/BesTofTrig.h"
31#include <fstream>
32#include <iostream>
33#include <string>
34using namespace CLHEP;
35using namespace std;
36
37const std::string BesGlobalTrigSvc::COND_NAME[] = {
38 "NClus1", "NClus2", "BClusBB", "EClusBB", "Clus_Z", "BClus_PHI",
39 "EClus_PHI", "BEtot_H", "EEtot_H", "Etot_L", "Etot_M", "BL_Z",
40 "NBClus1", "NEClus1", "BL_BBLK", "BL_EBLK", "ETofBB", "BTofBB",
41 "NETof2", "NETof1", "NBTof2", "NBTof1", "NTof1", "CTrk_BB",
42 "NCTrk2", "NCTrk1", "BTrk_BB", "NBTrk2", "NBTrk1", "ATrk_BB",
43 "NATrk2", "NATrk1", "MUONBB3478", "MUONBB37", "NotDefined", "NotDefined",
44 "NotDefined", "NotDefined", "STrk_BB", "NStrkN", "NStrk2", "NStrk1",
45 "LTrk_BB", "NLtrkN", "NLtrk2", "NLtrk1", "NItrk2", "NItrk1" };
46
47// Instantiation of a static factory class used by clients to create
48// instances of this service
49// static SvcFactory<BesGlobalTrigSvc> s_factory;
50// const ISvcFactory& BesGlobalTrigSvcFactory = s_factory;
51
52BesGlobalTrigSvc::BesGlobalTrigSvc( const std::string& name, ISvcLocator* svc )
53 : Service( name, svc )
54 , m_MdcTrig( 0 )
55 , m_TofTrig( 0 )
56 , m_EmcTrig( 0 )
57 , m_MucTrig( 0 )
58 , m_TMTrig( 0 ) {
59 trigTableFile = std::string( getenv( "TRIGGERROOT" ) );
60 trigTableFile += std::string( "/share/TriggerTable.txt" );
61 declareProperty( "TrigTableCon", trigTableFile );
62 declareProperty( "TofLayerControl", m_tofLayer = 2 );
63 declareProperty( "L1TC_GATE", L1TC_GATE = 70 );
64 declareProperty( "L1TC_THRESH", L1TC_THRESH = 130 );
65 declareProperty( "L1ETOT_L", L1ETOT_L = 0x56 );
66 declareProperty( "L1ETOT_M", L1ETOT_M = 0xba ); // 0xba(run10584),0x190,0x10a(run9571)
67 declareProperty( "L1ETOT_BR", L1ETOT_BR = 0x19a ); // 0x216,0x19a
68 declareProperty( "L1ETOT_EC", L1ETOT_EC = 0x19a ); // 0x1bd,0x19a
69 declareProperty( "L1EBL_BR", L1EBL_BR = 0x30 );
70 declareProperty( "L1EBL_EC", L1EBL_EC = 0x1ec );
71 declareProperty( "L1EDIFF_BR", L1EDIFF_BR = 0xf6 );
72 declareProperty( "L1EDIFF_EC", L1EDIFF_EC = 0xe1 );
73 declareProperty( "L1BLK_GATE", L1BLK_GATE = 0x30 );
74 declareProperty( "L1EBL_Z", L1EBL_Z = 0xa4 );
75 declareProperty( "MAXMDCTRACK", MAXMDCTRACK = 4 );
76 declareProperty( "TM_ENDCAP_MODE", tm_endcap = 0 );
77 declareProperty( "Energy_Ratio", Energy_Ratio = 1. );
78}
80//=============================================================================
81// Initialize
82//=============================================================================
84 MsgStream log( msgSvc(), name() );
85
86 StatusCode sc = Service::initialize();
87 if ( sc.isFailure() ) return sc;
88
89 StatusCode status;
90 // Get the references to the services that are needed by the ApplicationMgr itself
91 IIncidentSvc* incsvc;
92 status = service( "IncidentSvc", incsvc );
93 int priority = 100;
94 if ( status.isSuccess() ) { incsvc->addListener( this, "NewRun", priority ); }
95
96 IRealizationSvc* tmpReal;
97 status = service( "RealizationSvc", tmpReal );
98 if ( !status.isSuccess() )
99 { log << MSG::FATAL << " Could not initialize Realization Service" << endmsg; }
100 else { m_RealizationSvc = dynamic_cast<RealizationSvc*>( tmpReal ); }
101
102 m_MdcTrig = new BesMdcTrig();
103 m_TofTrig = new BesTofTrig();
104 m_EmcTrig = new BesEmcTrig();
105 m_MucTrig = new BesMucTrig();
106 m_TMTrig = new BesTMTrig();
107
108 if ( !m_MdcTrig ) log << MSG::FATAL << "can not get BesMdcTrig pointer " << endmsg;
109 if ( !m_TofTrig ) log << MSG::FATAL << "can not get BesTofTrig pointer " << endmsg;
110 if ( !m_EmcTrig ) log << MSG::FATAL << "can not get BesEmcTrig pointer " << endmsg;
111 if ( !m_MucTrig ) log << MSG::FATAL << "can not get BesMucTrig pointer " << endmsg;
112 if ( !m_TMTrig ) log << MSG::FATAL << "can not get BesTMTrig pointer " << endmsg;
113
114 trigChannel.clear();
115 trigCondName.clear();
116 trigTable.clear();
117 channelNo.clear();
118
119 if ( m_RealizationSvc->UseDBFlag() == false )
120 {
121 ifstream infile;
122 infile.open( trigTableFile.c_str(), ios_base::in );
123 if ( !infile )
124 log << MSG::FATAL << "can not open Trigger Table file: " << trigTableFile << endmsg;
125 char line[255];
126 // Skip the header
127 do {
128 infile.getline( line, 255 );
129 } while ( line[0] != 'C' );
130 // the name of each trigger channel
131 std::string chan;
132 int num;
133 char* token = strtok( line, " " );
134 do {
135 if ( token )
136 {
137 chan = token;
138 token = strtok( NULL, " " );
139 if ( chan != "CHANNEL" ) trigChannel.push_back( chan );
140 }
141 else continue;
142 } while ( token != NULL );
143 // use this trigger channel, yes or no ?
144 infile.getline( line, 255 );
145 token = strtok( line, " " );
146 do {
147 if ( token )
148 {
149 chan = token;
150 token = strtok( NULL, " " );
151 num = atoi( chan.c_str() );
152 channelNo.push_back( num );
153 }
154 else continue;
155 } while ( token != NULL );
156
157 while ( infile )
158 {
159 infile.getline( line, 255 );
160 if ( line[0] == ' ' ) continue;
161 if ( line[0] == '#' ) break;
162 token = strtok( line, " " );
163 do {
164 if ( token )
165 {
166 chan = token;
167 token = strtok( NULL, " " );
168 if ( chan == "1" || chan == "0" || chan == "-" ) { trigTable.push_back( chan ); }
169 else { trigCondName.push_back( chan ); }
170 }
171 else continue;
172 } while ( token != NULL );
173 }
174
175 for ( unsigned int i = 0; i < trigChannel.size(); i++ )
176 { cout << " " << trigChannel[i] << " "; }
177 cout << endl;
178 for ( unsigned int i = 0; i < channelNo.size(); i++ )
179 { cout << " " << channelNo[i] << " "; }
180 cout << endl;
181 for ( unsigned int j = 0; j < trigCondName.size(); j++ )
182 {
183 cout << trigCondName[j] << " ";
184 for ( unsigned int i = 0 + j * trigChannel.size();
185 i < trigChannel.size() + j * trigChannel.size(); i++ )
186 { cout << trigTable[i] << " "; }
187 cout << endl;
188 }
189 infile.close();
190 }
191
192 return StatusCode::SUCCESS;
193}
194
196 MsgStream log( msgSvc(), name() );
197 log << MSG::INFO << "Service finalized successfully" << endmsg;
198 return StatusCode::SUCCESS;
199}
200
201//=============================================================================
202// QueryInterface
203//=============================================================================
204StatusCode BesGlobalTrigSvc::queryInterface( const InterfaceID& riid, void** ppvInterface ) {
205 if ( IBesGlobalTrigSvc::interfaceID().versionMatch( riid ) )
206 { *ppvInterface = (IBesGlobalTrigSvc*)this; }
207 else { return Service::queryInterface( riid, ppvInterface ); }
208 addRef();
209 return StatusCode::SUCCESS;
210}
211
212void BesGlobalTrigSvc::handle( const Incident& inc ) {
213 MsgStream log( msgSvc(), name() );
214 log << MSG::DEBUG << "handle: " << inc.type() << endmsg;
215 if ( inc.type() != "NewRun" ) { return; }
216 log << MSG::DEBUG << "Begin New Run" << endmsg;
217 if ( m_RealizationSvc->UseDBFlag() == true && m_RealizationSvc->ifReadTrg() == true )
218 {
219
220 std::vector<uint32_t> trgTable_DB = m_RealizationSvc->getTrgTable();
221
222 trigChannel.clear();
223 trigCondName.clear();
224 trigTable.clear();
225 channelNo.clear();
226
227 for ( unsigned int i = 0, mask = 1; i < 16; i++, mask <<= 1 )
228 {
229 if ( trgTable_DB[0] & mask )
230 {
231 if ( i == 9 ) channelNo.push_back( 0 );
232 else channelNo.push_back( 1 );
233 }
234 else channelNo.push_back( 0 );
235 std::ostringstream osname;
236 osname << "Channel_" << i;
237 std::string name = osname.str();
238 trigChannel.push_back( name );
239 }
240
241 string table_tmp[16][64];
242 for ( unsigned int i = 1; i < 65; i++ )
243 {
244 for ( unsigned int j = 0; j < 16; j++ )
245 {
246 int bit2 = ( trgTable_DB[i] >> 2 * j ) & 0x3;
247 int row = (int)( i - 1 ) / 4;
248 int column = ( ( i - 1 ) % 4 ) * 16 + j;
249 if ( bit2 == 0 ) table_tmp[row][column] = "1";
250 else if ( bit2 == 1 ) table_tmp[row][column] = "0";
251 else table_tmp[row][column] = "-";
252 }
253 }
254
255 for ( int j = 0; j < 48; j++ )
256 {
257 trigCondName.push_back( COND_NAME[j] );
258 for ( int i = 0; i < 16; i++ ) { trigTable.push_back( table_tmp[i][j] ); }
259 }
260 // print
261 for ( unsigned int i = 0; i < trigChannel.size(); i++ )
262 { cout << " " << trigChannel[i] << " "; }
263 cout << endl;
264 for ( unsigned int i = 0; i < channelNo.size(); i++ )
265 { cout << " " << channelNo[i] << " "; }
266 cout << endl;
267 for ( unsigned int j = 0; j < trigCondName.size(); j++ )
268 {
269 cout << setw( 15 ) << trigCondName[j] << " ";
270 for ( unsigned int i = 0 + j * trigChannel.size();
271 i < trigChannel.size() + j * trigChannel.size(); i++ )
272 { cout << trigTable[i] << " "; }
273 cout << endl;
274 }
275 }
276}
277
279 L1ETOT_L = m_RealizationSvc->getVthEtotL();
280 return L1ETOT_L;
281}
282
284 L1ETOT_M = m_RealizationSvc->getVthEtotM();
285 return L1ETOT_M;
286}
287
289 L1ETOT_BR = m_RealizationSvc->getVthBEtotH();
290 return L1ETOT_BR;
291}
292
294 L1ETOT_EC = m_RealizationSvc->getVthEEtotH();
295 return L1ETOT_EC;
296}
297
299 L1EBL_BR = m_RealizationSvc->getVthBalBLK();
300 return L1EBL_BR;
301}
302
304 L1EBL_EC = m_RealizationSvc->getVthBalEEMC();
305 return L1EBL_EC;
306}
307
309 L1EDIFF_BR = m_RealizationSvc->getVthDiffB();
310 return L1EDIFF_BR;
311}
312
314 L1EDIFF_EC = m_RealizationSvc->getVthDiffE();
315 return L1EDIFF_EC;
316}
317
319 L1BLK_GATE = m_RealizationSvc->getVthBalBLK();
320 return L1BLK_GATE;
321}
322
324 L1EBL_Z = m_RealizationSvc->getVthBLZ();
325 return L1EBL_Z;
326}
327
329 if ( m_MdcTrig ) m_MdcTrig->startMdcTrig();
330}
331
333 if ( m_TofTrig ) m_TofTrig->startTofTrig();
334}
335
337 if ( m_EmcTrig ) m_EmcTrig->startEmcTrig();
338}
339
341 if ( m_TMTrig ) m_TMTrig->startTMTrig();
342}
343
345 // initialize
346 ifpass = false;
347 trigOut.clear();
348
349 for ( int i = 0; i < 16; i++ )
350 {
351 if ( i < 16 ) m_trigChannel[i] = 0;
352 }
353
354 MsgStream log( msgSvc(), name() );
355
356 // get Muc trigger information
357 muc_vlayerSeg = m_MucTrig->getNlayerSeg();
358
359 muc_nlayerEE = m_MucTrig->getNlayerPart( 0 );
360 muc_nlayerBR = m_MucTrig->getNlayerPart( 1 );
361 muc_nlayerWE = m_MucTrig->getNlayerPart( 2 );
362 muc_vhitLayer = m_MucTrig->getNhitLayer();
363 muc_vhitSeg = m_MucTrig->getNhitSeg();
364 muc_nhitEE = m_MucTrig->getNhitPart( 0 );
365 muc_nhitBR = m_MucTrig->getNhitPart( 1 );
366 muc_nhitWE = m_MucTrig->getNhitPart( 2 );
367 muc_nhitTotal = m_MucTrig->getNhitTotal();
368
369 // set trigger condition id
370 StatusCode status;
371 // StatusCode status = setTrigCondition();
372
373 // make out trigger conditon table;
374 for ( unsigned int i = 0; i < 48; i++ )
375 {
376 for ( unsigned int j = 0; j < trigChannel.size(); j++ )
377 {
378 if ( trigCond[i] ) trigOut.push_back( 1 );
379 else trigOut.push_back( 0 );
380 }
381 }
382
383 // compare trigger table and trigger output
384
385 for ( unsigned int i = 0; i < channelNo.size(); i++ )
386 {
387 if ( channelNo.size() > 16 )
388 {
389 log << MSG::FATAL << "Trigger Channel is greater than 16!!!!!" << endmsg;
390 return StatusCode::FAILURE;
391 }
392 int condition = 0;
393 int conditionNo = 0;
394 if ( channelNo[i] == 0 )
395 {
396 m_trigChannel[i] = 0; // data structure member in TDS
397 continue;
398 }
399 else
400 {
401 log << MSG::INFO << trigChannel[i] << ": ";
402 for ( unsigned int j = 0; j < trigCondName.size(); j++ )
403 {
404 if ( trigTable[i + j * channelNo.size()] == "1" &&
405 trigOut[i + j * channelNo.size()] == 1 )
406 condition++;
407 if ( trigTable[i + j * channelNo.size()] == "0" &&
408 trigOut[i + j * channelNo.size()] == 0 )
409 condition++;
410 if ( trigTable[i + j * channelNo.size()] == "1" )
411 log << MSG::INFO << trigCondName[j] << " ";
412 if ( trigTable[i + j * channelNo.size()] == "0" )
413 log << MSG::INFO << "anti_" << trigCondName[j] << " ";
414 }
415 for ( unsigned int k = 0; k < trigCondName.size(); k++ )
416 {
417 if ( trigTable[i + k * channelNo.size()] == "1" ||
418 trigTable[i + k * channelNo.size()] == "0" )
419 {
420 log << MSG::INFO << trigOut[i + k * channelNo.size()] << " ";
421 conditionNo++;
422 }
423 }
424 log << MSG::INFO << endmsg;
425 if ( ( condition == conditionNo ) && conditionNo != 0 )
426 {
427 ifpass = true;
428 m_trigChannel[i] = 1; // data structure member in TDS
429 }
430 else
431 {
432 m_trigChannel[i] = 0; // data structure member in TDS
433 }
434 }
435 }
436
437 return status;
438}
439
441 for ( int i = 0; i < 48; i++ )
442 {
443 trigCond[i] = false;
444 m_trigCondition[i] = 0;
445 }
446
447 trigCond[0] = emc_NClus1;
448 trigCond[1] = emc_NClus2;
449 trigCond[2] = emc_BClusBB;
450 trigCond[3] = emc_EClusBB;
451 trigCond[4] = emc_Clus_Z;
452 trigCond[5] = emc_BClus_PHI;
453 trigCond[6] = emc_EClus_PHI;
454 trigCond[7] = emc_BEtot_H;
455 trigCond[8] = emc_EEtot_H;
456 trigCond[9] = emc_Etot_L;
457 trigCond[10] = emc_Etot_M;
458 trigCond[11] = emc_BL_Z;
459 trigCond[12] = emc_NBClus1;
460 trigCond[13] = emc_NEClus1;
461 trigCond[14] = emc_BL_BBLK;
462 trigCond[15] = emc_BL_EBLK;
463 trigCond[16] = tof_ETofBB;
464 trigCond[17] = tof_BTofBB;
465 trigCond[18] = tof_NETof2;
466 trigCond[19] = tof_NETof1;
467 trigCond[20] = tof_NBTof2;
468 trigCond[21] = tof_NBTof1;
469 trigCond[22] = tof_NTof1;
470 trigCond[23] = tm_CTrk_BB;
471 trigCond[24] = tm_NCTrk2;
472 trigCond[25] = tm_NCTrk1;
473 trigCond[26] = tm_BTrk_BB;
474 trigCond[27] = tm_NBTrk2;
475 trigCond[28] = tm_NBTrk1;
476 trigCond[29] = tm_ATrk_BB;
477 trigCond[30] = tm_NATrk2;
478 trigCond[31] = tm_NATrk1;
479 trigCond[32] = muc_BB3478;
480 trigCond[33] = muc_BB37;
481 trigCond[34] = false;
482 trigCond[35] = false;
483 trigCond[36] = false;
484 trigCond[37] = false;
485 trigCond[38] = mdc_STrk_BB;
486 trigCond[39] = mdc_NStrkN;
487 trigCond[40] = mdc_NStrk2;
488 trigCond[41] = mdc_NStrk1;
489 trigCond[42] = mdc_LTrk_BB;
490 trigCond[43] = mdc_NLtrkN;
491 trigCond[44] = mdc_NLtrk2;
492 trigCond[45] = mdc_NLtrk1;
493 trigCond[46] = mdc_NItrk2;
494 trigCond[47] = mdc_NItrk1;
495
496 MsgStream log( msgSvc(), name() );
497 if ( trigCondName.size() != 48 )
498 {
499 log << MSG::FATAL << "The trigger condition CAN NOT be successfully read!!!" << endmsg;
500 return StatusCode::FAILURE;
501 }
502
503 for ( unsigned int i = 0; i < 48; i++ )
504 {
505 if ( trigCond[i] ) m_trigCondition[i] = 1; // data structure member in TDS
506 }
507
508 return StatusCode::SUCCESS;
509}
IMessageSvc * msgSvc()
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()
static const InterfaceID & interfaceID()