The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
Service Class Reference

Base class for all services. More...

#include </builds/gaudi/Gaudi/GaudiKernel/include/GaudiKernel/Service.h>

Inheritance diagram for Service:
Collaboration diagram for Service:

Public Types

using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
 

Public Member Functions

const std::string & name () const override
 Retrieve name of the service.
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service.
 
StatusCode sysStart () override
 Initialize Service.
 
StatusCode sysStop () override
 Initialize Service.
 
StatusCode sysFinalize () override
 Finalize Service.
 
StatusCode sysReinitialize () override
 Re-initialize the Service.
 
StatusCode sysRestart () override
 Re-initialize the Service.
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Protected Member Functions

std::vector< IAlgTool * > & tools ()
 
 ~Service () override
 
int outputLevel () const
 get the Service's output level
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 

Protected Attributes

Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
 
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
 
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
 
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
 
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
 
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
 
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
 
Gaudi::Property< bool > m_autoRetrieveTools
 
Gaudi::Property< bool > m_checkToolDeps
 
SmartIF< IAuditorSvcm_pAuditorSvc
 Auditor Service.
 

Private Member Functions

void initToolHandles () const
 
void sysInitialize_imp ()
 
void setServiceManager (ISvcManager *ism) override
 

Private Attributes

StatusCode m_initSC
 
std::once_flag m_initFlag
 
std::string m_name
 Service Name.
 
SmartIF< ISvcLocatorm_svcLocator
 Service Locator reference.
 
SmartIF< ISvcManagerm_svcManager
 
std::vector< IAlgTool * > m_tools
 
std::vector< BaseToolHandle * > m_toolHandles
 
std::vector< GaudiHandleArrayBase * > m_toolHandleArrays
 
bool m_toolHandlesInit = false
 

Friends

class ServiceManager
 

Detailed Description

Base class for all services.

It implements the IService and IProperty interfaces.

Author
Pere Mato
Marco Clemencic

Definition at line 39 of file Service.h.

Member Typedef Documentation

◆ Factory

using Service::Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>

Definition at line 41 of file Service.h.

Constructor & Destructor Documentation

◆ Service()

Service::Service ( std::string name,
ISvcLocator * svcloc )

Standard Constructor.

Definition at line 340 of file Service.cpp.

340 : m_name( std::move( name ) ), m_svcLocator( svcloc ) {
341 if ( m_name != "MessageSvc" ) { // the MessageSvc should not notify itself
342 m_outputLevel.declareUpdateHandler(
343 [this]( Gaudi::Details::PropertyBase& ) { this->updateMsgStreamOutputLevel( this->m_outputLevel ); } );
344 }
345
346 // Initialize the default value from ApplicationMgr AuditAlgorithms
347 Gaudi::Property<bool> audit( "AuditServices", false );
348 if ( auto appMgr = serviceLocator()->service<IProperty>( "ApplicationMgr" ) ) {
349 appMgr->getProperty( &audit ).ignore();
350 }
351
352 m_auditorInitialize = audit;
353 m_auditorStart = audit;
354 m_auditorStop = audit;
355 m_auditorFinalize = audit;
356 m_auditorReinitialize = audit;
357 m_auditorRestart = audit;
358}
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition Service.cpp:336
Gaudi::Property< bool > m_auditorStart
Definition Service.h:186
Gaudi::Property< bool > m_auditorFinalize
Definition Service.h:188
Gaudi::Property< int > m_outputLevel
flag indicating whether ToolHandle tools have been added to m_tools
Definition Service.h:184
Gaudi::Property< bool > m_auditorStop
Definition Service.h:187
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
Gaudi::Property< bool > m_auditorRestart
Definition Service.h:190
SmartIF< ISvcLocator > m_svcLocator
Service Locator reference.
Definition Service.h:170
SmartIF< IFace > service(const std::string &name, bool createIf=true) const
Definition Service.h:79
Gaudi::Property< bool > m_auditorInitialize
Definition Service.h:185
Gaudi::Property< bool > m_auditorReinitialize
Definition Service.h:189
std::string m_name
Service Name.
Definition Service.h:168

◆ ~Service()

Service::~Service ( )
overrideprotected

Definition at line 28 of file Service.cpp.

28 {
29 if ( m_svcManager ) m_svcManager->removeService( this ).ignore();
30}
SmartIF< ISvcManager > m_svcManager
Definition Service.h:171

