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