BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
TrigEventMaker.cxx
Go to the documentation of this file.
1#include "GaudiKernel/IDataProviderSvc.h"
2#include "GaudiKernel/ISvcLocator.h"
3#include "GaudiKernel/MsgStream.h"
4#include "GaudiKernel/PropertyMgr.h"
5#include "GaudiKernel/SmartDataPtr.h"
6
7#include "EventModel/Event.h"
8#include "EventModel/EventHeader.h"
9#include "EventModel/EventModel.h"
10#include "TrigEvent/TrigData.h"
11#include "TrigEvent/TrigGTD.h"
12#include "TrigEventMaker.h"
13
14using namespace Event;
16
17TrigEventMaker::TrigEventMaker( const std::string& name, ISvcLocator* pSvcLocator )
18 : Algorithm( name, pSvcLocator ) {}
19
21 MsgStream log( msgSvc(), name() );
22 log << MSG::DEBUG << "TrigEventMaker: in initialize()" << endmsg;
23 return StatusCode::SUCCESS;
24}
25
27 MsgStream log( msgSvc(), name() );
28 log << MSG::DEBUG << "TrigEventMaker: in execute()" << endmsg;
29
30 // Get the event header, print out event and run number
31
32 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
33 if ( !eventHeader )
34 {
35 log << MSG::FATAL << "Could not find Event Header" << endmsg;
36 return StatusCode::FAILURE;
37 }
38
39 int eventId = eventHeader->eventNumber();
40 int runId = eventHeader->runNumber();
41 log << MSG::INFO << "TrigEventMaker: retrieved event: "
42 << " Event Number " << eventId << " run: " << runId << endmsg;
43
44 // define elements in TrigData structure
45 int trgCond[48];
46 int trgChan[16];
47 int window = 0;
48 int timing = 0;
49 bool preScale = false;
50
51 // initialize the elements defined above
52 for ( int i = 0; i < 48; i++ )
53 {
54 if ( i < 16 ) trgChan[i] = 0;
55 trgCond[i] = 0;
56 }
57
58 // Get trigger information from TDS
59 SmartDataPtr<TrigGTDCol> trigGTDCol( eventSvc(), "/Event/Trig/TrigGTDCol" );
60 if ( !trigGTDCol )
61 {
62 log << MSG::FATAL << "Could not find TrigGTDCol!" << endmsg;
63 return StatusCode::FAILURE;
64 }
65
66 TrigGTDCol::iterator iter = trigGTDCol->begin();
67 for ( ; iter != trigGTDCol->end(); iter++ )
68 {
69 const uint32_t boardId =
70 ( *iter )->getId(); // The board Id 0xd3: GTL, 0xD2: SAF1, 0xD4: SAF2, 0xD6: SAF3
71 const uint32_t timeWindow =
72 ( *iter )->getTimeWindow(); // Time window, bit8 to bit13, total: 0--31
73 // const uint32_t dataType = (*iter)->getDataType(); //bit3 to bit7, total: 0--31
74 const uint32_t size =
75 ( *iter )->getDataSize(); // The size of trigger data, not include head
76 const uint32_t* trigData = ( *iter )->getDataPtr(); // Trigger data
77
78 window = timeWindow;
79
80 // Get data group 5 in GTL, including trigger channel, timing and prescale.
81 if ( boardId == 0xd3 )
82 {
83 if ( size % timeWindow != 0 )
84 {
85 log << MSG::FATAL << "GTL data is NOT completed" << endmsg;
86 return StatusCode::FAILURE;
87 }
88 for ( uint32_t j = 0; j < size; j++ )
89 {
90 uint32_t dataId = ( ( trigData[j] >> 24 ) & 0x7 );
91 if ( dataId != 5 ) continue; // find data group 5
92 for ( uint32_t i = 1, loop = 0; loop < 24; i <<= 1, loop++ )
93 {
94 if ( loop < 16 )
95 {
96 if ( trigData[j] & i ) trgChan[loop] = 1;
97 }
98 if ( ( loop == 16 ) && ( trigData[j] & i ) ) timing = 1;
99 if ( ( loop == 17 ) && ( trigData[j] & i ) && ( timing != 1 ) ) timing = 2;
100 if ( ( loop == 18 ) && ( trigData[j] & i ) && ( timing == 0 ) ) timing = 3;
101 if ( ( loop == 21 ) && ( trigData[j] & i ) ) preScale = true;
102 }
103 }
104 }
105 // Get "or 4" in SAF
106 if ( boardId == 0xd2 || boardId == 0xd4 || boardId == 0xd6 )
107 {
108 for ( uint32_t j = 0; j < size; j++ )
109 {
110 uint32_t dataId = ( ( trigData[j] >> 16 ) & 0xFF );
111 if ( dataId != 4 ) continue; // find data "or 4" in SAF
112 for ( uint32_t i = 1, loop = 0; loop < 16; i <<= 1, loop++ )
113 {
114 if ( ( boardId == 0xd2 ) && ( trigData[j] & i ) ) trgCond[32 + loop] = 1;
115 if ( ( boardId == 0xd4 ) && ( trigData[j] & i ) ) trgCond[16 + loop] = 1;
116 if ( ( boardId == 0xd6 ) && ( trigData[j] & i ) ) trgCond[loop] = 1;
117 }
118 }
119 }
120 }
121
122 // Register related trigger information to TDS for physics analysis
123 TrigData* aTrigData = new TrigData( window, timing, trgCond, trgChan, preScale );
124
125 StatusCode sc = StatusCode::SUCCESS;
126 sc = eventSvc()->registerObject( EventModel::Trig::TrigData, aTrigData );
127 if ( sc != StatusCode::SUCCESS )
128 {
129 log << MSG::DEBUG << "Could not register TrigData" << endmsg;
130 return StatusCode::FAILURE;
131 }
132
133 return StatusCode::SUCCESS;
134}
135
137 MsgStream log( msgSvc(), name() );
138 log << MSG::DEBUG << "==> Finalize TrigEventMaker" << endmsg;
139 return StatusCode::SUCCESS;
140}
DECLARE_COMPONENT(BesBdkRc)
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
IMessageSvc * msgSvc()
StatusCode execute()
StatusCode finalize()
TrigEventMaker(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initialize()