BOSS 7.1.2
BESIII Offline Software System
Loading...
Searching...
No Matches
EFtoTDS.cxx
Go to the documentation of this file.
3
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/SmartDataPtr.h"
6//#include "GaudiKernel/Bootstrap.h"
7//#include "GaudiKernel/IJobOptionsSvc.h"
8//#include "GaudiKernel/ISvcLocator.h"
9
10#include "EventModel/Event.h"
12#include "HltEvent/HltEvent.h"
13#include "HltEvent/HltRaw.h"
15#include "Identifier/HltID.h"
16
17using namespace std;
18using namespace Event;
19
20////////////////////////////////////////////////////////////////////////
21
22EFtoTDS::EFtoTDS(const std::string& name, ISvcLocator* pSvcLocator) :
23 Algorithm(name, pSvcLocator) {
24 declareProperty("OutputLevel", m_outputLevel);
25}
26
30
32
33 MsgStream log(msgSvc(), name());
34 log << MSG::INFO << "in initialize()" << endreq;
35
36 StatusCode sc = service( "HltStoreSvc", m_HltStoreSvc);
37 if( sc.isFailure() ) {
38 log << MSG::FATAL << name() << ": Unable to locate Service HltStoreSvc" << endreq;
39 return sc;
40 }
41
42 return StatusCode::SUCCESS;
43}
44
45StatusCode EFtoTDS::execute() {
46
47 MsgStream log(msgSvc(), name());
48 log << MSG::DEBUG << "in execute()" << endreq;
49
50 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),"/Event/EventHeader");
51 if (!eventHeader) {
52 log << MSG::FATAL << "Could not find Event Header" << endreq;
53 return StatusCode::FAILURE;
54 }
55
56 int eventId = eventHeader->eventNumber() ;
57 int runId = eventHeader->runNumber();
58 log << MSG::INFO << "retrieved event: " <<"Event Number "<<eventId<<" run: "<<runId<<endreq;
59
60 HltRawCol* aEF=new HltRawCol;
61
62 EFResult* efResult;
63 string answer="";
64 StatusCode sc = m_HltStoreSvc->get("EventType", efResult);
65 if ( sc.isFailure() ) {
66 log << MSG::ERROR << "Could not find EFResult (EventType)" << endreq;
67 answer="Error";
68 }
69 else {
70 if (efResult->getAnswerIndex() == -1) {
71 log << MSG::DEBUG << "Unvalid EFResult(AnswerIndex=-1)" << endreq;
72 answer="Error";
73 }
74 answer = efResult->getAnswer();
75 }
76 log << MSG::INFO << "The answer is " << answer << endreq;
77
78 uint32_t type=0;
79 if(answer=="Junk") type=1<<0;
80 else if(answer=="GJunk") type=(1<<1);
81 else if(answer=="Beamgas") type=1<<2;
82 else if(answer=="GBeamgas") type=(1<<3);
83 else if(answer=="Cosmic") type=1<<4;
84 else if(answer=="GCosmic") type=(1<<5);
85 else if(answer=="EBhabha") type=1<<6;
86 else if(answer=="GEBhabha") type=(1<<7);
87 else if(answer=="BBhabha") type=1<<8;
88 else if(answer=="GBBhabha") type=(1<<9);
89 else if(answer=="Dimuon") type=1<<10;
90 else if(answer=="GDimuon") type=(1<<11);
91 else if(answer=="Diphoton") type=1<<12;
92 else if(answer=="GDiphoton") type=(1<<13);
93 else if(answer=="Hadron") type=1<<14;
94 else if(answer=="GHadron") type=(1<<15);
95 else if(answer=="Twophoton") type=1<<16;
96 else if(answer=="GTwophoton") type=(1<<17);
97 else if(answer=="RandomTrg") type=1<<31;
98 else if(answer=="Error") type=1<<30;
99 else if(answer=="Other") type=1<<29;
100 else type=1<<28;
101
102 uint32_t id=0x50000000;
103 HltRaw* efType=new HltRaw(id);
104 efType->setIntChannel(type);
105 aEF->push_back(efType);
106
107 sc = m_HltStoreSvc->get("EFResult", efResult) ;
108 if ( sc.isFailure() ) {
109 log << MSG::FATAL << "Could not find EFResult (EFResult)" << endreq;
110 return StatusCode::FAILURE;
111 }
112 else {
113 uint32_t alg= efResult->getEFVec(0);
114 id++;
115 HltRaw* efAlg=new HltRaw(id);
116 uint32_t alg8=alg&0xFF;
117 efAlg->setIntChannel(alg8);
118 aEF->push_back(efAlg);
119 id++;
120 uint32_t cri=alg>>8;
121 HltRaw* efCri=new HltRaw(id);
122 efCri->setIntChannel(cri);
123 aEF->push_back(efCri);
124 id++;
125 HltRaw* efVer=new HltRaw(id);
126 efVer->setIntChannel(0);
127 aEF->push_back(efVer);
128 uint32_t etot= efResult->getEFVec(31);
129 id++;
130 HltRaw* efEtot=new HltRaw(id);
131 efEtot->setFloatChannel(*((float*)&etot));
132 aEF->push_back(efEtot);
133
134 uint32_t num=efResult->getEFVec(1);
135 int nmdc=num&0xFF;
136 int ntof=(num>>8)&0xFF;
137 int nemc=(num>>16)&0xFF;
138 int nmuc=(num>>24)&0xFF;
139 int ndata=1;
140
141 uint32_t ndatap = nmdc+ntof+nemc+nmuc;
142 ndata += ndatap;
143 int ndec=efResult->getDecNum();
144 if(ndec>0) ndata +=(ndec+1);
145
146 log << MSG::DEBUG << "ndata=" << ndata << "; nmdc=" << nmdc << ", ntof=" << ntof
147 << ", nemc=" << nemc << ", nmuc=" << nmuc << ", ndec=" << ndec << endreq;
148
149 if((alg&4)&&(!(alg&2))) log << MSG::WARNING<<"sub-algorithms error!"<<endreq;
150
151 uint32_t* var=new uint32_t[ndata];
152 if(ndata==1){
153 var[0]=0;
154 }
155 else{
156 var[0]=num;
157 int i=1;
158 for(int j=5;j<5+nmdc;j++){
159 var[i]=efResult->getEFVec(j);
160 ++i;
161 }
162 for(int j=25;j<25+ntof;j++){
163 var[i]=efResult->getEFVec(j);
164 ++i;
165 }
166 for(int j=30;j<30+nemc;j++){
167 var[i]=efResult->getEFVec(j);
168 ++i;
169 }
170 for(int j=52;j<52+nmuc;j++){
171 var[i]=efResult->getEFVec(j);
172 ++i;
173 }
174 if(ndec>0) {
175 var[i]=ndec;
176 ++i;
177 for(int j=54;j<54+ndec;++j){
178 var[i]=efResult->getEFVec(j);
179 ++i;
180 }
181 }
182 if(i!=ndata) log << MSG::FATAL << "number of datat error!" << endreq;
183 }
184
185 id++;
186 HltRaw* efTag=new HltRaw(id);
187 efTag->setIntChannel(var[0]);
188 aEF->push_back(efTag);
189
190 for(int i=1;i<ndata;i++){
191 id++;
192 HltRaw* efVar=new HltRaw(HltID::convert(id,nmdc,ntof,nemc,nmuc));
193 efVar->setFloatChannel(*((float*)&var[i]));
194 efVar->setIntChannel(var[i]);
195 aEF->push_back(efVar);
196 }
197 delete var;
198 }
199
200 uint32_t atype=0,alg=0,cri=0,ver=0;
201 float etot=0.;
202
203 DataObject *aHltEvent;
204 eventSvc()->findObject("/Event/Hlt", aHltEvent);
205 if(aHltEvent==NULL){
206 log<<MSG::INFO<< "HltEvent has not existed, so register it now!" <<endreq;
207 HltEvent* aHlt=new HltEvent();
208 sc = eventSvc()->registerObject(EventModel::Hlt::Event,aHlt);
209 if(sc!=StatusCode::SUCCESS) {
210 log<<MSG::FATAL<< "Could not register Hlt!!!" <<endreq;
211 return( StatusCode::FAILURE);
212 }
213 }
214 else{
215 log<<MSG::WARNING<< "HltEvent has existed!" <<endreq;
216 }
217
218 DataObject *aHltRawEvent;
219 eventSvc()->findObject("/Event/Hlt/HltRawCol", aHltRawEvent);
220 if(aHltRawEvent!=NULL) {
221 SmartDataPtr<HltRawCol> hltRawCol(eventSvc(),"/Event/Hlt/HltRawCol");
222 HltRawCol::iterator iter = hltRawCol->begin();
223 for (;iter != hltRawCol->end(); iter++ ) {
224 Identifier id = (*iter)->identify();
225 if(HltID::is_eventtype(id)) atype=(*iter)->getIntChannel();
226 if(HltID::is_algorithm(id)) alg=(*iter)->getIntChannel();
227 if(HltID::is_criteria(id)) cri=(*iter)->getIntChannel();
228 if(HltID::is_version(id)) ver=(*iter)->getIntChannel();
229 if(HltID::is_energy(id)) etot=(*iter)->getFloatChannel();
230 }
231 log<<MSG::DEBUG<<"old type="<<atype<<", alg="<<alg<<", criteria="<<cri
232 <<", version="<<ver<<", energy="<<etot<<endreq;
233 //then unregister HltRawCol
234 sc = eventSvc()->unregisterObject("/Event/Hlt/HltRawCol");
235 delete aHltRawEvent; //it must be delete to avoid memory leakage
236 log << MSG::INFO << "Old raw collection has been unregistered" << endreq;
237 if(sc!=StatusCode::SUCCESS) {
238 log << MSG::FATAL << "Could not unregister HLT raw collection" << endreq;
239 return( StatusCode::FAILURE);
240 }
241 }
242
243 // register
244 sc = eventSvc()->registerObject(EventModel::Hlt::HltRawCol,aEF);
245 if(sc!=StatusCode::SUCCESS) {
246 log<<MSG::FATAL<< "Still could not register HltRawCol" <<endreq;
247 return StatusCode::FAILURE;
248 }
249
250 SmartDataPtr<HltRawCol> hltRawCol(eventSvc(),"/Event/Hlt/HltRawCol");
251 if (!hltRawCol) {
252 log << MSG::FATAL << "Could not find HltRawCol!" << endreq;
253 return StatusCode::FAILURE;
254 }
255
256 HltRawCol::iterator iter = hltRawCol->begin();
257 for (;iter != hltRawCol->end(); iter++ ) {
258 Identifier id = (*iter)->identify();
259 if(HltID::is_eventtype(id)) atype=(*iter)->getIntChannel();
260 if(HltID::is_algorithm(id)) alg=(*iter)->getIntChannel();
261 if(HltID::is_criteria(id)) cri=(*iter)->getIntChannel();
262 if(HltID::is_version(id)) ver=(*iter)->getIntChannel();
263 if(HltID::is_energy(id)) etot=(*iter)->getFloatChannel();
264 }
265 log<<MSG::DEBUG<<" type="<<atype<<", alg="<<alg<<", criteria="<<cri
266 <<", version="<<ver<<", energy="<<etot<<endreq;
267
268 return StatusCode::SUCCESS;
269}
270
271StatusCode EFtoTDS::finalize() {
272
273 MsgStream log(msgSvc(), name());
274 log << MSG::INFO << "in finalize()" << endreq;
275
276 return StatusCode::SUCCESS;
277}
278
Double_t etot
Defines the EFResult RDO structure.
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
ObjectVector< HltRaw > HltRawCol
Definition HltRaw.h:35
IMessageSvc * msgSvc()
#define NULL
const int getDecNum() const
Definition EFResult.h:68
const std::string getAnswer() const
Definition EFResult.cxx:166
const int getAnswerIndex() const
Definition EFResult.cxx:168
const std::vector< uint32_t > getEFVec() const
Definition EFResult.cxx:51
StatusCode execute()
Definition EFtoTDS.cxx:45
virtual ~EFtoTDS()
Definition EFtoTDS.cxx:27
EFtoTDS(const std::string &name, ISvcLocator *pSvcLocator)
Definition EFtoTDS.cxx:22
StatusCode initialize()
Definition EFtoTDS.cxx:31
StatusCode finalize()
Definition EFtoTDS.cxx:271
static bool is_version(const Identifier &id)
Definition HltID.cxx:90
static bool is_eventtype(const Identifier &id)
Definition HltID.cxx:72
static Identifier convert(const unsigned int id, const int nmdc=0, const int ntof=0, const int nemc=0, const int nmuc=0)
convert global id to sub-id(Identifier)
Definition HltID.cxx:12
static bool is_algorithm(const Identifier &id)
Definition HltID.cxx:78
static bool is_criteria(const Identifier &id)
Definition HltID.cxx:84
static bool is_energy(const Identifier &id)
Definition HltID.cxx:96
void setIntChannel(const unsigned int intChannel)
Definition HltRaw.h:21
void setFloatChannel(const float value)
Definition HltRaw.h:24
bool get(const std::string &name, T &value)
Definition HltStoreSvc.h:76
_EXTERN_ std::string Event
Definition EventModel.h:72
_EXTERN_ std::string HltRawCol
Definition EventModel.h:73
Definition Event.h:21