Member Function Documentation

◆ addToolsArray()

template<class T>
void Service::addToolsArray ( ToolHandleArray< T > & hndlArr)
inline

Definition at line 133 of file Service.h.

133 {
134 m_toolHandleArrays.push_back( &hndlArr );
135 }
std::vector< GaudiHandleArrayBase * > m_toolHandleArrays
Definition Service.h:178

◆ auditorSvc()

SmartIF< IAuditorSvc > & Service::auditorSvc ( ) const

The standard auditor service.May not be invoked before sysInitialize() has been invoked.

Definition at line 360 of file Service.cpp.

360 {
361 if ( !m_pAuditorSvc ) {
362 m_pAuditorSvc = serviceLocator()->service( "AuditorSvc" );
363 if ( !m_pAuditorSvc ) { throw GaudiException( "Service [AuditorSvc] not found", name(), StatusCode::FAILURE ); }
364 }
365 return m_pAuditorSvc;
366}
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
SmartIF< IAuditorSvc > m_pAuditorSvc
Auditor Service.
Definition Service.h:198
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ configure()

StatusCode Service::configure ( )
inlineoverride

Definition at line 49 of file Service.h.

49{ return StatusCode::SUCCESS; }
constexpr static const auto SUCCESS
Definition StatusCode.h:99

◆ declareProperty() [1/2]

template<class T>
Gaudi::Details::PropertyBase * Service::declareProperty ( const std::string & name,
ToolHandle< T > & hndl,
const std::string & doc = "none" )
inline

Definition at line 91 of file Service.h.

92 {
93 this->declareTool( hndl, hndl.typeAndName() ).ignore();
94 return PropertyHolderImpl::declareProperty( name, hndl, doc );
95 }
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
StatusCode declareTool(ToolHandle< T > &handle, bool createIf=true)
Definition Service.h:98
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition StatusCode.h:139
std::string typeAndName() const override
Definition ToolHandle.h:273

◆ declareProperty() [2/2]

template<class T>
Gaudi::Details::PropertyBase * Service::declareProperty ( const std::string & name,
ToolHandleArray< T > & hndlArr,
const std::string & doc = "none" )
inline

Definition at line 126 of file Service.h.

127 {
128 addToolsArray( hndlArr );
129 return PropertyHolderImpl::declareProperty( name, hndlArr, doc );
130 }
void addToolsArray(ToolHandleArray< T > &hndlArr)
Definition Service.h:133

◆ declareTool() [1/2]

template<class T>
StatusCode Service::declareTool ( ToolHandle< T > & handle,
bool createIf = true )
inline

Definition at line 98 of file Service.h.

98 {
99 return this->declareTool( handle, handle.typeAndName(), createIf );
100 }

◆ declareTool() [2/2]

template<class T>
StatusCode Service::declareTool ( ToolHandle< T > & handle,
const std::string & toolTypeAndName,
bool createIf = true )
inline

Declare used tool.

Parameters
handleToolHandle<T>
toolTypeAndName
parent,defaultpublic tool
createif necessary, default true

Definition at line 110 of file Service.h.

110 {
111
112 StatusCode sc = handle.initialize( toolTypeAndName, handle.isPublic() ? nullptr : this, createIf );
113 if ( !sc ) {
114 throw GaudiException{ std::string{ "Cannot create handle for " } + ( handle.isPublic() ? "public" : "private" ) +
115 " tool " + toolTypeAndName,
116 name(), sc };
117 }
118
119 m_toolHandles.push_back( &handle );
120
121 return sc;
122 }
std::vector< BaseToolHandle * > m_toolHandles
Definition Service.h:177
StatusCode initialize(const std::string &toolTypeAndName, const IInterface *parent=nullptr, bool createIf=true)
Definition ToolHandle.h:213
bool isPublic() const noexcept
Definition ToolHandle.h:49

◆ finalize()

StatusCode Service::finalize ( )
override

Definition at line 223 of file Service.cpp.

223 {
224 // m_state = Gaudi::StateMachine::ChangeState(Gaudi::StateMachine::TERMINATE,m_state);
225 return StatusCode::SUCCESS;
226}

◆ FSMState()

Gaudi::StateMachine::State Service::FSMState ( ) const
inlineoverride

