1 #include "GaudiKernel/Kernel.h"
2 #include "GaudiKernel/ISvcLocator.h"
3 #include "GaudiKernel/IMessageSvc.h"
4 #include "GaudiKernel/IJobOptionsSvc.h"
5 #include "GaudiKernel/IAlgManager.h"
6 #include "GaudiKernel/IAuditorSvc.h"
7 #include "GaudiKernel/IDataProviderSvc.h"
8 #include "GaudiKernel/IConversionSvc.h"
9 #include "GaudiKernel/IHistogramSvc.h"
10 #include "GaudiKernel/INTupleSvc.h"
11 #include "GaudiKernel/IRndmGenSvc.h"
12 #include "GaudiKernel/IToolSvc.h"
13 #include "GaudiKernel/IExceptionSvc.h"
14 #include "GaudiKernel/IAlgContextSvc.h"
15 #include "GaudiKernel/IProperty.h"
17 #include "GaudiKernel/Algorithm.h"
18 #include "GaudiKernel/PropertyMgr.h"
19 #include "GaudiKernel/MsgStream.h"
20 #include "GaudiKernel/Chrono.h"
21 #include "GaudiKernel/Stat.h"
22 #include "GaudiKernel/GaudiException.h"
23 #include "GaudiKernel/ServiceLocatorHelper.h"
24 #include "GaudiKernel/ThreadGaudi.h"
25 #include "GaudiKernel/Guards.h"
29 const std::string& version)
32 m_registerContext (
false ) ,
33 m_pSvcLocator(pSvcLocator),
41 m_subAlgms =
new std::vector<Algorithm *>();
44 declareProperty(
"OutputLevel", m_outputLevel =
MSG::NIL);
45 declareProperty(
"Enable", m_isEnabled =
true);
46 declareProperty(
"ErrorMax", m_errorMax = 1);
47 declareProperty(
"ErrorCounter", m_errorCount = 0);
51 declareProperty(
"AuditAlgorithms", m_auditInit );
58 if (m_name !=
"IncidentSvc") {
61 audit = m_auditInit.value();
64 declareProperty(
"AuditInitialize" , m_auditorInitialize = audit ) ;
65 declareProperty(
"AuditReinitialize", m_auditorReinitialize = audit ) ;
66 declareProperty(
"AuditRestart" , m_auditorRestart = audit ) ;
67 declareProperty(
"AuditExecute" , m_auditorExecute = audit ) ;
68 declareProperty(
"AuditFinalize" , m_auditorFinalize = audit ) ;
69 declareProperty(
"AuditBeginRun" , m_auditorBeginRun = audit ) ;
70 declareProperty(
"AuditEndRun" , m_auditorEndRun = audit ) ;
71 declareProperty(
"AuditStart" , m_auditorStart = audit ) ;
72 declareProperty(
"AuditStop" , m_auditorStop = audit ) ;
74 declareProperty(
"MonitorService" , m_monitorSvcName =
"MonitorSvc" );
77 (
"RegisterForContextService" ,
79 "The flag to enforce the registration for Algorithm Context Service") ;
111 setOutputLevel( m_outputLevel );
120 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
129 (m_auditorInitialize) ? auditorSvc().
get() : 0,
137 std::vector<Algorithm *>::iterator it;
139 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
140 if ((*it)->sysInitialize().isFailure()) fail =
true;
145 log <<
MSG::ERROR <<
" Error initializing one or several sub-algorithms"
149 m_state = m_targetState;
157 <<
" is caught " <<
endmsg;
159 Stat stat( chronoSvc() , Exception.
tag() );
162 catch(
const std::exception& Exception )
167 Stat stat( chronoSvc() ,
"*std::exception*" );
174 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
196 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
206 (m_auditorStart) ? auditorSvc().
get() : 0,
214 std::vector<Algorithm *>::iterator it;
216 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
217 if ((*it)->sysStart().isFailure()) fail =
true;
222 log <<
MSG::ERROR <<
" Error starting one or several sub-algorithms"
226 m_state = m_targetState;
233 log <<
MSG::FATAL <<
"in sysStart(): exception with tag=" << Exception.
tag()
234 <<
" is caught" <<
endmsg;
236 Stat stat( chronoSvc() , Exception.
tag() );
239 catch(
const std::exception& Exception )
244 Stat stat( chronoSvc() ,
"*std::exception*" );
251 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
268 <<
"sysReinitialize(): cannot reinitialize algorithm not initialized"
275 setOutputLevel( m_outputLevel );
283 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
291 (m_auditorReinitialize) ? auditorSvc().
get() : 0,
299 std::vector<Algorithm *>::iterator it;
301 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
302 if((*it)->sysReinitialize().isFailure()) fail =
true;
309 <<
"sysReinitialize(): Error reinitializing one or several "
310 <<
"sub-algorithms" <<
endmsg;
317 log <<
MSG::FATAL <<
"sysReinitialize(): Exception with tag=" << Exception.
tag()
318 <<
" is caught" <<
endmsg;
320 Stat stat( chronoSvc() , Exception.
tag() );
323 catch(
const std::exception& Exception )
328 Stat stat( chronoSvc() ,
"*std::exception*" );
335 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
352 <<
"sysRestart(): cannot restart algorithm not started"
359 setOutputLevel( m_outputLevel );
367 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
375 (m_auditorRestart) ? auditorSvc().
get() : 0,
383 std::vector<Algorithm *>::iterator it;
385 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
386 if ((*it)->sysRestart().isFailure()) fail =
true;
392 <<
"sysRestart(): Error restarting one or several sub-algorithms"
401 <<
" is caught" <<
endmsg;
403 Stat stat( chronoSvc() , Exception.
tag() );
406 catch(
const std::exception& Exception )
411 Stat stat( chronoSvc() ,
"*std::exception*" );
418 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
433 setOutputLevel( m_outputLevel );
441 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
449 (m_auditorBeginRun) ? auditorSvc().
get() : 0,
457 std::vector<Algorithm *>::iterator it;
459 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
460 if((*it)->sysBeginRun().isFailure()) fail =
true;
465 log <<
MSG::ERROR <<
" Error executing BeginRun for one or several sub-algorithms"
474 <<
" is caught " <<
endmsg;
476 Stat stat( chronoSvc() , Exception.
tag() );
479 catch(
const std::exception& Exception )
484 Stat stat( chronoSvc() ,
"*std::exception*" );
491 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
509 setOutputLevel( m_outputLevel );
517 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
525 (m_auditorEndRun) ? auditorSvc().
get() : 0,
533 std::vector<Algorithm *>::iterator it;
535 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
536 if ((*it)->sysEndRun().isFailure()) fail =
true;
541 log <<
MSG::ERROR <<
" Error calling endRun for one or several sub-algorithms"
550 <<
" is caught " <<
endmsg;
552 Stat stat( chronoSvc() , Exception.
tag() );
555 catch(
const std::exception& Exception )
560 Stat stat( chronoSvc() ,
"*std::exception*" );
567 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
595 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
599 (m_auditorExecute) ? auditorSvc().
get() : 0,
607 status = exceptionSvc()->handleErr(*
this,status);
622 log <<
" Exception with tag=" << Exception.
tag()
623 <<
" is caught " <<
endmsg;
627 Stat stat( chronoSvc() , Exception.
tag() ) ;
628 status = exceptionSvc()->handle(*
this,Exception);
630 catch(
const std::exception& Exception )
637 Stat stat( chronoSvc() ,
"*std::exception*" ) ;
638 status = exceptionSvc()->handle(*
this,Exception);
646 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
648 status = exceptionSvc()->handle(*
this);
651 if( status.isFailure() ) {
656 if( m_errorCount < m_errorMax ) {
658 <<
", max=" << m_errorMax <<
")" <<
endmsg;
677 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
683 std::vector<Algorithm *>::iterator it;
684 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
685 (*it)->sysStop().ignore();
690 (m_auditorStop) ? auditorSvc().
get() : 0,
698 m_state = m_targetState;
704 <<
" is caught" <<
endmsg;
706 Stat stat( chronoSvc() , Exception.
tag() );
709 catch(
const std::exception& Exception ) {
713 Stat stat( chronoSvc() ,
"*std::exception*" );
719 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
736 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
743 std::vector<Algorithm *>::iterator it;
745 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
746 if (!(*it)->sysFinalize().isSuccess()) {
754 (m_auditorFinalize) ? auditorSvc().
get() : 0,
764 for (it = m_subAlgms->begin(); it != m_subAlgms->end(); it++) {
768 m_state = m_targetState;
775 <<
" is caught " <<
endmsg;
777 Stat stat( chronoSvc() , Exception.
tag() ) ;
780 catch(
const std::exception& Exception )
785 Stat stat( chronoSvc() ,
"*std::exception*" ) ;
792 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
850 m_isExecuted =
state;
854 m_isExecuted =
false;
855 m_filterPassed =
true;
863 return m_filterPassed;
867 m_filterPassed =
state;
878 { msgSvc()->setOutputLevel( name(), level ) ; }
879 m_outputLevel = msgSvc()->outputLevel( name() );
883 #define serviceAccessor(METHOD,INTERFACE,NAME,MEMBER) \
884 SmartIF<INTERFACE>& Algorithm::METHOD() const { \
885 if ( !MEMBER.isValid() ) { \
886 MEMBER = service(NAME); \
887 if( !MEMBER.isValid() ) { \
888 throw GaudiException("Service [" NAME "] not found", name(), StatusCode::FAILURE); \
897 if ( !m_MS.isValid() ) {
899 m_MS = serviceLocator();
900 if( !m_MS.isValid() ) {
940 return eventCnvSvc();
957 if ( 0 == m_pAuditorSvc ) {
958 StatusCode sc = service(
"AuditorSvc", m_pAuditorSvc,
true );
960 throw GaudiException(
"Service [AuditorSvc] not found", name(), sc);
963 return m_pAuditorSvc;
968 StatusCode sc = service(
"ChronoStatSvc", m_CSS,
true );
970 throw GaudiException(
"Service [ChronoStatSvc] not found", name(), sc);
978 StatusCode sc = service(
"DetectorDataSvc", m_DDS,
true );
980 throw GaudiException(
"Service [DetectorDataSvc] not found", name(), sc);
988 StatusCode sc = service(
"DetectorPersistencySvc", m_DCS,
true );
990 throw GaudiException(
"Service [DetectorPersistencySvc] not found",
999 StatusCode sc = service(
"EventDataSvc", m_EDS,
true );
1001 throw GaudiException(
"Service [EventDataSvc] not found", name(), sc);
1009 StatusCode sc = service(
"EventPersistencySvc", m_ECS,
true );
1020 StatusCode sc = service(
"HistogramDataSvc", m_HDS,
true );
1022 throw GaudiException(
"Service [HistogramDataSvc] not found", name(), sc);
1030 StatusCode sc = service(
"ExceptionSvc", m_EXS,
true );
1032 throw GaudiException(
"Service [ExceptionSvc] not found", name(), sc);
1041 StatusCode sc = serviceLocator()->service(
"MessageSvc", m_MS,
true );
1043 throw GaudiException(
"Service [MessageSvc] not found", name(), sc);
1051 StatusCode sc = service(
"NTupleSvc", m_NTS,
true );
1053 throw GaudiException(
"Service [NTupleSvc] not found", name(), sc);
1072 StatusCode sc = service(
"RndmGenSvc", m_RGS,
true );
1074 throw GaudiException(
"Service [RndmGenSvc] not found", name(), sc);
1081 if ( 0 == m_ptoolSvc ) {
1082 StatusCode sc = service(
"ToolSvc", m_ptoolSvc,
true );
1097 if( m_pSvcLocator != 0 ) {
1099 if( jos.isValid() ) {
1106 if(jos->setMyProperties( name(),
this ).isFailure()) {
1117 const std::string& name,
1131 pSubAlgorithm =
dynamic_cast<Algorithm*
>(tmp);
1132 m_subAlgms->push_back(pSubAlgorithm);
1142 return m_propertyMgr->setProperty(p);
1145 return m_propertyMgr->setProperty(s);
1148 return m_propertyMgr->setProperty(n,v);
1151 return m_propertyMgr->getProperty(p);
1154 return m_propertyMgr->getProperty(name);
1157 return m_propertyMgr->getProperty(n,v);
1160 return m_propertyMgr->getProperties();
1163 return m_propertyMgr->hasProperty(name);
1179 void** ppSvc)
const {
1181 return helper.getService(svcName, createIf, iid, ppSvc);
1186 const std::string& svcName,
1188 void** ppSvc)
const {
1190 return helper.createService(svcType, svcName, iid, ppSvc);
1195 return helper.service(name, quiet, createIf);
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
SmartIF< IDataProviderSvc > & detSvc() const
The standard detector data service.
std::vector< Algorithm * > * subAlgorithms() const
List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms.
Definition of the MsgStream class used to transmit messages.
an helper to share the implementation of service() among the various kernel base classes $Id: ...
virtual StatusCode setProperty(const Property &p)
Implementation of IProperty::setProperty.
SmartIF< IConversionSvc > & eventDataCnvService() const
Obsoleted name, kept due to the backwards compatibility.
virtual void setExecuted(bool state)
Set the executed flag to the specified state.
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
GAUDI_API std::string getGaudiThreadIDfromName(const std::string &name)
helper function to extract Gaudi Thread ID from thread copy name
StatusCode createSubAlgorithm(const std::string &type, const std::string &name, Algorithm *&pSubAlg)
Create a sub algorithm.
Helper "sentry" class to automatize the safe register/unregister the algorithm's context.
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
virtual StatusCode sysRestart()
Restart method invoked by the framework.
SmartIF< IHistogramSvc > & histoSvc() const
The standard histogram service.
virtual bool filterPassed() const
Did this algorithm pass or fail its filter criterion for the last event?
virtual ~Algorithm()
Destructor.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
GAUDI_API bool isGaudiThreaded(const std::string &name)
test if current Gaudi object is running /will run in a thread
StatusCode setProperties()
Set the algorithm's properties.
Small wrapper class for easy manipulation with generic counters and IStatSvc&ICounterSvc interface...
virtual StatusCode sysExecute()
The actions to be performed by the algorithm on an event.
bool isSuccess() const
Test for a status code of SUCCESS.
SmartIF< IExceptionSvc > & exceptionSvc() const
Get the exception Service.
virtual bool isEnabled() const
Is this algorithm enabled or disabled?
State GAUDI_API ChangeState(const Transition transition, const State state)
Function to get the new state according to the required transition, checking if the transition is all...
StatusCode service_i(const std::string &svcName, bool createIf, const InterfaceID &iid, void **ppSvc) const
implementation of service method
virtual bool isExecuted() const
Has this algorithm been executed since the last reset?
virtual StatusCode restart()
the default (empty) implementation of IStateful::restart() method
GAUDI_API std::string getGaudiThreadGenericName(const std::string &name)
helper function to extract Gaudi instance name from thread copy name
SmartIF< IAuditorSvc > & auditorSvc() const
The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Data provider interface definition.
Property manager helper class.
virtual StatusCode sysStart()
Reinitialization method invoked by the framework.
virtual StatusCode beginRun()
Algorithm begin run.
bool isFailure() const
Test for a status code of FAILURE.
virtual StatusCode sysReinitialize()
Reinitialization method invoked by the framework.
SmartIF< IDataProviderSvc > & detDataService() const
Obsoleted name, kept due to the backwards compatibility.
virtual StatusCode reinitialize()
the default (empty) implementation of IStateful::reinitialize() method
virtual StatusCode endRun()
Algorithm end run. This method is called at the end of the event loop.
virtual StatusCode sysEndRun()
endRun method invoked by the framework.
virtual const StatusCode & code() const
StatusCode for Exception.
virtual StatusCode sysFinalize()
System finalization.
SmartIF< IConversionSvc > & detDataCnvService() const
Obsoleted name, kept due to the backwards compatibility.
Random Generator service definition.
virtual const std::string & version() const
The version of the algorithm.
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
The IChronoStatSvc is the interface implemented by the ChronoStatService.
virtual void resetExecuted()
Reset the executed state of the Algorithm for the duration of the current event.
Random Generator service interface definition Definition of a interface for a service to access rando...
This class is used for returning status codes from appropriate routines.
virtual void setFilterPassed(bool state)
Set the filter passed flag to the specified state.
virtual StatusCode sysBeginRun()
beginRun method invoked by the framework.
Simple implementation of IExceptionSvc abstract interface.
The IMessage is the interface implemented by the message service.
virtual const std::string & name() const
The identifying name of the algorithm object.
serviceAccessor(auditorSvc, IAuditorSvc,"AuditorSvc", m_pAuditorSvc) serviceAccessor(chronoSvc
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition of the IHistogramSvc interface class.
SmartIF< IRndmGenSvc > & randSvc() const
AIDA-based NTuple service Returns a pointer to the AIDATuple service if present.
virtual StatusCode getProperty(Property *p) const
Implementation of IProperty::getProperty.
The IAlgorithm is the interface implemented by the Algorithm base class.
Algorithm(const std::string &name, ISvcLocator *svcloc, const std::string &version=PACKAGE_VERSION)
Constructor.
SmartIF< INTupleSvc > & ntupleSvc() const
The standard N tuple service.
void initOutputLevel(Property &prop)
callback for output level property
SmartIF< IChronoStatSvc > & chronoSvc() const
The standard Chrono & Stat service, Return a pointer to the service if present.
SmartIF< IConversionSvc > & eventCnvSvc() const
The standard event data persistency conversion service.
Base class from which all concrete algorithm classes should be derived.
virtual StatusCode sysInitialize()
Initialization method invoked by the framework.
Property base class allowing Property* collections to be "homogeneous".
SmartIF< IDataProviderSvc > & eventSvc() const
The standard event data service.
m_CSS m_DCS EventPersistencySvc
virtual bool hasProperty(const std::string &name) const
Implementation of IProperty::hasProperty.
m_CSS DetectorPersistencySvc
An abstract interface for Algorithm Context Service.
virtual StatusCode sysStop()
System stop.
SmartIF< IDataProviderSvc > & eventDataService() const
Obsoleted name, kept due to the backwards compatibility.
SmartIF< IHistogramSvc > & histogramDataService() const
Obsoleted name, kept due to the backwards compatibility.
SmartIF< IMessageSvc > & messageService() const
Obsoleted name, kept due to the backwards compatibility.
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
It is a simple guard, which "locks" the scope for the Auditor Service is am exception-safe way...
The interface implemented by the IAuditorSvc base class.
SmartIF< INTupleSvc > & ntupleService() const
Obsoleted name, kept due to the backwards compatibility.
SmartIF< IConversionSvc > & detCnvSvc() const
The standard detector data persistency conversion service.
Helper functions to set/get the application return code.
The abstract interface for exception handling service.
void setOutputLevel(int level)
Set the output level for current algorithm.
The Chrono & Stat Sservice: service implements the IChronoStatSvc interface and provides the basic ch...
virtual const std::vector< Property * > & getProperties() const
Implementation of IProperty::getProperties.