The Gaudi Framework  master (37c0b60a)
Service Class Reference

#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 = PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 Typedef used to refer to this class from derived classes, as in. More...
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 

Public Member Functions

const std::stringname () const override
 Retrieve name of the service
More...
 
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
More...
 
StatusCode sysStart () override
 Initialize Service
More...
 
StatusCode sysStop () override
 Initialize Service
More...
 
StatusCode sysFinalize () override
 Finalize Service
More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor
More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator
More...
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
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. More...
 
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. More...
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property. More...
 
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. More...
 
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. More...
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property. More...
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name More...
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string More...
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property. More...
 
virtual StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p)=0
 Set the property from a property with a different name. More...
 
virtual StatusCode setProperty (const std::string &s)=0
 Set the property by string. More...
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals. More...
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string. More...
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation More...
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property More...
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name More...
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string More...
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties More...
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name. More...
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected More...
 
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) More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 

Protected Member Functions

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

Protected Attributes

Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state
More...
 
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools More...
 
Gaudi::Property< bool > m_auditInit { this, "AuditServices", false, "[[deprecated]] unused" }
 
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
More...
 

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
More...
 
SmartIF< ISvcLocatorm_svcLocator
 Service Locator reference
More...
 
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 46 of file Service.h.

Member Typedef Documentation

◆ Factory

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

Definition at line 48 of file Service.h.

Constructor & Destructor Documentation

◆ Service()

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

Standard Constructor

Definition at line 339 of file Service.cpp.

339  : m_name( std::move( name ) ), m_svcLocator( svcloc ) {
340  if ( m_name != "MessageSvc" ) { // the MessageSvc should not notify itself
343  }
344 
345  // Initialize the default value from ApplicationMgr AuditAlgorithms
346  Gaudi::Property<bool> audit( false );
347  auto appMgr = serviceLocator()->service<IProperty>( "ApplicationMgr" );
348  if ( appMgr && appMgr->hasProperty( "AuditServices" ) ) { audit.assign( appMgr->getProperty( "AuditServices" ) ); }
349  m_auditInit = audit;
350  m_auditorInitialize = audit;
351  m_auditorStart = audit;
352  m_auditorStop = audit;
353  m_auditorFinalize = audit;
354  m_auditorReinitialize = audit;
355  m_auditorRestart = audit;
356 }

◆ ~Service()

Service::~Service ( )
overrideprotected

Standard Destructor

Definition at line 29 of file Service.cpp.

29  {
30  if ( m_svcManager ) m_svcManager->removeService( this ).ignore();
31 }

Member Function Documentation

◆ addToolsArray()

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

Definition at line 179 of file Service.h.

179  {
180  m_toolHandleArrays.push_back( &hndlArr );
181  }

◆ auditorSvc()

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

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

Definition at line 358 of file Service.cpp.

358  {
359  if ( !m_pAuditorSvc ) {
360  m_pAuditorSvc = serviceLocator()->service( "AuditorSvc" );
361  if ( !m_pAuditorSvc ) { throw GaudiException( "Service [AuditorSvc] not found", name(), StatusCode::FAILURE ); }
362  }
363  return m_pAuditorSvc;
364 }

◆ configure()

StatusCode Service::configure ( )
inlineoverride

Definition at line 56 of file Service.h.

56 { return StatusCode::SUCCESS; }

◆ 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 137 of file Service.h.

138  {
139  this->declareTool( hndl, hndl.typeAndName() ).ignore();
140  return PropertyHolderImpl::declareProperty( name, hndl, doc );
141  }

◆ 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 172 of file Service.h.

173  {
174  addToolsArray( hndlArr );
175  return PropertyHolderImpl::declareProperty( name, hndlArr, doc );
176  }

◆ declareTool() [1/2]

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

Definition at line 144 of file Service.h.

144  {
145  return this->declareTool( handle, handle.typeAndName(), createIf );
146  }

◆ 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 156 of file Service.h.

