13#define GAUDISVC_EFEVENTLOOPMGR_CPP
16#include "GaudiKernel/DataObject.h"
17#include "GaudiKernel/DataSelectionAgent.h"
18#include "GaudiKernel/IAlgManager.h"
19#include "GaudiKernel/IAlgorithm.h"
20#include "GaudiKernel/IConversionSvc.h"
21#include "GaudiKernel/IDataManagerSvc.h"
22#include "GaudiKernel/IDataProviderSvc.h"
23#include "GaudiKernel/IEvtSelector.h"
24#include "GaudiKernel/IIncidentSvc.h"
25#include "GaudiKernel/Incident.h"
26#include "GaudiKernel/MsgStream.h"
27#include "GaudiKernel/SmartDataPtr.h"
28#include "GaudiKernel/SmartIF.h"
29#include "GaudiKernel/ThreadGaudi.h"
38#include "EventModel/Event.h"
39#include "EventModel/EventHeader.h"
40#include "EventModel/EventModel.h"
44#include "eformat/eformat.h"
47#include "RawDataCnv/EventManagement/RAWEVENT.h"
48#include "RawDataCnv/RawDataAddress.h"
55 : MinimalEventLoopMgr( nam, svcLoc ) {
56 declareProperty(
"EvtSel",
m_evtsel );
58 declareProperty(
"DisableEFResult", m_disableEFResult =
true );
59 declareProperty(
"OkexecuteEvent", m_okexecuteEvent =
true );
60 declareProperty(
"OutputLevel", m_outputLevel = MSG::ALWAYS );
61 declareProperty(
"TimeTest", m_timeTest = 0 );
93 MsgStream log(
msgSvc(), name() );
95 cout <<
"EFEventLoopMgr::initialize() there are " << m_topAlgList.size() <<
" topAlg now"
97 StatusCode sc = MinimalEventLoopMgr::initialize();
100 log << MSG::INFO <<
"EFEventLoopMgr:initalize(): ---> EventLoopMgr = " << name()
101 <<
" initializing " << endmsg;
102 if ( !sc.isSuccess() )
105 <<
"EFEventLoopMgr:initalize():Failed to initialize base class MinimalEventLoopMgr"
110 sc = serviceLocator()->service(
"EventDataSvc",
m_evtDataMgrSvc,
true );
111 if ( !sc.isSuccess() )
113 log << MSG::FATAL <<
"Error retrieving EventDataSvc interface IDataManagerSvc." << endmsg;
116 sc = serviceLocator()->service(
"EventDataSvc",
m_evtDataSvc,
true );
117 if ( !sc.isSuccess() )
119 log << MSG::FATAL <<
"Error retrieving EventDataSvc interface IDataProviderSvc." << endmsg;
125 sc = serviceLocator()->service(
"IncidentSvc",
m_incidentSvc,
true );
127 if ( !sc.isSuccess() )
129 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():Error retrieving IncidentSvc" << endmsg;
136 sc = serviceLocator()->service(
"HltStoreSvc",
m_HltStoreSvc,
true );
137 if ( !sc.isSuccess() )
139 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():Error retrieving HltStoreSvc" << endmsg;
146 SmartIF<IProperty> prpMgr( serviceLocator() );
147 if ( !prpMgr.isValid() )
150 <<
"EFEventLoopMgr:initalize():IProperty interface not found in ApplicationMgr."
152 return StatusCode::FAILURE;
159 setProperty( prpMgr->getProperty(
"EvtSel" ) );
164 sc = serviceLocator()->service(
"EventSelector",
m_evtSelector,
true );
165 if ( sc.isSuccess() )
168 if ( !sc.isSuccess() )
170 log << MSG::FATAL <<
"Can not create the event selector Context." << endmsg;
176 log << MSG::FATAL <<
"EFEventLoopMgr:initalize():EventSelector not found." << endmsg;
177 return StatusCode::FAILURE;
185 <<
"EFEventLoopMgr:initalize():No service \"EventSelector\" provided : assume "
186 "\"online\" running "
193 sc = serviceLocator()->getService(
"RawDataInputSvc", svc );
194 if ( sc != StatusCode::SUCCESS )
196 log << MSG::WARNING <<
" Cant get RawDataInputSvc " << endmsg;
201 if ( m_inputSvc == 0 )
203 log << MSG::WARNING <<
" Cant cast to RawDataInputSvc " << endmsg;
204 return StatusCode::FAILURE;
208 if ( sc.isFailure() )
210 log << MSG::ERROR <<
"Could not find EventType" << endmsg;
211 return StatusCode::FAILURE;
214 if ( sc.isFailure() )
216 log << MSG::ERROR <<
"Could not find EFResult" << endmsg;
217 return StatusCode::FAILURE;
234 return StatusCode::SUCCESS;
241 MsgStream log(
msgSvc(), name() );
243 <<
" EFEventLoopMgr:finalize():Number of events processed : " << m_total_nevt << endmsg;
257 StatusCode sc = MinimalEventLoopMgr::finalize();
270 DataObject* pObject = 0;
271 MsgStream log(
msgSvc(), name() );
282 m_firstEvent =
false;
284 else { m_re->reset(); }
290 std::cerr << std::endl <<
"Uncaught eformat issue: " << ex.
what() << std::endl;
291 return StatusCode::FAILURE;
294 std::cerr << std::endl <<
"Uncaught ERS issue: " << ex.
what() << std::endl;
295 return StatusCode::FAILURE;
296 }
catch ( std::exception& ex )
298 std::cerr << std::endl <<
"Uncaught std exception: " << ex.
what() << std::endl;
299 return StatusCode::FAILURE;
302 std::cerr << std::endl <<
"Uncaught unknown exception" << std::endl;
303 return StatusCode::FAILURE;
307 <<
" words in " << pre.
nchildren() <<
" subdetectors " << endmsg;
309 m_re->setRunNo( pre.
run_no() );
311 m_re->setTime( pre.
time() );
315 if ( nrobs > 100 ) log << MSG::ERROR <<
"ROBFragments' number exceeds than 100!" << endmsg;
317 for (
int robi = 0; robi < nrobs; robi++ )
322 if ( ( status & 0x2 ) && ( sourceid != 0xa50000 ) )
324 std::string answer =
"Error";
327 m_evtType->setAnswer( answer );
328 log << MSG::DEBUG <<
"detector status is " << status << endmsg;
330 return StatusCode::SUCCESS;
335 for (
int robi = 0; robi < nrobs; robi++ )
338 uint32_t* dataptr = NULL;
340 vector<uint32_t> DetElements( dataptr, ( dataptr + rob.
rod_ndata() ) );
344 source_id_number <<= 8;
345 source_id_number >>= 24;
348 log << MSG::DEBUG << source_id_number <<
" Digi size=" << DetElements.size() << endmsg;
349 switch ( source_id_number )
352 m_re->addReMdcDigi( dataptr, DetElements.size() );
355 case 163: m_re->addReEmcDigi( dataptr, DetElements.size() );
break;
358 m_re->addReTofDigi( dataptr, DetElements.size() );
362 m_re->addReMucDigi( dataptr, DetElements.size() );
371 std::string answer =
"RandomTrg";
374 m_evtType->setAnswer( answer );
375 log << MSG::DEBUG <<
"a random trigger event is taken" << endmsg;
377 return StatusCode::SUCCESS;
385 if ( !( m_inputSvc->setCurrentEvent( m_re ) ) )
387 log << MSG::FATAL <<
"m_inputSvc->setCurrentEvent(m_re) Failed!" << endmsg;
391 if ( 0 != m_total_nevt )
394 if ( !sc.isSuccess() )
395 { log << MSG::DEBUG <<
"Clear of Event data store failed" << endmsg; }
433 IOpaqueAddress* addr = 0;
435 if ( !sc.isSuccess() )
437 log << MSG::WARNING <<
"Error creating IOpaqueAddress." << endmsg;
442 if ( !sc.isSuccess() )
444 log << MSG::WARNING <<
"Error declaring event root address." << endmsg;
448 if ( !sc.isSuccess() )
450 log << MSG::WARNING <<
"Unable to retrieve Event root object" << endmsg;
456 m_incidentSvc->fireIncident( Incident( name(),
"BeginEvent" ) );
458 sc = MinimalEventLoopMgr::executeEvent( NULL );
460 m_incidentSvc->fireIncident( Incident( name(),
"EndEvent" ) );
476 if ( !sc.isSuccess() ) {
return sc; }
479 if ( !sc.isSuccess() )
482 if ( sc.isSuccess() )
485 if ( !sc.isSuccess() )
487 MsgStream log(
msgSvc(), name() );
488 log << MSG::WARNING <<
"Error creating IOpaqueAddress." << endmsg;
501 else {
return MinimalEventLoopMgr::queryInterface( riid, ppvInterface ); }
503 return StatusCode::SUCCESS;
510 MsgStream log(
msgSvc(), name() );
512 int run_num = ef_run_number;
513 log << MSG::DEBUG <<
" ---> EFprepareForRun::Received run number from PT = " << run_num
516 log << MSG::DEBUG <<
" ---> EFprepareForRun::Setup IOVSvc for run number = " << run_num
525 m_incidentSvc->fireIncident( Incident( name(),
"BeginRun" ) );
526 ListAlg::iterator ita;
528 for ( ita = m_topAlgList.begin(); ita != m_topAlgList.end(); ita++ )
530 sc = ( *ita )->sysBeginRun();
531 if ( !sc.isSuccess() )
533 log << MSG::WARNING <<
"beginRun() of algorithm " << ( *ita )->name() <<
" failed"
539 if ( failed )
return StatusCode::FAILURE;
540 else return StatusCode::SUCCESS;
548 MsgStream log(
msgSvc(), name() );
549 if ( m_disableEFResult )
551 std::string defaultEFDecision =
"Other";
553 <<
"EFEventLoopMgr:EF_Decision():---> EFResult handling is disabled. Default "
555 << defaultEFDecision << endmsg;
556 if ( m_okexecuteEvent != 1 )
558 std::string defaultEFDecision =
"Error";
560 <<
"EFEventLoopMgr:EF_Decision():---> Error in executeEvent, setting EFDecision to: "
561 << defaultEFDecision << endmsg;
562 return defaultEFDecision;
564 return defaultEFDecision;
573 if ( m_evtType->getAnswerIndex() == -1 )
575 log << MSG::DEBUG <<
"EF_Decision(): Unvalid EFResult(AnswerIndex=-1)" << endmsg;
578 std::string answer = m_evtType->getAnswer();
579 log << MSG::INFO <<
"The answer is " << answer << endmsg;
585 MsgStream log(
msgSvc(), name() );
589 uint32_t version = ( x << 16 ) + ( y << 8 ) + z;
590 log << MSG::INFO <<
"The version is " << version << endmsg;
594 MsgStream log(
msgSvc(), name() );
595 uint32_t alg = m_efResult->getEFVec( 0 );
597 int itype = m_evtType->getMidAnswerIndex();
599 if ( itype != -1 ) alg += ( 1 << itype );
600 uint32_t alg16 = alg >> 16;
601 log << MSG::DEBUG <<
"The algorithm tag is " << alg <<
":" << ( alg & 1 )
602 << ( ( alg >> 1 ) & 1 ) << ( ( alg >> 2 ) & 1 ) << ( ( alg >> 3 ) & 1 )
603 << ( ( alg >> 4 ) & 1 ) << ( ( alg >> 5 ) & 1 ) << ( ( alg >> 6 ) & 1 )
604 << ( ( alg >> 7 ) & 1 ) <<
":%# " << alg16 << endmsg;
609 MsgStream log(
msgSvc(), name() );
610 uint32_t
etot = m_efResult->getEFVec( 31 );
611 log << MSG::INFO <<
"The total energy is " << *( (
float*)&
etot ) <<
"GeV" << endmsg;
618 MsgStream log(
msgSvc(), name() );
620 if ( m_disableEFResult )
623 <<
"EFEventLoopMgr:EF_Fragment_Address():---> EFResult handling is disabled!!!! No "
624 "pointer to EF Fragment will be given."
633 uint32_t alg = m_efResult->getEFVec( 0 );
634 log << MSG::DEBUG <<
"alg=" << alg << endmsg;
635 uint32_t
num = m_efResult->getEFVec( 1 );
636 int nmdc =
num & 0xFF;
637 int ntof = (
num >> 8 ) & 0xFF;
638 int nemc = (
num >> 16 ) & 0xFF;
639 int nmuc = (
num >> 24 ) & 0xFF;
641 uint32_t ndatap = nmdc + ntof + nemc + nmuc;
643 int ndec = m_efResult->getDecNum();
644 if ( ndec > 0 ) ndata += ( ndec + 1 );
645 if ( ( alg & 4 ) && ( !( alg & 2 ) ) )
646 log << MSG::WARNING <<
"sub-algorithms error!" << endmsg;
649 log << MSG::FATAL <<
"data length error!" << endmsg;
652 log << MSG::INFO <<
"sent data lenth=" << ndata + 40 << endmsg;
656 if ( efAddress == NULL )
return NULL;
657 efAddress[0] = 0xbb1234bb;
660 efAddress[3] = 0x3000000;
661 efAddress[4] = 0x7c0000;
665 efAddress[8] = 0xcc1234cc;
666 efAddress[9] = efAddress[1] - efAddress[2];
668 efAddress[11] = 0x3000000;
669 efAddress[12] = 0x7c0000;
676 efAddress[19] = 0xdd1234dd;
677 efAddress[20] = efAddress[9] - efAddress[10];
679 efAddress[22] = 0x3000000;
680 efAddress[23] = 0x7c0000;
684 efAddress[27] = 0xee1234ee;
686 efAddress[29] = 0x3000000;
687 efAddress[30] = 0x7c0000;
694 efAddress[36 + ndata] = 0;
695 efAddress[37 + ndata] = 1;
696 efAddress[38 + ndata] = ndata;
697 efAddress[39 + ndata] = 1;
699 if ( ndata == 1 ) {
return efAddress; }
703 for (
int j = 5; j < 5 + nmdc; j++ )
708 for (
int j = 25; j < 25 + ntof; j++ )
713 for (
int j = 30; j < 30 + nemc; j++ )
718 for (
int j = 52; j < 52 + nmuc; j++ )
727 for (
int j = 54; j < 54 + ndec; ++j )
733 log << MSG::DEBUG <<
"0th eff data is "
738 for (
int i = 1; i < ndatap + 1; i++ )
740 log << MSG::DEBUG << i <<
"th eff data is "
743 for (
int i = ndatap + 1; i < ndata; i++ )
745 log << MSG::DEBUG << i <<
"th eff data is " << efAddress[
ONLINE_DATA_HEAD + i]
861 MsgStream log(
msgSvc(), name() );
862 log << MSG::DEBUG << ndata <<
":" << ( *data ) <<
"," << endmsg;
865 while ( ndata - index > 1 )
867 uint32_t header = *(
data + index );
868 uint32_t blockSize = ( ( header >> 14 ) & 0x3FF );
869 uint32_t
id = ( header >> 24 );
872 if ( blockSize == 0 || ( index + blockSize ) > ndata )
break;
875 uint32_t window = ( ( header >> 8 ) & 0x3F );
876 uint32_t size = blockSize - 1;
879 log << MSG::FATAL <<
"window=0" << endmsg;
882 else if ( size % window != 0 )
884 log << MSG::FATAL <<
"GTL data is NOT completed" << endmsg;
888 for ( uint32_t j = 0; j < size; j++ )
890 uint32_t trgdata = *(
data + index + 1 + j );
891 uint32_t dataId = ( ( trgdata >> 24 ) & 0x7 );
894 if ( dataId != 5 )
continue;
896 m_trgType = m_trgType | ( trgdata & 0xFFFF );
897 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.
This class provides general information about an event. It extends EventInfo with a list of sub-evts ...
static const InterfaceID & interfaceID()
Retrieve interface ID.
const char * what() const
Human description message.