1#include "HltAlgorithms/EFtoTDS.h"
2#include "HltDataTypes/EFResult.h"
4#include "GaudiKernel/MsgStream.h"
5#include "GaudiKernel/SmartDataPtr.h"
10#include "EventModel/Event.h"
11#include "EventModel/EventHeader.h"
12#include "HltEvent/HltEvent.h"
13#include "HltEvent/HltRaw.h"
14#include "Identifier/Identifier.h"
15#include "Identifier/HltID.h"
23 Algorithm(name, pSvcLocator) {
24 declareProperty(
"OutputLevel", m_outputLevel);
33 MsgStream log(
msgSvc(), name());
34 log << MSG::INFO <<
"in initialize()" << endreq;
36 StatusCode sc = service(
"HltStoreSvc", m_HltStoreSvc);
37 if( sc.isFailure() ) {
38 log << MSG::FATAL << name() <<
": Unable to locate Service HltStoreSvc" << endreq;
42 return StatusCode::SUCCESS;
47 MsgStream log(
msgSvc(), name());
48 log << MSG::DEBUG <<
"in execute()" << endreq;
50 SmartDataPtr<Event::EventHeader> eventHeader(eventSvc(),
"/Event/EventHeader");
52 log << MSG::FATAL <<
"Could not find Event Header" << endreq;
53 return StatusCode::FAILURE;
56 int eventId = eventHeader->eventNumber() ;
57 int runId = eventHeader->runNumber();
58 log << MSG::INFO <<
"retrieved event: " <<
"Event Number "<<eventId<<
" run: "<<runId<<endreq;
64 StatusCode sc = m_HltStoreSvc->
get(
"EventType", efResult);
65 if ( sc.isFailure() ) {
66 log << MSG::ERROR <<
"Could not find EFResult (EventType)" << endreq;
71 log << MSG::DEBUG <<
"Unvalid EFResult(AnswerIndex=-1)" << endreq;
76 log << MSG::INFO <<
"The answer is " << answer << endreq;
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;
102 uint32_t
id=0x50000000;
105 aEF->push_back(efType);
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;
113 uint32_t alg= efResult->
getEFVec(0);
116 uint32_t alg8=alg&0xFF;
118 aEF->push_back(efAlg);
123 aEF->push_back(efCri);
127 aEF->push_back(efVer);
132 aEF->push_back(efEtot);
136 int ntof=(
num>>8)&0xFF;
137 int nemc=(
num>>16)&0xFF;
138 int nmuc=(
num>>24)&0xFF;
141 uint32_t ndatap = nmdc+ntof+nemc+nmuc;
144 if(ndec>0) ndata +=(ndec+1);
146 log << MSG::DEBUG <<
"ndata=" << ndata <<
"; nmdc=" << nmdc <<
", ntof=" << ntof
147 <<
", nemc=" << nemc <<
", nmuc=" << nmuc <<
", ndec=" << ndec << endreq;
149 if((alg&4)&&(!(alg&2))) log << MSG::WARNING<<
"sub-algorithms error!"<<endreq;
151 uint32_t* var=
new uint32_t[ndata];
158 for(
int j=5;j<5+nmdc;j++){
162 for(
int j=25;j<25+ntof;j++){
166 for(
int j=30;j<30+nemc;j++){
170 for(
int j=52;j<52+nmuc;j++){
177 for(
int j=54;j<54+ndec;++j){
182 if(i!=ndata) log << MSG::FATAL <<
"number of datat error!" << endreq;
188 aEF->push_back(efTag);
190 for(
int i=1;i<ndata;i++){
195 aEF->push_back(efVar);
200 uint32_t atype=0,alg=0,cri=0,ver=0;
203 DataObject *aHltEvent;
204 eventSvc()->findObject(
"/Event/Hlt", aHltEvent);
206 log<<MSG::INFO<<
"HltEvent has not existed, so register it now!" <<endreq;
209 if(sc!=StatusCode::SUCCESS) {
210 log<<MSG::FATAL<<
"Could not register Hlt!!!" <<endreq;
211 return( StatusCode::FAILURE);
215 log<<MSG::WARNING<<
"HltEvent has existed!" <<endreq;
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++ ) {
231 log<<MSG::DEBUG<<
"old type="<<atype<<
", alg="<<alg<<
", criteria="<<cri
232 <<
", version="<<ver<<
", energy="<<
etot<<endreq;
234 sc = eventSvc()->unregisterObject(
"/Event/Hlt/HltRawCol");
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);
245 if(sc!=StatusCode::SUCCESS) {
246 log<<MSG::FATAL<<
"Still could not register HltRawCol" <<endreq;
247 return StatusCode::FAILURE;
250 SmartDataPtr<HltRawCol> hltRawCol(eventSvc(),
"/Event/Hlt/HltRawCol");
252 log << MSG::FATAL <<
"Could not find HltRawCol!" << endreq;
253 return StatusCode::FAILURE;
256 HltRawCol::iterator
iter = hltRawCol->begin();
257 for (;
iter != hltRawCol->end();
iter++ ) {
265 log<<MSG::DEBUG<<
" type="<<atype<<
", alg="<<alg<<
", criteria="<<cri
266 <<
", version="<<ver<<
", energy="<<
etot<<endreq;
268 return StatusCode::SUCCESS;
273 MsgStream log(
msgSvc(), name());
274 log << MSG::INFO <<
"in finalize()" << endreq;
276 return StatusCode::SUCCESS;
ObjectVector< HltRaw > HltRawCol
const int getDecNum() const
const std::string getAnswer() const
const int getAnswerIndex() const
const std::vector< uint32_t > getEFVec() const
EFtoTDS(const std::string &name, ISvcLocator *pSvcLocator)
static bool is_version(const Identifier &id)
static bool is_eventtype(const Identifier &id)
static bool is_algorithm(const Identifier &id)
static bool is_criteria(const Identifier &id)
static Identifier convert(const unsigned int id, const int nmdc=0, const int ncgem=0, const int ntof=0, const int nemc=0, const int nmuc=0)
convert global id to sub-id(Identifier)
static bool is_energy(const Identifier &id)
void setIntChannel(const unsigned int intChannel)
void setFloatChannel(const float value)
bool get(const std::string &name, T &value)
_EXTERN_ std::string Event
_EXTERN_ std::string HltRawCol