156  {
157 
158  StatusCode sc = handle.initialize( toolTypeAndName, handle.isPublic() ? nullptr : this, createIf );
159  if ( !sc ) {
160  throw GaudiException{ std::string{ "Cannot create handle for " } + ( handle.isPublic() ? "public" : "private" ) +
161  " tool " + toolTypeAndName,
162  name(), sc };
163  }
164 
165  m_toolHandles.push_back( &handle );
166 
167  return sc;
168  }

◆ finalize()

StatusCode Service::finalize ( )
override

Definition at line 222 of file Service.cpp.

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

◆ FSMState()

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

Definition at line 62 of file Service.h.

62 { return m_state; }

◆ 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 }

◆ initToolHandles()

void Service::initToolHandles ( ) const
private

Definition at line 368 of file Service.cpp.

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

◆ name()

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

Retrieve name of the service

Definition at line 332 of file Service.cpp.

332 { return m_name; }

◆ outputLevel()

int Service::outputLevel ( ) const
inlineprotected

get the Service's output level

Definition at line 208 of file Service.h.

208 { return m_outputLevel.value(); }

◆ reinitialize()

StatusCode Service::reinitialize ( )
override

Definition at line 295 of file Service.cpp.

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

◆ restart()

StatusCode Service::restart ( )
override

Definition at line 316 of file Service.cpp.

316  {
317  // Default implementation is stop+start
318  StatusCode sc = stop();
319  if ( sc.isFailure() ) {
320  error() << "restart(): cannot be stopped" << endmsg;
321  return sc;
322  }
323  sc = start();
324  if ( sc.isFailure() ) {
325  error() << "restart(): cannot be started" << endmsg;
326  return sc;
327  }
328  return StatusCode::SUCCESS;
329 }

◆ service() [1/4]

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

Definition at line 117 of file Service.h.

117  {
118  return ServiceLocatorHelper( *serviceLocator(), *this )
119  .service<IFace>( name, !createIf, // quiet
120  createIf );
121  }

◆ service() [2/4]

template<class T >
StatusCode Service::service ( const std::string name,
const T *&  psvc,
bool  createIf = true 
) const
inline

Access a service by name, creating it if it doesn't already exist.

Definition at line 89 of file Service.h.

89  {
90  ISvcLocator& svcLoc = *serviceLocator();
91  auto ptr = ServiceLocatorHelper( svcLoc, *this )
92  .service<T>( name, !createIf, // quiet
93  createIf );
94  if ( ptr ) {
95  psvc = ptr.get();
96  const_cast<T*>( psvc )->addRef();
97  return StatusCode::SUCCESS;
98  }
99  // else
100  psvc = nullptr;
101  return StatusCode::FAILURE;
102  }

◆ service() [3/4]

template<class T >
StatusCode Service::service ( const std::string name,
T *&  psvc,
bool  createIf = true 
) const
inline

Definition at line 106 of file Service.h.

106  {
107  auto ptr = service<T>( name, createIf );
108  psvc = ( ptr ? ptr.get() : nullptr );
109  if ( psvc ) {
110  psvc->addRef();
111  return StatusCode::SUCCESS;
112  }
113  return StatusCode::FAILURE;
114  }

◆ service() [4/4]

template<class T >
StatusCode Service::service ( const std::string svcType,
const std::string svcName,
T *&  psvc 
) const
inline

Access a service by name and type, creating it if it doesn't already exist.

Definition at line 127 of file Service.h.

127  {
128  return service( svcType + "/" + svcName, psvc );
129  }

◆ serviceLocator()

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

Retrieve pointer to service locator

Definition at line 335 of file Service.cpp.

335 { return m_svcLocator; }

◆ setServiceManager()

void Service::setServiceManager ( ISvcManager ism)
overrideprivate

Definition at line 366 of file Service.cpp.

366 { 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 
196 
197  try {
199  Gaudi::Guards::AuditorGuard guard( this,
200  // check if we want to audit the initialize
201  ( m_auditorFinalize ) ? auditorSvc().get() : nullptr, IAuditor::Finalize );
202  sc = finalize();
203  if ( sc.isSuccess() ) m_state = m_targetState;
204  } catch ( const GaudiException& Exception ) {
205  fatal() << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
206  error() << Exception << endmsg;
207  // Stat stat( chronoSvc() , Exception.tag() ) ;
208  } catch ( const std::exception& Exception ) {
209  fatal() << " Standard std::exception is caught " << endmsg;
210  error() << Exception.what() << endmsg;
211  // Stat stat( chronoSvc() , "*std::exception*" ) ;
212  } catch ( ... ) {
213  fatal() << "UNKNOWN Exception is caught " << endmsg;
214  // Stat stat( chronoSvc() , "*UNKNOWN Exception*" ) ;
215  }
216 
217  m_pAuditorSvc = nullptr;
218  return sc;
219 }

◆ sysInitialize()

StatusCode Service::sysInitialize ( )
override

Initialize Service

Definition at line 34 of file Service.cpp.

34  {
36  return m_initSC;
37 }

◆ sysInitialize_imp()

void Service::sysInitialize_imp ( )
private

Definition at line 39 of file Service.cpp.

39  {
40 
41  try {
43  Gaudi::Guards::AuditorGuard guard( this,
44  // check if we want to audit the initialize
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
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 
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 }

◆ sysReinitialize()

StatusCode Service::sysReinitialize ( )
override

Re-initialize the Service.

Definition at line 228 of file Service.cpp.

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

◆ sysRestart()

StatusCode Service::sysRestart ( )
override

Re-initialize the Service.

Definition at line 262 of file Service.cpp.

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

◆ 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( this,
131  // check if we want to audit the initialize
132  ( m_auditorStart ) ? auditorSvc().get() : nullptr, IAuditor::Start );
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 }

◆ 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( this,
159  // check if we want to audit the initialize
160  ( m_auditorStop ) ? auditorSvc().get() : nullptr, 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 }

◆ targetFSMState()

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

Definition at line 63 of file Service.h.

63 { return m_targetState; }

◆ terminate()

StatusCode Service::terminate ( )
inlineoverride

Definition at line 61 of file Service.h.

61 { return StatusCode::SUCCESS; }

◆ tools() [1/2]

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

Definition at line 415 of file Service.cpp.

415  {
417 
418  return m_tools;
419 }

◆ tools() [2/2]

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

Definition at line 409 of file Service.cpp.

409  {
411 
412  return m_tools;
413 }

Friends And Related Function Documentation

◆ ServiceManager

friend class ServiceManager
friend

Definition at line 50 of file Service.h.

Member Data Documentation

◆ m_auditInit

Gaudi::Property<bool> Service::m_auditInit { this, "AuditServices", false, "[[deprecated]] unused" }
protected

Definition at line 233 of file Service.h.

◆ m_auditorFinalize

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

Definition at line 237 of file Service.h.

◆ m_auditorInitialize

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

Definition at line 234 of file Service.h.

◆ m_auditorReinitialize

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

Definition at line 238 of file Service.h.

◆ m_auditorRestart

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

Definition at line 239 of file Service.h.

◆ m_auditorStart

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

Definition at line 235 of file Service.h.

◆ m_auditorStop

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

Definition at line 236 of file Service.h.

◆ m_autoRetrieveTools

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

Definition at line 241 of file Service.h.

◆ 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 243 of file Service.h.

◆ m_initFlag

std::once_flag Service::m_initFlag
private

Definition at line 213 of file Service.h.

◆ m_initSC

StatusCode Service::m_initSC
private

Definition at line 212 of file Service.h.

◆ m_name

std::string Service::m_name
private

Service Name

Definition at line 216 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 232 of file Service.h.

◆ m_pAuditorSvc

SmartIF<IAuditorSvc> Service::m_pAuditorSvc
mutableprotected

Auditor Service

Definition at line 247 of file Service.h.

◆ m_state

Service state

Definition at line 203 of file Service.h.

◆ m_svcLocator

SmartIF<ISvcLocator> Service::m_svcLocator
mutableprivate

Service Locator reference

Definition at line 218 of file Service.h.

◆ m_svcManager

SmartIF<ISvcManager> Service::m_svcManager
private

Definition at line 219 of file Service.h.

◆ m_targetState

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

Service state

Definition at line 205 of file Service.h.

◆ m_toolHandleArrays

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

Definition at line 226 of file Service.h.

◆ m_toolHandles

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

Definition at line 225 of file Service.h.

◆ m_toolHandlesInit

bool Service::m_toolHandlesInit = false
mutableprivate

Definition at line 227 of file Service.h.

◆ m_tools

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

Definition at line 224 of file Service.h.


The documentation for this class was generated from the following files:
IDataHandleHolder
Definition: IDataHandleHolder.h:24
Service::m_auditorStart
Gaudi::Property< bool > m_auditorStart
Definition: Service.h:235
ServiceLocatorHelper::service
SmartIF< IService > service(std::string_view name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:50
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
Service::m_auditorStop
Gaudi::Property< bool > m_auditorStop
Definition: Service.h:236
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
std::call_once
T call_once(T... args)
IAuditor::ReStart
@ ReStart
Definition: IAuditor.h:34
Service::m_pAuditorSvc
SmartIF< IAuditorSvc > m_pAuditorSvc
Auditor Service
Definition: Service.h:247
Service::m_toolHandlesInit
bool m_toolHandlesInit
Definition: Service.h:227
Service::m_toolHandleArrays
std::vector< GaudiHandleArrayBase * > m_toolHandleArrays
Definition: Service.h:226
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:118
std::string
STL class.
std::exception
STL class.
std::move
T move(T... args)
Service::m_state
Gaudi::StateMachine::State m_state
Service state
Definition: Service.h:203
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
Service::m_initSC
StatusCode m_initSC
Definition: Service.h:212
Service::start
StatusCode start() override
Definition: Service.cpp:187
Service::sysInitialize_imp
void sysInitialize_imp()
Definition: Service.cpp:39
Service::addToolsArray
void addToolsArray(ToolHandleArray< T > &hndlArr)
Definition: Service.h:179
std::unordered_set::size
T size(T... args)
ISvcLocator
Definition: ISvcLocator.h:46
GaudiException
Definition: GaudiException.h:31
GaudiPartProp.decorators.get
get
decorate the vector of properties
Definition: decorators.py:283
Service::m_auditorInitialize
Gaudi::Property< bool > m_auditorInitialize
Definition: Service.h:234
Service::m_svcLocator
SmartIF< ISvcLocator > m_svcLocator
Service Locator reference
Definition: Service.h:218
Service::m_auditorReinitialize
Gaudi::Property< bool > m_auditorReinitialize
Definition: Service.h:238
Service::initToolHandles
void initToolHandles() const
Definition: Service.cpp:368
IDataHandleHolder::inputDataObjs
virtual const DataObjIDColl & inputDataObjs() const =0
CommonMessaging< implements< IService, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:148
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:222
Service::FSMState
Gaudi::StateMachine::State FSMState() const override
Definition: Service.h:62
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::bindPropertiesTo
void bindPropertiesTo(Gaudi::Interfaces::IOptionsSvc &optsSvc)
Definition: PropertyHolder.h:252
Gaudi::Guards::AuditorGuard
Definition: Guards.h:213
Service::m_name
std::string m_name
Service Name
Definition: Service.h:216
std::vector::push_back
T push_back(T... args)
Service::m_auditInit
Gaudi::Property< bool > m_auditInit
Definition: Service.h:233
IProperty
Definition: IProperty.h:33
IAuditor::Finalize
@ Finalize
Definition: IAuditor.h:34
Service::m_initFlag
std::once_flag m_initFlag
Definition: Service.h:213
ON_DEBUG
#define ON_DEBUG
Definition: Service.cpp:26
bug_34121.tool
tool
Definition: bug_34121.py:18
CommonMessaging< implements< IService, IProperty, IStateful > >::setUpMessaging
MSG::Level setUpMessaging() const
Set up local caches.
Definition: CommonMessaging.h:174
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
StatusCode
Definition: StatusCode.h:65
IAuditor::Stop
@ Stop
Definition: IAuditor.h:34
Service::m_tools
std::vector< IAlgTool * > m_tools
Definition: Service.h:224
Service::m_auditorFinalize
Gaudi::Property< bool > m_auditorFinalize
Definition: Service.h:237
IDataHandleHolder::outputDataObjs
virtual const DataObjIDColl & outputDataObjs() const =0
IAuditor::Initialize
@ Initialize
Definition: IAuditor.h:34
IAuditor::ReInitialize
@ ReInitialize
Definition: IAuditor.h:34
Gaudi::StateMachine::OFFLINE
@ OFFLINE
Definition: StateMachine.h:23
Service::m_auditorRestart
Gaudi::Property< bool > m_auditorRestart
Definition: Service.h:239
Gaudi::Property::declareUpdateHandler
Details::PropertyBase & declareUpdateHandler(std::function< void(Details::PropertyBase &)> fun) override
set new callback for update
Definition: Property.h:144
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
ServiceLocatorHelper
an helper to share the implementation of service() among the various kernel base classes
Definition: ServiceLocatorHelper.h:27
GaudiPython.Bindings.nullptr
nullptr
Definition: Bindings.py:87
CommonMessaging< implements< IService, IProperty, IStateful > >::updateMsgStreamOutputLevel
void updateMsgStreamOutputLevel(int level)
Update the output level of the cached MsgStream.
Definition: CommonMessaging.h:185
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
Gaudi::StateMachine::RUNNING
@ RUNNING
Definition: StateMachine.h:26
StatusCode::ignore
const StatusCode & ignore() const
Allow discarding a StatusCode without warning.
Definition: StatusCode.h:139
ToolHandleInfo::isPublic
bool isPublic() const noexcept
Definition: ToolHandle.h:51
Gaudi::StateMachine::ChangeState
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...
Definition: StateMachine.cpp:19
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
IAuditor::Start
@ Start
Definition: IAuditor.h:34
PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Details::PropertyBase &prop)
Declare a property.
Definition: PropertyHolder.h:106
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
Service::stop
StatusCode stop() override
Definition: Service.cpp:181
Service::m_autoRetrieveTools
Gaudi::Property< bool > m_autoRetrieveTools
Definition: Service.h:241
BaseToolHandle
Definition: ToolHandle.h:80
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:86
Gaudi::StateMachine::INITIALIZED
@ INITIALIZED
Definition: StateMachine.h:25
Gaudi::StateMachine::START
@ START
Definition: StateMachine.h:36
Service::m_svcManager
SmartIF< ISvcManager > m_svcManager
Definition: Service.h:219
Service::reinitialize
StatusCode reinitialize() override
Definition: Service.cpp:295
Service::m_targetState
Gaudi::StateMachine::State m_targetState
Service state
Definition: Service.h:205
ToolHandle::initialize
StatusCode initialize(const std::string &toolTypeAndName, const IInterface *parent=nullptr, bool createIf=true)
Definition: ToolHandle.h:213
ToolHandle::typeAndName
std::string typeAndName() const override
Definition: ToolHandle.h:273
Service::declareTool
StatusCode declareTool(ToolHandle< T > &handle, bool createIf=true)
Definition: Service.h:144
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Service::auditorSvc
SmartIF< IAuditorSvc > & auditorSvc() const
The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Definition: Service.cpp:358
Gaudi::Details::Property::ParsingErrorPolicy::Exception
@ Exception
Service::restart
StatusCode restart() override
Definition: Service.cpp:316
IOTest.appMgr
appMgr
Definition: IOTest.py:105
Service::m_checkToolDeps
Gaudi::Property< bool > m_checkToolDeps
Definition: Service.h:243
Gaudi::StateMachine::CONFIGURE
@ CONFIGURE
Definition: StateMachine.h:34
Service::service
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:89
Service::m_outputLevel
Gaudi::Property< int > m_outputLevel
flag indicating whether ToolHandle tools have been added to m_tools
Definition: Service.h:232
Gaudi::Property< bool >
Gaudi::StateMachine::STOP
@ STOP
Definition: StateMachine.h:37
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator
Definition: Service.cpp:335
Service::m_toolHandles
std::vector< BaseToolHandle * > m_toolHandles
Definition: Service.h:225