13#define GAUDISVC_EFEVENTLOOPMGR_CPP
16#include "GaudiKernel/IAlgorithm.h"
17#include "GaudiKernel/SmartIF.h"
18#include "GaudiKernel/Incident.h"
19#include "GaudiKernel/MsgStream.h"
20#include "GaudiKernel/DataSelectionAgent.h"
21#include "GaudiKernel/DataObject.h"
22#include "GaudiKernel/IIncidentSvc.h"
23#include "GaudiKernel/IEvtSelector.h"
24#include "GaudiKernel/IDataManagerSvc.h"
25#include "GaudiKernel/IDataProviderSvc.h"
26#include "GaudiKernel/IConversionSvc.h"
27#include "GaudiKernel/ThreadGaudi.h"
28#include "GaudiKernel/SmartDataPtr.h"
29#include "GaudiKernel/IAlgManager.h"
31#include "HltDataTypes/EventIncident.h"
32#include "HltDataTypes/EventInfo.h"
33#include "HltDataTypes/EventID.h"
34#include "HltDataTypes/EventType.h"
35#include "HltDataTypes/EFResult.h"
38#include "EventModel/EventModel.h"
39#include "EventModel/Event.h"
40#include "EventModel/EventHeader.h"
42#include "EFServices/EFEventLoopMgr.h"
44#include "eformat/eformat.h"
47#include "RawDataCnv/EventManagement/RAWEVENT.h"
48#include "RawDataCnv/RawDataAddress.h"
56: MinimalEventLoopMgr(nam, svcLoc)
58 declareProperty(
"EvtSel",
m_evtsel );
60 declareProperty(
"DisableEFResult", m_disableEFResult =
true);
61 declareProperty(
"OkexecuteEvent", m_okexecuteEvent =
true);
62 declareProperty(
"OutputLevel", m_outputLevel = MSG::ALWAYS);
63 declareProperty(
"TimeTest", m_timeTest = 0);
97 MsgStream log(
msgSvc(), name());
99 cout <<
"EFEventLoopMgr::initialize() there are " << m_topAlgList.size() <<
" topAlg now" << endl;
100 StatusCode sc = MinimalEventLoopMgr::initialize();
103 log << MSG::INFO <<
"EFEventLoopMgr:initalize(): ---> EventLoopMgr = " << name() <<
" initializing " << endreq;
104 if ( !sc.isSuccess() ) {
106 <<
"EFEventLoopMgr:initalize():Failed to initialize base class MinimalEventLoopMgr"
112 if( !sc.isSuccess() ) {
113 log << MSG::FATAL <<
"Error retrieving EventDataSvc interface IDataManagerSvc." << endreq;
116 sc = serviceLocator()->service(
"EventDataSvc",
m_evtDataSvc,
true);
117 if( !sc.isSuccess() ) {
118 log << MSG::FATAL <<
"Error retrieving EventDataSvc interface IDataProviderSvc." << endreq;
124 sc = serviceLocator()->service(
"IncidentSvc" ,
m_incidentSvc,
true);
126 if( !sc.isSuccess() ) {
127 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():Error retrieving IncidentSvc" << endreq;
134 sc = serviceLocator()->service(
"HltStoreSvc" ,
m_HltStoreSvc,
true);
135 if( !sc.isSuccess() ) {
136 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():Error retrieving HltStoreSvc" << endreq;
143 SmartIF<IProperty> prpMgr(serviceLocator());
144 if ( !prpMgr.isValid() ) {
146 <<
"EFEventLoopMgr:initalize():IProperty interface not found in ApplicationMgr."
148 return StatusCode::FAILURE;
155 setProperty(prpMgr->getProperty(
"EvtSel"));
159 sc = serviceLocator()->service(
"EventSelector" ,
m_evtSelector,
true );
160 if( sc.isSuccess() ) {
162 if( !sc.isSuccess() ) {
163 log << MSG::FATAL <<
"Can not create the event selector Context." << endreq;
167 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():EventSelector not found." << endreq;
168 return StatusCode::FAILURE;
174 <<
"EFEventLoopMgr:initalize():No service \"EventSelector\" provided : assume \"online\" running "
181 sc = serviceLocator()->getService(
"RawDataInputSvc", svc);
182 if(sc != StatusCode::SUCCESS ) {
183 log<<MSG::WARNING <<
" Cant get RawDataInputSvc " <<endreq;
188 if(m_inputSvc == 0 ) {
189 log<<MSG::WARNING <<
" Cant cast to RawDataInputSvc " <<endreq;
190 return StatusCode::FAILURE ;
194 if ( sc.isFailure() ) {
195 log << MSG::ERROR <<
"Could not find EventType" << endreq;
196 return StatusCode::FAILURE ;
199 if ( sc.isFailure() ) {
200 log << MSG::ERROR <<
"Could not find EFResult" << endreq;
201 return StatusCode::FAILURE ;
217 return StatusCode::SUCCESS;
225 MsgStream log(
msgSvc(), name());
226 log << MSG::INFO <<
" EFEventLoopMgr:finalize():Number of events processed : " << m_total_nevt << endreq;
239 StatusCode sc = MinimalEventLoopMgr::finalize();
253 DataObject* pObject = 0;
254 MsgStream log(
msgSvc(), name() );
275 std::cerr << std::endl
276 <<
"Uncaught eformat issue: " << ex.
what() << std::endl;
277 return StatusCode::FAILURE ;
280 std::cerr << std::endl
281 <<
"Uncaught ERS issue: " << ex.
what() << std::endl;
282 return StatusCode::FAILURE ;
284 catch (std::exception& ex) {
285 std::cerr << std::endl
286 <<
"Uncaught std exception: " << ex.
what() << std::endl;
287 return StatusCode::FAILURE ;
290 std::cerr << std::endl <<
"Uncaught unknown exception" << std::endl;
291 return StatusCode::FAILURE ;
294 log << MSG::DEBUG <<
"[Event No. #" << pre.
global_id()
305 if(nrobs>100) log<<MSG::ERROR<<
"ROBFragments' number exceeds than 100!"<<endreq;
307 for (
int robi = 0; robi < nrobs; robi++) {
311 if((status&0x2)&&(sourceid!=0xa50000)) {
312 std::string answer=
"Error";
316 log << MSG::DEBUG <<
"detector status is "<<status<<endreq;
318 return StatusCode::SUCCESS;
323 for (
int robi = 0; robi < nrobs; robi++) {
325 uint32_t* dataptr = NULL;
327 vector<uint32_t> DetElements(dataptr, (dataptr+rob.
rod_ndata()));
331 source_id_number <<= 8;
332 source_id_number >>= 24;
335 log<<MSG::DEBUG<< source_id_number <<
" Digi size="<<DetElements.size()<<endreq;
336 switch(source_id_number)
361 std::string answer=
"RandomTrg";
365 log << MSG::DEBUG <<
"a random trigger event is taken" << endreq;
367 return StatusCode::SUCCESS;
376 log << MSG::FATAL <<
"m_inputSvc->setCurrentEvent(m_re) Failed!" << endreq;
380 if( 0 != m_total_nevt ) {
382 if( !sc.isSuccess() ) {
383 log << MSG::DEBUG <<
"Clear of Event data store failed" << endreq;
422 IOpaqueAddress* addr = 0;
424 if( !sc.isSuccess() ) {
425 log << MSG::WARNING <<
"Error creating IOpaqueAddress." << endreq;
430 if( !sc.isSuccess() ) {
431 log << MSG::WARNING <<
"Error declaring event root address." << endreq;
435 if( !sc.isSuccess() ) {
436 log << MSG::WARNING <<
"Unable to retrieve Event root object" << endreq;
444 sc = MinimalEventLoopMgr::executeEvent(NULL);
462 if ( !sc.isSuccess() ) {
467 if( !sc.isSuccess() ) {
469 if ( sc.isSuccess() ) {
471 if ( !sc.isSuccess() ) {
472 MsgStream log(
msgSvc(), name() );
473 log << MSG::WARNING <<
"Error creating IOpaqueAddress." << endreq;
488 return MinimalEventLoopMgr::queryInterface(riid, ppvInterface);
491 return StatusCode::SUCCESS;
499 MsgStream log(
msgSvc(), name() );
501 int run_num = ef_run_number;
502 log << MSG::DEBUG <<
" ---> EFprepareForRun::Received run number from PT = "
503 << run_num << endreq;
506 <<
" ---> EFprepareForRun::Setup IOVSvc for run number = "
507 << run_num << endreq;
515 ListAlg::iterator ita;
517 for (ita = m_topAlgList.begin(); ita != m_topAlgList.end(); ita++ ) {
518 sc = (*ita)->sysBeginRun();
519 if( !sc.isSuccess() ) {
520 log << MSG::WARNING <<
"beginRun() of algorithm " << (*ita)->name() <<
" failed" << endmsg;
525 if(failed)
return StatusCode::FAILURE;
526 else return StatusCode::SUCCESS;
535 MsgStream log(
msgSvc(), name() );
536 if (m_disableEFResult) {
537 std::string defaultEFDecision =
"Other" ;
539 <<
"EFEventLoopMgr:EF_Decision():---> EFResult handling is disabled. Default EFDecision = "
542 if (m_okexecuteEvent!=1){
543 std::string defaultEFDecision =
"Error";
545 <<
"EFEventLoopMgr:EF_Decision():---> Error in executeEvent, setting EFDecision to: "<< defaultEFDecision << endreq;
546 return defaultEFDecision;
548 return defaultEFDecision;
557 log << MSG::DEBUG <<
"EF_Decision(): Unvalid EFResult(AnswerIndex=-1)" << endreq;
560 std::string answer = m_evtType->
getAnswer();
561 log << MSG::INFO <<
"The answer is " << answer << endreq;
568 MsgStream log(
msgSvc(), name() );
572 uint32_t version=(
x<<16)+(y<<8)+z;
573 log << MSG::INFO <<
"The version is " <<version << endreq;
578 MsgStream log(
msgSvc(), name() );
579 uint32_t alg=m_efResult->
getEFVec(0);
583 if(itype != -1) alg += (1<<itype);
584 uint32_t alg16=alg>>16;
585 log << MSG::DEBUG <<
"The algorithm tag is " << alg <<
":"
586 << (alg&1)<<((alg>>1)&1)<<((alg>>2)&1)<<((alg>>3)&1)
587 <<((alg>>4)&1)<<((alg>>5)&1)<<((alg>>6)&1)<<((alg>>7)&1)
588 <<
":%# "<< alg16<<endreq;
594 MsgStream log(
msgSvc(), name() );
596 log << MSG::INFO <<
"The total energy is " <<*((
float*)&
etot) <<
"GeV"<<endreq;
603 MsgStream log(
msgSvc(), name() );
605 if (m_disableEFResult) {
606 log << MSG::WARNING <<
"EFEventLoopMgr:EF_Fragment_Address():---> EFResult handling is disabled!!!! No pointer to EF Fragment will be given." << endreq;
613 uint32_t alg=m_efResult->
getEFVec(0);
614 log << MSG::DEBUG <<
"alg="<<alg<<endreq;
617 int ntof=(
num>>8)&0xFF;
618 int nemc=(
num>>16)&0xFF;
619 int nmuc=(
num>>24)&0xFF;
621 uint32_t ndatap = nmdc+ntof+nemc+nmuc;
624 if(ndec>0) ndata +=(ndec+1);
625 if((alg&4)&&(!(alg&2))) log << MSG::WARNING<<
"sub-algorithms error!"<<endreq;
627 log << MSG::FATAL <<
"data length error!" <<endreq;
630 log << MSG::INFO<<
"sent data lenth=" << ndata+40<<endreq;
634 if(efAddress==NULL)
return NULL;
635 efAddress[0]=0xbb1234bb;
638 efAddress[3]=0x3000000;
639 efAddress[4]=0x7c0000;
643 efAddress[8]=0xcc1234cc;
644 efAddress[9]=efAddress[1]-efAddress[2];
646 efAddress[11]=0x3000000;
647 efAddress[12]=0x7c0000;
654 efAddress[19]=0xdd1234dd;
655 efAddress[20]=efAddress[9]-efAddress[10];
657 efAddress[22]=0x3000000;
658 efAddress[23]=0x7c0000;
662 efAddress[27]=0xee1234ee;
664 efAddress[29]=0x3000000;
665 efAddress[30]=0x7c0000;
672 efAddress[36+ndata]=0;
673 efAddress[37+ndata]=1;
674 efAddress[38+ndata]=ndata;
675 efAddress[39+ndata]=1;
682 for(
int j=5;j<5+nmdc;j++){
686 for(
int j=25;j<25+ntof;j++){
690 for(
int j=30;j<30+nemc;j++){
694 for(
int j=52;j<52+nmuc;j++){
701 for(
int j=54;j<54+ndec;++j){
706 log << MSG::DEBUG <<
"0th eff data is "
711 for(
int i=1;i<ndatap+1;i++){
712 log << MSG::DEBUG <<i<<
"th eff data is " <<*((
float*)&(efAddress[
ONLINE_DATA_HEAD+i]))<<endreq;
714 for(
int i=ndatap+1;i<ndata;i++){
715 log << MSG::DEBUG <<i<<
"th eff data is " << efAddress[
ONLINE_DATA_HEAD+i]<<endreq;
831 MsgStream log(
msgSvc(), name() );
832 log << MSG::DEBUG << ndata<<
":"<<(*data)<<
","<<endreq;
835 while (ndata - index > 1) {
836 uint32_t header= *(
data+index);
837 uint32_t blockSize = ( (header>>14) & 0x3FF);
838 uint32_t
id = (header>>24);
841 if (blockSize == 0 || (index+blockSize) > ndata)
break;
843 uint32_t window = ((header >> 8) & 0x3F);
844 uint32_t size= blockSize-1;
846 log << MSG::FATAL <<
"window=0" << endreq;
849 else if(size%window != 0) {
850 log << MSG::FATAL <<
"GTL data is NOT completed" << endreq;
854 for(uint32_t j = 0; j < size; j++) {
855 uint32_t trgdata = *(
data+index+1+j);
856 uint32_t dataId = ((trgdata >> 24) & 0x7);
858 if(dataId!=5)
continue;
860 m_trgType= m_trgType|(trgdata&0xFFFF);
861 if(trgdata&(1<<9))
return true;
virtual bool getTrigChn(uint32_t *data, uint32_t ndata)
whether it is a RrandomTrg
std::string m_evtsel
Event selector.
virtual StatusCode executeEvent(void *par)
implementation of IEventProcessor::executeEvent(void* par)
virtual ~EFEventLoopMgr()
Standard Destructor.
IEvtSelector::Context * m_evtContext
Event Context.
std::string m_histPersName
Name of the Hist Pers type.
virtual StatusCode initialize()
implementation of IAppMgrUI::initalize
virtual std::string EF_Decision()
return data from EF decision
virtual StatusCode finalize()
implementation of IAppMgrUI::finalize
StatusCode getEventRoot(IOpaqueAddress *&refpAddr)
Create event address using event selector.
EventID::number_type m_currentRun
current run number
IDataManagerSvc * m_histoDataMgrSvc
Reference to the Histogram Data Service.
virtual uint32_t EF_Version()
return version number
EFEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
virtual uint32_t EF_Total_Energy()
return total energy
IEvtSelector * m_evtSelector
Reference to the Event Selector.
virtual uint32_t * EF_Fragment_Address()
Return a pointer to the local memory containing the EF subdetector fragment.
virtual StatusCode prepareForRun(int ef_run_number)
prepare for run step
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
implementation of IInterface: queryInterface
IConversionSvc * m_histoPersSvc
Reference to the Histogram Persistency Service.
HltStoreSvc * m_HltStoreSvc
Reference to HltStoreSvc;.
virtual uint32_t EF_Algorithm_Tag()
return algorithm tag
IDataManagerSvc * m_evtDataMgrSvc
Reference to the Event Data Service's IDataManagerSvc interface.
IDataProviderSvc * m_evtDataSvc
Reference to the Event Data Service's IDataProviderSvc interface.
IIncidentSvc * m_incidentSvc
Reference to the indicent service.
const int getDecNum() const
const std::string getAnswer() const
const int getMidAnswerIndex() const
void setAnswer(std::string &answer)
const int getAnswerIndex() const
const std::vector< uint32_t > getEFVec() const
This class provides general information about an event. It extends EventInfo with a list of sub-evts ...
bool get(const std::string &name, T &value)
static const InterfaceID & interfaceID()
Retrieve interface ID.
void addReTofDigi(uint32_t *digi, uint32_t size)
void setRunNo(uint32_t run_no)
void addReMdcDigi(uint32_t *digi, uint32_t size)
void addReMucDigi(uint32_t *digi, uint32_t size)
void setTime(uint32_t time)
void setEventNo(uint32_t event_no)
void addReEmcDigi(uint32_t *digi, uint32_t size)
const char * what() const
Human description message.