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