Definition at line 55 of file Service.h.

55{ return m_state; }
Gaudi::StateMachine::State m_state
Service state.
Definition Service.h:155

◆ initialize()

StatusCode Service::initialize ( )
override

Definition at line 118 of file Service.cpp.

118 {
119 ON_DEBUG debug() << "Service base class initialized successfully" << endmsg;
121 return StatusCode::SUCCESS;
122}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define ON_DEBUG
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
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...

◆ initToolHandles()

void Service::initToolHandles ( ) const
private

Definition at line 370 of file Service.cpp.

370 {
371 auto init_one = [&]( BaseToolHandle* th ) {
372 if ( !th->isEnabled() ) {
373 if ( msgLevel( MSG::DEBUG ) && !th->typeAndName().empty() )
374 debug() << "ToolHandle " << th->typeAndName() << " not used" << endmsg;
375 return;
376 }
377 if ( !th->get() ) {
378 auto sc = th->retrieve();
379 if ( sc.isFailure() ) {
380 throw GaudiException( "Failed to retrieve tool " + th->typeAndName(), this->name(), StatusCode::FAILURE );
381 }
382 }
383 auto* tool = th->get();
384 if ( msgLevel( MSG::DEBUG ) )
385 debug() << "Adding " << ( th->isPublic() ? "public" : "private" ) << " ToolHandle tool " << tool->name() << " ("
386 << tool->type() << ")" << endmsg;
387 m_tools.push_back( tool );
388 };
389
390 for ( auto thArr : m_toolHandleArrays ) {
391 if ( msgLevel( MSG::DEBUG ) )
392 debug() << "Registering all Tools in ToolHandleArray " << thArr->propertyName() << endmsg;
393 // Iterate over its tools:
394 for ( auto toolHandle : thArr->getBaseArray() ) {
395 // Try to cast it into a BaseToolHandle pointer:
396 BaseToolHandle* bth = dynamic_cast<BaseToolHandle*>( toolHandle );
397 if ( bth ) {
398 init_one( bth );
399 } else {
400 error() << "Error retrieving Tool " << toolHandle->typeAndName() << " in ToolHandleArray "
401 << thArr->propertyName() << ". Not registered" << endmsg;
402 }
403 }
404 }
405
406 for ( BaseToolHandle* th : m_toolHandles ) init_one( th );
407
408 m_toolHandlesInit = true;
409}
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::vector< IAlgTool * > m_tools
Definition Service.h:176
bool m_toolHandlesInit
Definition Service.h:179
@ DEBUG
Definition IMessageSvc.h:22

◆ name()

const std::string & Service::name ( ) const
override

Retrieve name of the service.

Definition at line 333 of file Service.cpp.

333{ return m_name; }

◆ outputLevel()

int Service::outputLevel ( ) const
inlineprotected

get the Service's output level

Definition at line 160 of file Service.h.

160{ return m_outputLevel.value(); }

◆ reinitialize()

StatusCode Service::reinitialize ( )
override

Definition at line 296 of file Service.cpp.

296 {
297 /* @TODO
298 * MCl 2008-10-23: the implementation of reinitialize as finalize+initialize
299 * is causing too many problems
300 *
301 // Default implementation is finalize+initialize
302 StatusCode sc = finalize();
303 if (sc.isFailure()) {
304 error() << "reinitialize(): cannot be finalized" << endmsg;
305 return sc;
306 }
307 sc = initialize();
308 if (sc.isFailure()) {
309 error() << "reinitialize(): cannot be initialized" << endmsg;
310 return sc;
311 }
312 */
313 return StatusCode::SUCCESS;
314}

◆ restart()

StatusCode Service::restart ( )
override

Definition at line 317 of file Service.cpp.

317 {
318 // Default implementation is stop+start
319 StatusCode sc = stop();
320 if ( sc.isFailure() ) {
321 error() << "restart(): cannot be stopped" << endmsg;
322 return sc;
323 }
324 sc = start();
325 if ( sc.isFailure() ) {
326 error() << "restart(): cannot be started" << endmsg;
327 return sc;
328 }
329 return StatusCode::SUCCESS;
330}
StatusCode stop() override
Definition Service.cpp:181
StatusCode start() override
Definition Service.cpp:187
bool isFailure() const
Definition StatusCode.h:129

