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"
50: MinimalEventLoopMgr(nam, svcLoc)
52 declareProperty(
"EvtSel",
m_evtsel );
54 declareProperty(
"DisableEFResult", m_disableEFResult =
true);
55 declareProperty(
"OkexecuteEvent", m_okexecuteEvent =
true);
56 declareProperty(
"OutputLevel", m_outputLevel = MSG::ALWAYS);
57 declareProperty(
"TimeTest", m_timeTest = 0);
93 StatusCode sc = MinimalEventLoopMgr::initialize();
96 MsgStream log(
msgSvc(), name());
97 log << MSG::INFO <<
"EFEventLoopMgr:initalize(): ---> EventLoopMgr = " << name() <<
" initializing " << endreq;
98 if ( !sc.isSuccess() ) {
100 <<
"EFEventLoopMgr:initalize():Failed to initialize base class MinimalEventLoopMgr"
108 if( !sc.isSuccess() ) {
109 log << MSG::FATAL <<
"Error retrieving EventDataSvc interface IDataManagerSvc." << endreq;
112 sc = serviceLocator()->service(
"EventDataSvc",
m_evtDataSvc,
true);
114 if( !sc.isSuccess() ) {
115 log << MSG::FATAL <<
"Error retrieving EventDataSvc interface IDataProviderSvc." << endreq;
122 sc = serviceLocator()->service(
"IncidentSvc" ,
m_incidentSvc,
true);
124 if( !sc.isSuccess() ) {
125 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():Error retrieving IncidentSvc" << endreq;
132 sc = serviceLocator()->service(
"HltStoreSvc" ,
m_HltStoreSvc,
true);
133 if( !sc.isSuccess() ) {
134 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():Error retrieving HltStoreSvc" << endreq;
141 SmartIF<IProperty> prpMgr(serviceLocator());
142 if ( !prpMgr.isValid() ) {
144 <<
"EFEventLoopMgr:initalize():IProperty interface not found in ApplicationMgr."
146 return StatusCode::FAILURE;
153 setProperty(prpMgr->getProperty(
"EvtSel"));
157 sc = serviceLocator()->service(
"EventSelector" ,
m_evtSelector,
true );
158 if( sc.isSuccess() ) {
160 if( !sc.isSuccess() ) {
161 log << MSG::FATAL <<
"Can not create the event selector Context." << endreq;
165 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():EventSelector not found." << endreq;
166 return StatusCode::FAILURE;
172 <<
"EFEventLoopMgr:initalize():No service \"EventSelector\" provided : assume \"online\" running "
180 sc = serviceLocator()->getService(
"RawDataInputSvc", svc);
181 if(sc != StatusCode::SUCCESS ) {
182 log<<MSG::WARNING <<
" Cant get RawDataInputSvc " <<endreq;
187 if(m_inputSvc == 0 ) {
188 log<<MSG::WARNING <<
" Cant cast to RawDataInputSvc " <<endreq;
189 return StatusCode::FAILURE ;
193 if ( sc.isFailure() ) {
194 log << MSG::ERROR <<
"Could not find EventType" << endreq;
195 return StatusCode::FAILURE ;
198 if ( sc.isFailure() ) {
199 log << MSG::ERROR <<
"Could not find EFResult" << endreq;
200 return StatusCode::FAILURE ;
216 return StatusCode::SUCCESS;
224 MsgStream log(
msgSvc(), name());
225 log << MSG::INFO <<
" EFEventLoopMgr:finalize():Number of events processed : " << m_total_nevt << endreq;
239 return MinimalEventLoopMgr::finalize();
251 DataObject* pObject = 0;
252 MsgStream log(
msgSvc(), name() );
260 if(m_firstEvent) m_re =
new RAWEVENT;
270 std::cerr << std::endl
271 <<
"Uncaught eformat issue: " << ex.
what() << std::endl;
272 return StatusCode::FAILURE ;
275 std::cerr << std::endl
276 <<
"Uncaught ERS issue: " << ex.
what() << std::endl;
277 return StatusCode::FAILURE ;
279 catch (std::exception& ex) {
280 std::cerr << std::endl
281 <<
"Uncaught std exception: " << ex.
what() << std::endl;
282 return StatusCode::FAILURE ;
285 std::cerr << std::endl <<
"Uncaught unknown exception" << std::endl;
286 return StatusCode::FAILURE ;
289 log << MSG::DEBUG <<
"[Event No. #" << pre.
global_id()
300 if(nrobs>100) log<<MSG::ERROR<<
"ROBFragments' number exceeds than 100!"<<endreq;
302 for (
int robi = 0; robi < nrobs; robi++) {
306 if((status&0x2)&&(sourceid!=0xa50000)) {
307 std::string answer=
"Error";
311 log << MSG::DEBUG <<
"detector status is "<<status<<endreq;
313 return StatusCode::SUCCESS;
318 for (
int robi = 0; robi < nrobs; robi++) {
320 uint32_t* dataptr = NULL;
322 vector<uint32_t> DetElements(dataptr, (dataptr+rob.
rod_ndata()));
326 source_id_number <<= 8;
327 source_id_number >>= 24;
330 log<<MSG::DEBUG<< source_id_number <<
" Digi size="<<DetElements.size()<<endreq;
331 switch(source_id_number)
356 std::string answer=
"RandomTrg";
360 log << MSG::DEBUG <<
"a random trigger event is taken" << endreq;
362 return StatusCode::SUCCESS;
371 log << MSG::FATAL <<
"m_inputSvc->setCurrentEvent(m_re) Failed!" << endreq;
375 if( 0 != m_total_nevt ) {
377 if( !sc.isSuccess() ) {
378 log << MSG::DEBUG <<
"Clear of Event data store failed" << endreq;
387 if( !sc.isSuccess() ) {
388 log << MSG::WARNING <<
"Error declaring event root address." << endreq;
392 if( !sc.isSuccess() ) {
393 log << MSG::WARNING <<
"Unable to retrieve Event root object" << endreq;
401 sc = MinimalEventLoopMgr::executeEvent(NULL);
419 if ( !sc.isSuccess() ) {
424 if( !sc.isSuccess() ) {
426 if ( sc.isSuccess() ) {
428 if ( !sc.isSuccess() ) {
429 MsgStream log(
msgSvc(), name() );
430 log << MSG::WARNING <<
"Error creating IOpaqueAddress." << endreq;
445 return MinimalEventLoopMgr::queryInterface(riid, ppvInterface);
448 return StatusCode::SUCCESS;
456 MsgStream log(
msgSvc(), name() );
458 int run_num = ef_run_number;
459 log << MSG::DEBUG <<
" ---> EFprepareForRun::Received run number from PT = "
460 << run_num << endreq;
463 <<
" ---> EFprepareForRun::Setup IOVSvc for run number = "
464 << run_num << endreq;
473 return StatusCode::SUCCESS;
482 MsgStream log(
msgSvc(), name() );
483 if (m_disableEFResult) {
484 std::string defaultEFDecision =
"Other" ;
486 <<
"EFEventLoopMgr:EF_Decision():---> EFResult handling is disabled. Default EFDecision = "
489 if (m_okexecuteEvent!=1){
490 std::string defaultEFDecision =
"Error";
492 <<
"EFEventLoopMgr:EF_Decision():---> Error in executeEvent, setting EFDecision to: "<< defaultEFDecision << endreq;
493 return defaultEFDecision;
495 return defaultEFDecision;
504 log << MSG::DEBUG <<
"EF_Decision(): Unvalid EFResult(AnswerIndex=-1)" << endreq;
507 std::string answer = m_evtType->
getAnswer();
508 log << MSG::INFO <<
"The answer is " << answer << endreq;
515 MsgStream log(
msgSvc(), name() );
519 uint32_t version=(
x<<16)+(y<<8)+z;
520 log << MSG::INFO <<
"The version is " <<version << endreq;
525 MsgStream log(
msgSvc(), name() );
526 uint32_t alg=m_efResult->
getEFVec(0);
530 if(itype != -1) alg += (1<<itype);
531 uint32_t alg16=alg>>16;
532 log << MSG::DEBUG <<
"The algorithm tag is " << alg <<
":"
533 << (alg&1)<<((alg>>1)&1)<<((alg>>2)&1)<<((alg>>3)&1)
534 <<((alg>>4)&1)<<((alg>>5)&1)<<((alg>>6)&1)<<((alg>>7)&1)
535 <<
":%# "<< alg16<<endreq;
541 MsgStream log(
msgSvc(), name() );
543 log << MSG::INFO <<
"The total energy is " <<*((
float*)&
etot) <<
"GeV"<<endreq;
550 MsgStream log(
msgSvc(), name() );
552 if (m_disableEFResult) {
553 log << MSG::WARNING <<
"EFEventLoopMgr:EF_Fragment_Address():---> EFResult handling is disabled!!!! No pointer to EF Fragment will be given." << endreq;
560 uint32_t alg=m_efResult->
getEFVec(0);
561 log << MSG::DEBUG <<
"alg="<<alg<<endreq;
564 int ntof=(
num>>8)&0xFF;
565 int nemc=(
num>>16)&0xFF;
566 int nmuc=(
num>>24)&0xFF;
568 uint32_t ndatap = nmdc+ntof+nemc+nmuc;
571 if(ndec>0) ndata +=(ndec+1);
572 if((alg&4)&&(!(alg&2))) log << MSG::WARNING<<
"sub-algorithms error!"<<endreq;
574 log << MSG::FATAL <<
"data length error!" <<endreq;
577 log << MSG::INFO<<
"sent data lenth=" << ndata+40<<endreq;
581 if(efAddress==NULL)
return NULL;
582 efAddress[0]=0xbb1234bb;
585 efAddress[3]=0x3000000;
586 efAddress[4]=0x7c0000;
590 efAddress[8]=0xcc1234cc;
591 efAddress[9]=efAddress[1]-efAddress[2];
593 efAddress[11]=0x3000000;
594 efAddress[12]=0x7c0000;
601 efAddress[19]=0xdd1234dd;
602 efAddress[20]=efAddress[9]-efAddress[10];
604 efAddress[22]=0x3000000;
605 efAddress[23]=0x7c0000;
609 efAddress[27]=0xee1234ee;
611 efAddress[29]=0x3000000;
612 efAddress[30]=0x7c0000;
619 efAddress[36+ndata]=0;
620 efAddress[37+ndata]=1;
621 efAddress[38+ndata]=ndata;
622 efAddress[39+ndata]=1;
629 for(
int j=5;j<5+nmdc;j++){
633 for(
int j=25;j<25+ntof;j++){
637 for(
int j=30;j<30+nemc;j++){
641 for(
int j=52;j<52+nmuc;j++){
648 for(
int j=54;j<54+ndec;++j){
653 log << MSG::DEBUG <<
"0th eff data is "
658 for(
int i=1;i<ndatap+1;i++){
659 log << MSG::DEBUG <<i<<
"th eff data is " <<*((
float*)&(efAddress[
ONLINE_DATA_HEAD+i]))<<endreq;
661 for(
int i=ndatap+1;i<ndata;i++){
662 log << MSG::DEBUG <<i<<
"th eff data is " << efAddress[
ONLINE_DATA_HEAD+i]<<endreq;
778 MsgStream log(
msgSvc(), name() );
779 log << MSG::DEBUG << ndata<<
":"<<(*data)<<
","<<endreq;
782 while (ndata - index > 1) {
783 uint32_t header= *(
data+index);
784 uint32_t blockSize = ( (header>>14) & 0x3FF);
785 uint32_t
id = (header>>24);
788 if (blockSize == 0 || (index+blockSize) > ndata)
break;
790 uint32_t window = ((header >> 8) & 0x3F);
791 uint32_t size= blockSize-1;
793 log << MSG::FATAL <<
"window=0" << endreq;
796 else if(size%window != 0) {
797 log << MSG::FATAL <<
"GTL data is NOT completed" << endreq;
801 for(uint32_t j = 0; j < size; j++) {
802 uint32_t trgdata = *(
data+index+1+j);
803 uint32_t dataId = ((trgdata >> 24) & 0x7);
805 if(dataId!=5)
continue;
807 m_trgType= m_trgType|(trgdata&0xFFFF);
808 if(trgdata&(1<<9))
return true;
Defines the EFResult RDO structure.
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)
IConversionSvc * m_histoPersSvc
Reference to the Histogram Persistency Service.
virtual ~EFEventLoopMgr()
Standard Destructor.
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
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
IIncidentSvc * m_incidentSvc
Reference to the indicent service.
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
IDataManagerSvc * m_evtDataMgrSvc
Reference to the Event Data Service's IDataManagerSvc interface.
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
implementation of IInterface: queryInterface
IEvtSelector::Context * m_evtContext
Event Context.
IDataProviderSvc * m_evtDataSvc
Reference to the Event Data Service's IDataProviderSvc interface.
virtual uint32_t EF_Algorithm_Tag()
return algorithm tag
IDataManagerSvc * m_histoDataMgrSvc
Reference to the Histogram Data Service.
HltStoreSvc * m_HltStoreSvc
Reference to HltStoreSvc;.
IEvtSelector * m_evtSelector
Reference to the Event Selector.
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.