2 #include "GaudiKernel/Kernel.h"
3 #include "GaudiKernel/ISvcLocator.h"
4 #include "GaudiKernel/IMessageSvc.h"
5 #include "GaudiKernel/IJobOptionsSvc.h"
6 #include "GaudiKernel/IAlgManager.h"
7 #include "GaudiKernel/IAuditorSvc.h"
8 #include "GaudiKernel/IDataProviderSvc.h"
9 #include "GaudiKernel/IConversionSvc.h"
10 #include "GaudiKernel/IHistogramSvc.h"
11 #include "GaudiKernel/INTupleSvc.h"
12 #include "GaudiKernel/IRndmGenSvc.h"
13 #include "GaudiKernel/IToolSvc.h"
14 #include "GaudiKernel/IExceptionSvc.h"
15 #include "GaudiKernel/IAlgContextSvc.h"
16 #include "GaudiKernel/IProperty.h"
18 #include "GaudiKernel/Algorithm.h"
19 #include "GaudiKernel/PropertyMgr.h"
20 #include "GaudiKernel/MsgStream.h"
21 #include "GaudiKernel/Chrono.h"
22 #include "GaudiKernel/Stat.h"
23 #include "GaudiKernel/GaudiException.h"
24 #include "GaudiKernel/ServiceLocatorHelper.h"
25 #include "GaudiKernel/ThreadGaudi.h"
26 #include "GaudiKernel/Guards.h"
29 template <StatusCode (Algorithm::*f)(),
typename C >
bool for_algorithms(C&
c) {
31 [](
bool b,
Algorithm* a) {
return (a->*f)().isSuccess() && b; } );
37 const std::string& version)
40 m_pSvcLocator(pSvcLocator),
45 declareProperty(
"OutputLevel", m_outputLevel =
MSG::NIL);
46 declareProperty(
"Enable", m_isEnabled =
true);
47 declareProperty(
"ErrorMax", m_errorMax = 1);
48 declareProperty(
"ErrorCounter", m_errorCount = 0);
52 declareProperty(
"AuditAlgorithms", m_auditInit );
59 if (m_name !=
"IncidentSvc") {
62 audit = m_auditInit.value();
65 declareProperty(
"AuditInitialize" , m_auditorInitialize = audit ) ;
66 declareProperty(
"AuditReinitialize", m_auditorReinitialize = audit ) ;
67 declareProperty(
"AuditRestart" , m_auditorRestart = audit ) ;
68 declareProperty(
"AuditExecute" , m_auditorExecute = audit ) ;
69 declareProperty(
"AuditFinalize" , m_auditorFinalize = audit ) ;
70 declareProperty(
"AuditBeginRun" , m_auditorBeginRun = audit ) ;
71 declareProperty(
"AuditEndRun" , m_auditorEndRun = audit ) ;
72 declareProperty(
"AuditStart" , m_auditorStart = audit ) ;
73 declareProperty(
"AuditStop" , m_auditorStop = audit ) ;
75 declareProperty(
"MonitorService" , m_monitorSvcName =
"MonitorSvc" );
78 (
"RegisterForContextService" ,
80 "The flag to enforce the registration for Algorithm Context Service") ;
105 setOutputLevel( m_outputLevel );
114 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
123 (m_auditorInitialize) ? auditorSvc().
get() : 0,
132 for (
auto& it : m_subAlgms ) {
133 if (it->sysInitialize().isFailure()) fail =
true;
138 log <<
MSG::ERROR <<
" Error initializing one or several sub-algorithms"
142 m_state = m_targetState;
150 <<
" is caught " <<
endmsg;
152 Stat stat( chronoSvc() , Exception.
tag() );
155 catch(
const std::exception& Exception )
160 Stat stat( chronoSvc() ,
"*std::exception*" );
167 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
189 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
199 (m_auditorStart) ? auditorSvc().
get() : 0,
207 if( !for_algorithms<&Algorithm::sysStart>( m_subAlgms ) ) {
210 log <<
MSG::ERROR <<
" Error starting one or several sub-algorithms"
214 m_state = m_targetState;
221 log <<
MSG::FATAL <<
"in sysStart(): exception with tag=" << Exception.
tag()
222 <<
" is caught" <<
endmsg;
224 Stat stat( chronoSvc() , Exception.
tag() );
227 catch(
const std::exception& Exception )
232 Stat stat( chronoSvc() ,
"*std::exception*" );
239 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
256 <<
"sysReinitialize(): cannot reinitialize algorithm not initialized"
263 setOutputLevel( m_outputLevel );
271 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
279 (m_auditorReinitialize) ? auditorSvc().
get() : 0,
287 if ( !for_algorithms<&Algorithm::sysReinitialize>( m_subAlgms ) ) {
291 <<
"sysReinitialize(): Error reinitializing one or several "
292 <<
"sub-algorithms" <<
endmsg;
299 log <<
MSG::FATAL <<
"sysReinitialize(): Exception with tag=" << Exception.
tag()
300 <<
" is caught" <<
endmsg;
302 Stat stat( chronoSvc() , Exception.
tag() );
305 catch(
const std::exception& Exception )
310 Stat stat( chronoSvc() ,
"*std::exception*" );
317 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
334 <<
"sysRestart(): cannot restart algorithm not started"
341 setOutputLevel( m_outputLevel );
349 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
357 (m_auditorRestart) ? auditorSvc().
get() : 0,
365 if( !for_algorithms<&Algorithm::sysRestart>( m_subAlgms ) ) {
369 <<
"sysRestart(): Error restarting one or several sub-algorithms"
378 <<
" is caught" <<
endmsg;
380 Stat stat( chronoSvc() , Exception.
tag() );
383 catch(
const std::exception& Exception )
388 Stat stat( chronoSvc() ,
"*std::exception*" );
395 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
410 setOutputLevel( m_outputLevel );
418 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
426 (m_auditorBeginRun) ? auditorSvc().
get() : 0,
434 if( !for_algorithms<&Algorithm::sysBeginRun>( m_subAlgms ) ) {
437 log <<
MSG::ERROR <<
" Error executing BeginRun for one or several sub-algorithms"
446 <<
" is caught " <<
endmsg;
448 Stat stat( chronoSvc() , Exception.
tag() );
451 catch(
const std::exception& Exception )
456 Stat stat( chronoSvc() ,
"*std::exception*" );
463 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
481 setOutputLevel( m_outputLevel );
489 (
this , registerContext() ? contextSvc().
get() :
nullptr ) ;
497 (m_auditorEndRun) ? auditorSvc().
get() : 0,
505 if( !for_algorithms<&Algorithm::sysEndRun>( m_subAlgms ) ) {
508 log <<
MSG::ERROR <<
" Error calling endRun for one or several sub-algorithms"
517 <<
" is caught " <<
endmsg;
519 Stat stat( chronoSvc() , Exception.
tag() );
522 catch(
const std::exception& Exception )
527 Stat stat( chronoSvc() ,
"*std::exception*" );
534 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
562 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
566 (m_auditorExecute) ? auditorSvc().
get() : 0,
574 status = exceptionSvc()->handleErr(*
this,status);
589 log <<
" Exception with tag=" << Exception.
tag()
590 <<
" is caught " <<
endmsg;
594 Stat stat( chronoSvc() , Exception.
tag() ) ;
595 status = exceptionSvc()->handle(*
this,Exception);
597 catch(
const std::exception& Exception )
604 Stat stat( chronoSvc() ,
"*std::exception*" ) ;
605 status = exceptionSvc()->handle(*
this,Exception);
613 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
615 status = exceptionSvc()->handle(*
this);
618 if( status.isFailure() ) {
623 if( m_errorCount < m_errorMax ) {
625 <<
", max=" << m_errorMax <<
")" <<
endmsg;
644 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
650 for_algorithms<&Algorithm::sysStop>( m_subAlgms );
654 (m_auditorStop) ? auditorSvc().
get() : 0,
662 m_state = m_targetState;
668 <<
" is caught" <<
endmsg;
670 Stat stat( chronoSvc() , Exception.
tag() );
673 catch(
const std::exception& Exception ) {
677 Stat stat( chronoSvc() ,
"*std::exception*" );
683 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
700 (
this , registerContext() ? contextSvc().
get() : 0 ) ;
707 bool ok = for_algorithms<&Algorithm::sysFinalize>( m_subAlgms );
711 (m_auditorFinalize) ? auditorSvc().
get() : 0,
721 for (
auto& it : m_subAlgms ) it->release();
723 m_state = m_targetState;
730 <<
" is caught " <<
endmsg;
732 Stat stat( chronoSvc() , Exception.
tag() ) ;
735 catch(
const std::exception& Exception )
740 Stat stat( chronoSvc() ,
"*std::exception*" ) ;
747 Stat stat( chronoSvc() ,
"*UNKNOWN Exception*" ) ;
805 m_isExecuted =
state;
809 m_isExecuted =
false;
810 m_filterPassed =
true;
818 return m_filterPassed;
822 m_filterPassed =
state;
837 { msgSvc()->setOutputLevel(
name(), level ) ; }
838 m_outputLevel = msgSvc()->outputLevel(
name() );
842 #define serviceAccessor(METHOD,INTERFACE,NAME,MEMBER) \
843 SmartIF<INTERFACE>& Algorithm::METHOD() const { \
845 MEMBER = service(NAME); \
847 throw GaudiException("Service [" NAME "] not found", name(), StatusCode::FAILURE); \
870 m_MS = serviceLocator();
896 return eventCnvSvc();
917 if( m_pSvcLocator ) {
918 auto jos = m_pSvcLocator->service<
IJobOptionsSvc>(
"JobOptionsSvc");
926 if(jos->setMyProperties( name(),
this ).isFailure()) {
937 const std::string& name,
951 pSubAlgorithm =
dynamic_cast<Algorithm*
>(tmp);
952 m_subAlgms.push_back(pSubAlgorithm);
962 return m_propertyMgr->setProperty(p);
965 return m_propertyMgr->setProperty(s);
968 return m_propertyMgr->setProperty(n,v);
971 return m_propertyMgr->getProperty(p);
974 return m_propertyMgr->getProperty(name);
977 return m_propertyMgr->getProperty(n,v);
980 return m_propertyMgr->getProperties();
983 return m_propertyMgr->hasProperty(name);
999 void** ppSvc)
const {
1001 return helper.getService(svcName, createIf, iid, ppSvc);
1006 const std::string& svcName,
1008 void** ppSvc)
const {
1010 return helper.createService(svcType, svcName, iid, ppSvc);
1015 return helper.service(name, quiet, createIf);
StatusCode endRun() override
Algorithm end run. This method is called at the end of the event loop.
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
void resetExecuted() override
Reset the executed state of the Algorithm for the duration of the current event.
Definition of the MsgStream class used to transmit messages.
an helper to share the implementation of service() among the various kernel base classes ...
Small smart pointer class with automatic reference counting for IInterface.
SmartIF< IConversionSvc > & eventDataCnvService() const
Obsoleted name, kept due to the backwards compatibility.
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 sysEndRun() override
endRun method invoked by the framework.
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.
const std::string & version() const override
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
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...
auto begin(reverse_wrapper< T > &w)
StatusCode sysBeginRun() override
beginRun method invoked by the framework.
bool isSuccess() const
Test for a status code of SUCCESS.
StatusCode setProperty(const Property &p) override
Implementation of IProperty::setProperty.
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
SmartIF< IChronoStatSvc > & chronoStatService() const
Obsoleted name, kept due to the backwards compatibility.
bool filterPassed() const override
Did this algorithm pass or fail its filter criterion for the last event?
GAUDI_API std::string getGaudiThreadGenericName(const std::string &name)
helper function to extract Gaudi instance name from thread copy name
Data provider interface definition.
Property manager helper class.
bool isFailure() const
Test for a status code of FAILURE.
SmartIF< IDataProviderSvc > & detDataService() const
Obsoleted name, kept due to the backwards compatibility.
virtual const StatusCode & code() const
StatusCode for Exception.
StatusCode sysRestart() override
Restart method invoked by the framework.
SmartIF< IConversionSvc > & detDataCnvService() const
Obsoleted name, kept due to the backwards compatibility.
Random Generator service definition.
const std::string & name() const override
The identifying name of the algorithm object.
The IChronoStatSvc is the interface implemented by the ChronoStatService.
void setExecuted(bool state) override
Set the executed flag to the specified state.
Main interface for the JobOptions service.
StatusCode getProperty(Property *p) const override
Implementation of IProperty::getProperty.
StatusCode sysReinitialize() override
Reinitialization method invoked by the framework.
auto end(reverse_wrapper< T > &w)
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.
StatusCode sysExecute() override
The actions to be performed by the algorithm on an event.
bool isExecuted() const override
Has this algorithm been executed since the last reset?
StatusCode beginRun() override
Algorithm begin run.
StatusCode sysStart() override
Reinitialization method invoked by the framework.
Simple implementation of IExceptionSvc abstract interface.
The IMessage is the interface implemented by the message service.
StatusCode sysFinalize() override
System finalization.
serviceAccessor(auditorSvc, IAuditorSvc,"AuditorSvc", m_pAuditorSvc) serviceAccessor(chronoSvc
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition of the IHistogramSvc interface class.
const std::vector< Property * > & getProperties() const override
Implementation of IProperty::getProperties.
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.
void initOutputLevel(Property &prop)
callback for output level property
const std::vector< Algorithm * > * subAlgorithms() const
List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms.
Base class from which all concrete algorithm classes should be derived.
Property base class allowing Property* collections to be "homogeneous".
m_CSS m_DCS EventPersistencySvc
bool isEnabled() const override
Is this algorithm enabled or disabled?
m_CSS DetectorPersistencySvc
StatusCode restart() override
the default (empty) implementation of IStateful::restart() method
bool hasProperty(const std::string &name) const override
Implementation of IProperty::hasProperty.
An abstract interface for Algorithm Context Service.
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.
The IProperty is the basic interface for all components which have properties that can be set or get...
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.
StatusCode sysInitialize() override
Initialization method invoked by the framework.
StatusCode reinitialize() override
the default (empty) implementation of IStateful::reinitialize() method
void setFilterPassed(bool state) override
Set the filter passed flag to the specified state.
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...
StatusCode sysStop() override
System stop.