◆ service()

template<typename IFace = IService>
SmartIF< IFace > Service::service ( const std::string & name,
bool createIf = true ) const
inline

Definition at line 79 of file Service.h.

79 {
80 return ServiceLocatorHelper( *serviceLocator(), *this )
81 .service<IFace>( name, !createIf, // quiet
82 createIf );
83 }

◆ serviceLocator()

SmartIF< ISvcLocator > & Service::serviceLocator ( ) const
override

Retrieve pointer to service locator.

Definition at line 336 of file Service.cpp.

336{ return m_svcLocator; }

◆ setServiceManager()

void Service::setServiceManager ( ISvcManager * ism)
overrideprivate

Definition at line 368 of file Service.cpp.

368{ m_svcManager = ism; }

◆ start()

StatusCode Service::start ( )
override

Definition at line 187 of file Service.cpp.

187 {
188 // stub implementation
189 return StatusCode::SUCCESS;
190}

◆ stop()

StatusCode Service::stop ( )
override

Definition at line 181 of file Service.cpp.

181 {
182 // stub implementation
183 return StatusCode::SUCCESS;
184}

◆ sysFinalize()

StatusCode Service::sysFinalize ( )
override

Finalize Service.

Definition at line 193 of file Service.cpp.

193 {
194
195 StatusCode sc( StatusCode::FAILURE );
196
197 try {
199 Gaudi::Guards::AuditorGuard guard( name(),
200 // check if we want to audit the initialize
201 ( m_auditorFinalize ) ? auditorSvc().get() : nullptr,
203 sc = finalize();
204 if ( sc.isSuccess() ) m_state = m_targetState;
205 } catch ( const GaudiException& Exception ) {
206 fatal() << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
207 error() << Exception << endmsg;
208 // Stat stat( chronoSvc() , Exception.tag() ) ;
209 } catch ( const std::exception& Exception ) {
210 fatal() << " Standard std::exception is caught " << endmsg;
211 error() << Exception.what() << endmsg;
212 // Stat stat( chronoSvc() , "*std::exception*" ) ;
213 } catch ( ... ) {
214 fatal() << "UNKNOWN Exception is caught " << endmsg;
215 // Stat stat( chronoSvc() , "*UNKNOWN Exception*" ) ;
216 }
217
218 m_pAuditorSvc = nullptr;
219 return sc;
220}
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
static const std::string Finalize
Definition IAuditor.h:53
SmartIF< IAuditorSvc > & auditorSvc() const
The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Definition Service.cpp:360
StatusCode finalize() override
Definition Service.cpp:223
Gaudi::StateMachine::State m_targetState
Service state.
Definition Service.h:157
get
decorate the vector of properties
Definition decorators.py:94

◆ sysInitialize()

StatusCode Service::sysInitialize ( )
override

Initialize Service.

Definition at line 33 of file Service.cpp.

33 {
34 std::call_once( m_initFlag, &Service::sysInitialize_imp, this );
35 return m_initSC;
36}
void sysInitialize_imp()
Definition Service.cpp:38
std::once_flag m_initFlag
Definition Service.h:165
StatusCode m_initSC
Definition Service.h:164

◆ sysInitialize_imp()

void Service::sysInitialize_imp ( )
private

Definition at line 38 of file Service.cpp.

38 {
39
40 try {
42 Gaudi::Guards::AuditorGuard guard( name(),
43 // check if we want to audit the initialize
44 ( m_auditorInitialize ) ? auditorSvc().get() : nullptr,
46
47 // initialize messaging (except for MessageSvc)
48 if ( name() != "MessageSvc" ) {
49 // this initializes the messaging, in case property update handlers need to print
50 // and update the property value bypassing the update handler
51 m_outputLevel.value() = setUpMessaging();
52 }
53
54 bindPropertiesTo( serviceLocator()->getOptsSvc() );
55
57 error() << "Property AutoRetrieveTools must be set TRUE if CheckToolDeps is True" << endmsg;
59 return;
60 }
61
62 m_initSC = initialize(); // This should change the state to Gaudi::StateMachine::CONFIGURED
63
64 // Check for data dependencies in AlgTools
65 // visit all sub-algs and tools, build full set. First initialize ToolHandles if needed
66 if ( m_autoRetrieveTools ) {
67 try {
69 } catch ( const GaudiException& Exception ) {
70 error() << "Service failed to initilize ToolHandles : " << Exception << endmsg;
72 return;
73 }
74
75 if ( m_checkToolDeps ) {
76 for ( auto& itool : m_tools ) {
77 info() << " AlgTool: " << itool->name() << endmsg;
78 IDataHandleHolder* idh = dynamic_cast<IDataHandleHolder*>( itool );
79 if ( idh == 0 ) {
80 error() << "dcast to IDataHandleHolder failed" << endmsg;
81 continue;
82 }
83 if ( idh->inputDataObjs().size() != 0 ) {
84 error() << "Service " << name() << " holds AlgTool " << itool->name()
85 << " which holds at least one ReadDataHandle" << endmsg;
86 for ( auto& obj : idh->inputDataObjs() ) { error() << " -> InputHandle: " << obj << endmsg; }
88 }
89 if ( idh->outputDataObjs().size() != 0 ) {
90 error() << "Service " << name() << " holds AlgTool " << itool->name()
91 << " which holds at least one WriteDataHandle" << endmsg;
92 for ( auto& obj : idh->outputDataObjs() ) { error() << " -> OutputHandle: " << obj << endmsg; }
94 }
95 }
96 }
97 }
98
99 if ( m_initSC.isSuccess() ) m_state = m_targetState;
100 return;
101 } catch ( const GaudiException& Exception ) {
102 fatal() << "in sysInitialize(): exception with tag=" << Exception.tag() << " is caught" << endmsg;
103 error() << Exception << endmsg;
104 // Stat stat( chronoSvc() , Exception.tag() );
105 } catch ( const std::exception& Exception ) {
106 fatal() << "in sysInitialize(): standard std::exception is caught" << endmsg;
107 error() << Exception.what() << endmsg;
108 // Stat stat( chronoSvc() , "*std::exception*" );
109 } catch ( ... ) {
110 fatal() << "in sysInitialize(): UNKNOWN Exception is caught" << endmsg;
111 // Stat stat( chronoSvc() , "*UNKNOWN Exception*" ) ;
112 }
113
115}
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
static const std::string Initialize
Definition IAuditor.h:47
virtual const DataObjIDColl & inputDataObjs() const =0
virtual const DataObjIDColl & outputDataObjs() const =0
Gaudi::Property< bool > m_checkToolDeps
Definition Service.h:194
Gaudi::Property< bool > m_autoRetrieveTools
Definition Service.h:192
StatusCode initialize() override
Definition Service.cpp:118
void initToolHandles() const
Definition Service.cpp:370

◆ sysReinitialize()

StatusCode Service::sysReinitialize ( )
override

Re-initialize the Service.

Definition at line 229 of file Service.cpp.

229 {
230
231 StatusCode sc;
232
233 // Check that the current status is the correct one.
235 error() << "sysReinitialize(): cannot reinitialize service not initialized" << endmsg;
236 return StatusCode::FAILURE;
237 }
238
239 try {
240
241 Gaudi::Guards::AuditorGuard guard( name(),
242 // check if we want to audit the initialize
243 ( m_auditorReinitialize ) ? auditorSvc().get() : nullptr,
245 sc = reinitialize();
246 return sc;
247 } catch ( const GaudiException& Exception ) {
248 fatal() << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
249 error() << Exception << endmsg;
250 // Stat stat( chronoSvc() , Exception.tag() ) ;
251 } catch ( const std::exception& Exception ) {
252 fatal() << " Standard std::exception is caught " << endmsg;
253 error() << Exception.what() << endmsg;
254 // Stat stat( chronoSvc() , "*std::exception*" ) ;
255 } catch ( ... ) {
256 fatal() << "UNKNOWN Exception is caught " << endmsg;
257 // Stat stat( chronoSvc() , "*UNKNOWN Exception*" ) ;
258 }
259 return StatusCode::FAILURE;
260}
static const std::string ReInitialize
Definition IAuditor.h:48
Gaudi::StateMachine::State FSMState() const override
Definition Service.h:55
StatusCode reinitialize() override
Definition Service.cpp:296

◆ sysRestart()

StatusCode Service::sysRestart ( )
override

Re-initialize the Service.

Definition at line 263 of file Service.cpp.

263 {
264
265 StatusCode sc;
266
267 // Check that the current status is the correct one.
269 error() << "sysRestart(): cannot restart service in state " << FSMState() << " -- must be RUNNING " << endmsg;
270 return StatusCode::FAILURE;
271 }
272
273 try {
274
275 Gaudi::Guards::AuditorGuard guard( name(),
276 // check if we want to audit the initialize
278 sc = restart();
279 return sc;
280 } catch ( const GaudiException& Exception ) {
281 fatal() << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
282 error() << Exception << endmsg;
283 // Stat stat( chronoSvc() , Exception.tag() ) ;
284 } catch ( const std::exception& Exception ) {
285 fatal() << " Standard std::exception is caught " << endmsg;
286 error() << Exception.what() << endmsg;
287 // Stat stat( chronoSvc() , "*std::exception*" ) ;
288 } catch ( ... ) {
289 fatal() << "UNKNOWN Exception is caught " << endmsg;
290 // Stat stat( chronoSvc() , "*UNKNOWN Exception*" ) ;
291 }
292 return StatusCode::FAILURE;
293}
static const std::string ReStart
Definition IAuditor.h:50
StatusCode restart() override
Definition Service.cpp:317

◆ sysStart()

StatusCode Service::sysStart ( )
override

Initialize Service.

Definition at line 125 of file Service.cpp.

125 {
126 StatusCode sc;
127
128 try {
130 Gaudi::Guards::AuditorGuard guard( name(),
131 // check if we want to audit the initialize
133 sc = start();
134 if ( sc.isSuccess() ) m_state = m_targetState;
135 return sc;
136 } catch ( const GaudiException& Exception ) {
137 fatal() << "in sysStart(): exception with tag=" << Exception.tag() << " is caught" << endmsg;
138 error() << Exception << endmsg;
139 // Stat stat( chronoSvc() , Exception.tag() );
140 } catch ( const std::exception& Exception ) {
141 fatal() << "in sysStart(): standard std::exception is caught" << endmsg;
142 fatal() << Exception.what() << endmsg;
143 // Stat stat( chronoSvc() , "*std::exception*" );
144 } catch ( ... ) {
145 fatal() << "in sysStart(): UNKNOWN Exception is caught" << endmsg;
146 // Stat stat( chronoSvc() , "*UNKNOWN Exception*" ) ;
147 }
148
149 return StatusCode::FAILURE;
150}
static const std::string Start
Definition IAuditor.h:49
bool isSuccess() const
Definition StatusCode.h:314

◆ sysStop()

StatusCode Service::sysStop ( )
override

Initialize Service.

Definition at line 153 of file Service.cpp.

153 {
154 StatusCode sc;
155
156 try {
158 Gaudi::Guards::AuditorGuard guard( name(),
159 // check if we want to audit the initialize
160 ( m_auditorStop ) ? auditorSvc().get() : nullptr, Gaudi::IAuditor::Stop );
161 sc = stop();
162 if ( sc.isSuccess() ) m_state = m_targetState;
163 return sc;
164 } catch ( const GaudiException& Exception ) {
165 fatal() << "in sysStop(): exception with tag=" << Exception.tag() << " is caught" << endmsg;
166 error() << Exception << endmsg;
167 // Stat stat( chronoSvc() , Exception.tag() );
168 } catch ( const std::exception& Exception ) {
169 fatal() << "in sysStop(): standard std::exception is caught" << endmsg;
170 error() << Exception.what() << endmsg;
171 // Stat stat( chronoSvc() , "*std::exception*" );
172 } catch ( ... ) {
173 fatal() << "in sysStop(): UNKNOWN Exception is caught" << endmsg;
174 // Stat stat( chronoSvc() , "*UNKNOWN Exception*" ) ;
175 }
176
177 return StatusCode::FAILURE;
178}
static const std::string Stop
Definition IAuditor.h:52

◆ targetFSMState()

Gaudi::StateMachine::State Service::targetFSMState ( ) const
inlineoverride

Definition at line 56 of file Service.h.

56{ return m_targetState; }

◆ terminate()

StatusCode Service::terminate ( )
inlineoverride

Definition at line 54 of file Service.h.

54{ return StatusCode::SUCCESS; }

◆ tools() [1/2]

std::vector< IAlgTool * > & Service::tools ( )
protected

Definition at line 417 of file Service.cpp.

417 {
419
420 return m_tools;
421}

◆ tools() [2/2]

const std::vector< IAlgTool * > & Service::tools ( ) const

Definition at line 411 of file Service.cpp.

411 {
413
414 return m_tools;
415}

Friends And Related Symbol Documentation

◆ ServiceManager

friend class ServiceManager
friend

Definition at line 43 of file Service.h.

Member Data Documentation

◆ m_auditorFinalize

Gaudi::Property<bool> Service::m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
protected

Definition at line 188 of file Service.h.

188{ this, "AuditFinalize", false, "trigger auditor on finalize()" };

◆ m_auditorInitialize

Gaudi::Property<bool> Service::m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
protected

Definition at line 185 of file Service.h.

185{ this, "AuditInitialize", false, "trigger auditor on initialize()" };

◆ m_auditorReinitialize

Gaudi::Property<bool> Service::m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
protected

Definition at line 189 of file Service.h.

189{ this, "AuditReinitialize", false, "trigger auditor on reinitialize()" };

◆ m_auditorRestart

Gaudi::Property<bool> Service::m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
protected

Definition at line 190 of file Service.h.

190{ this, "AuditRestart", false, "trigger auditor on restart()" };

◆ m_auditorStart

Gaudi::Property<bool> Service::m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
protected

Definition at line 186 of file Service.h.

186{ this, "AuditStart", false, "trigger auditor on start()" };

◆ m_auditorStop

Gaudi::Property<bool> Service::m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
protected

Definition at line 187 of file Service.h.

187{ this, "AuditStop", false, "trigger auditor on stop()" };

◆ m_autoRetrieveTools

Gaudi::Property<bool> Service::m_autoRetrieveTools
protected
Initial value:
{ this, "AutoRetrieveTools", true,
"retrieve all AlgTools during initialize" }

Definition at line 192 of file Service.h.

192 { this, "AutoRetrieveTools", true,
193 "retrieve all AlgTools during initialize" };

◆ m_checkToolDeps

Gaudi::Property<bool> Service::m_checkToolDeps
protected
Initial value:
{ this, "CheckToolDeps", true,
"check data dependencies of AlgTools (error if any found)" }

Definition at line 194 of file Service.h.

194 { this, "CheckToolDeps", true,
195 "check data dependencies of AlgTools (error if any found)" };

◆ m_initFlag

std::once_flag Service::m_initFlag
private

Definition at line 165 of file Service.h.

◆ m_initSC

StatusCode Service::m_initSC
private

Definition at line 164 of file Service.h.

◆ m_name

std::string Service::m_name
private

Service Name.

Definition at line 168 of file Service.h.

◆ m_outputLevel

Gaudi::Property<int> Service::m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
protected

flag indicating whether ToolHandle tools have been added to m_tools

Definition at line 184 of file Service.h.

184{ this, "OutputLevel", MSG::NIL, "output level" };
@ NIL
Definition IMessageSvc.h:22

◆ m_pAuditorSvc

SmartIF<IAuditorSvc> Service::m_pAuditorSvc
mutableprotected

Auditor Service.

Definition at line 198 of file Service.h.

◆ m_state

Service state.

Definition at line 155 of file Service.h.

◆ m_svcLocator

SmartIF<ISvcLocator> Service::m_svcLocator
mutableprivate

Service Locator reference.

Definition at line 170 of file Service.h.

◆ m_svcManager

SmartIF<ISvcManager> Service::m_svcManager
private

Definition at line 171 of file Service.h.

◆ m_targetState

Gaudi::StateMachine::State Service::m_targetState = Gaudi::StateMachine::OFFLINE
protected

Service state.

Definition at line 157 of file Service.h.

◆ m_toolHandleArrays

std::vector<GaudiHandleArrayBase*> Service::m_toolHandleArrays
mutableprivate

Definition at line 178 of file Service.h.

◆ m_toolHandles

std::vector<BaseToolHandle*> Service::m_toolHandles
mutableprivate

Definition at line 177 of file Service.h.

◆ m_toolHandlesInit

bool Service::m_toolHandlesInit = false
mutableprivate

Definition at line 179 of file Service.h.

◆ m_tools

std::vector<IAlgTool*> Service::m_tools
mutableprivate

Definition at line 176 of file Service.h.


The documentation for this class was generated from the following files: