| The Gaudi Framework v29r1 (5cd95fa2)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ToolSvc Class Reference

This service manages tools. More...

`#include <src/ApplicationMgr/ToolSvc.h>`

Inheritance diagram for ToolSvc:
[legend]
Collaboration diagram for ToolSvc:
[legend]

## Public Member Functions
StatusCode | initialize () override
| Initialize the service. More...
StatusCode | finalize () override
| Finalize the service. More...
StatusCode | start () override
StatusCode | stop () override
StatusCode | retrieve (const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf) override
| Retrieve tool, create it by default as common tool if it does not already exist. More...
StatusCode | retrieve (const std::string &tooltype, const std::string &toolname, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf) override
| Retrieve tool, create it by default as common tool if it does not already exist. More...
std::vector< std::string > | getInstances (const std::string &toolType) override
| Get names of all tool instances of a given type. More...
std::vector< std::string > | getInstances () const override
| Get names of all tool instances. More...
std::vector< IAlgTool * > | getTools () const override
| Get pointers to all tool instances. More...
StatusCode | releaseTool (IAlgTool *tool) override
| Release tool. More...
StatusCode | create (const std::string &type, const IInterface *parent, IAlgTool *&tool)
| Create Tool standard way with automatically assigned name. More...
StatusCode | create (const std::string &type, const std::string &name, const IInterface *parent, IAlgTool *&tool)
| Create Tool standard way with specified name. More...
bool | existsTool (const std::string &toolname) const
| Check if the tool instance exists. More...
std::string | nameTool (const std::string &nameByUser, const IInterface *parent)
| Get Tool full name by combining nameByUser and "parent" part. More...
| ToolSvc (const std::string &name, ISvcLocator *svc)
| Standard Constructor. More...
| ~ToolSvc () override
| Destructor. More...
void | registerObserver (IToolSvc::Observer *obs) override
Public Member Functions inherited from extends< Service, IToolSvc >
void * | i_cast (const InterfaceID &tid) const override
| Implementation of IInterface::i_cast. More...
StatusCode | queryInterface (const InterfaceID &ti, void **pp) override
| Implementation of IInterface::queryInterface. More...
std::vector< std::string > | getInterfaceNames () const override
| Implementation of IInterface::getInterfaceNames. More...
| ~extends () override=default
| Virtual destructor. More...
Public Member Functions inherited from Service
const std::string & | name () 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...
StatusCode | setProperties ()
| Method for setting declared properties to the values specified for the job. 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 >
StatusCode | declareTool (ToolHandle< T > &handle, std::string toolTypeAndName, bool createIf=true)
| Declare used tool. More...
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
| ~PropertyHolder () override=default
Gaudi::Details::PropertyBase & | declareProperty (Gaudi::Details::PropertyBase &prop)
| Declare a property. More...
Gaudi::Details::PropertyBase * | declareProperty (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::PropertyBase * | declareProperty (const std::string &name, TYPE &value, const std::string &doc="none") const
Gaudi::Details::PropertyBase * | declareProperty (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::PropertyBase * | declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
| Declare a remote property. More...
StatusCode | setProperty (const Gaudi::Details::PropertyBase &p) override
| set the property form another property More...
StatusCode | setProperty (const std::string &s) override
| set the property from the formatted string More...
StatusCode | setProperty (const std::string &n, const std::string &v) override
| set the property from name and the value More...
StatusCode | setProperty (const std::string &name, const TYPE &value)
| set the property form the value More...
StatusCode | getProperty (Gaudi::Details::PropertyBase *p) const override
| get the property More...
const Gaudi::Details::PropertyBase & | getProperty (const std::string &name) const override
| get the property by name More...
StatusCode | getProperty (const std::string &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 (const std::string &name) const override
| Return true if we have a property with the given name. More...
| PropertyHolder (const PropertyHolder &)=delete
PropertyHolder & | operator= (const PropertyHolder &)=delete
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, GaudiHandleBase &ref, const std::string &doc="none")
| Specializations for various GaudiHandles. More...
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, GaudiHandleArrayBase &ref, const std::string &doc="none")
Gaudi::Details::PropertyBase * | declareProperty (const std::string &name, DataObjectHandleBase &ref, const std::string &doc="none")
Public Member Functions inherited from CommonMessagingBase
virtual | ~CommonMessagingBase ()=default
| Virtual destructor. More...
const SmartIF< IMessageSvc > & | msgSvc () const
| The standard message service. More...
MsgStream & | msgStream () const
| Return an uninitialized MsgStream. More...
MsgStream & | msgStream (const MSG::Level level) const
| Predefined configurable message stream for the efficient printouts. More...
MsgStream & | always () const
| shortcut for the method msgStream(MSG::ALWAYS) More...
MsgStream & | fatal () const
| shortcut for the method msgStream(MSG::FATAL) More...
MsgStream & | err () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | error () const
| shortcut for the method msgStream(MSG::ERROR) More...
MsgStream & | warning () const
| shortcut for the method msgStream(MSG::WARNING) More...
MsgStream & | info () const
| shortcut for the method msgStream(MSG::INFO) More...
MsgStream & | debug () const
| shortcut for the method msgStream(MSG::DEBUG) More...
MsgStream & | verbose () const
| shortcut for the method msgStream(MSG::VERBOSE) More...
MsgStream & | msg () const
| shortcut for the method msgStream(MSG::INFO) More...
MSG::Level | msgLevel () const
| get the cached level (originally extracted from the embedded MsgStream) More...
MSG::Level | outputLevel () const __attribute__((deprecated))
| Backward compatibility function for getting the output level. More...
bool | msgLevel (MSG::Level lvl) const
| get the output level from the embedded MsgStream More...
Public Member Functions inherited from extend_interfaces< Interfaces... >
| ~extend_interfaces () override=default
| Virtual destructor. More...

## Private Types
typedef std::recursive_mutex | CallMutex

## Private Member Functions
unsigned long | totalToolRefCount () const
| The total number of refCounts on all tools in the instancesTools list. More...
unsigned long | minimumToolRefCount () const
| The minimum number of refCounts of all tools. More...
StatusCode | finalizeTool (IAlgTool *itool) const
| Finalize the given tool, with exception handling. More...

## Private Attributes
std::vector< IAlgTool * > | m_instancesTools
| Common Tools. More...
IHistorySvc * | m_pHistorySvc = nullptr
| Pointer to HistorySvc. More...
std::vector< IToolSvc::Observer * > | m_observers
CallMutex | m_mut

## Additional Inherited Members
Public Types inherited from extends< Service, IToolSvc >
using | base_class = extends
| Typedef to this class. More...
using | extend_interfaces_base = extend_interfaces< Interfaces... >
| Typedef to the base of this class. More...
Public Types inherited from Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > | Factory
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 Types inherited from extend_interfaces< Interfaces... >
using | ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
| take union of the ext_iids of all Interfaces... More...
Protected Member Functions inherited from Service
| ~Service () override
| Standard Destructor. More...
int | outputLevel () const
| get the `Service's` output level More...
Protected Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
Gaudi::Details::PropertyBase * | property (const std::string &name) const
Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level | setUpMessaging ()
| 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 inherited from Service
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"}
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()"}
SmartIF< IAuditorSvc > | m_pAuditorSvc
| Auditor Service. More...

## Detailed Description

This service manages tools.

Tools can be common, in which case a single instance can be shared by different algorithms, or private in which case it is necessary to specify the parent when requesting it. The parent of a tool can be an algortihm or a Service The environment of a tool is set by using that of the parent. A common tool is considered to belong to the ToolSvc itself.

Author
  G. Corti, P. Mato

Definition at line 24 of file ToolSvc.h.

## Member Typedef Documentation

typedef std::recursive_mutex ToolSvc::CallMutex
| private

Definition at line 103 of file ToolSvc.h.

## Constructor & Destructor Documentation

ToolSvc::ToolSvc | ( | const std::string & | name,
|  | ISvcLocator * | svc
| ) |  |

Standard Constructor.

Parameters

  name | String with service name
  svc | Pointer to service locator interface

Definition at line 48 of file ToolSvc.cpp.

50 : base_class( name, svc )
51 {
52 }
extends< Service, IToolSvc >::base_class
extends base_class
Typedef to this class.
Definition: extends.h:15

ToolSvc::~ToolSvc | ( |  | ) |
| override

Destructor.

Definition at line 54 of file ToolSvc.cpp.

55 {
56 // tell the remaining observers that we're gone, and forget about unregistering..
57 std::for_each( std::begin( m_observers ), std::end( m_observers ),
58 [&]( IToolSvc::Observer* obs ) { obs->setUnregister( {} ); } );
59 }
IToolSvc::Observer
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:223
std::end
T end(T...args)
ToolSvc::m_observers
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:101
IToolSvc::Observer::setUnregister
void setUnregister(std::function< void()> unregister)
Definition: IToolSvc.h:230
std::begin
T begin(T...args)
std::for_each
T for_each(T...args)

## Member Function Documentation

StatusCode ToolSvc::create | ( | const std::string & | type,
|  | const IInterface * | parent,
|  | IAlgTool *& | tool
| ) |  |

Create Tool standard way with automatically assigned name.

Definition at line 396 of file ToolSvc.cpp.

398 {
399 const std::string& toolname = tooltype;
400 return create( tooltype, toolname, parent, tool );
401 }
ToolSvc::create
StatusCode create(const std::string &type, const IInterface *parent, IAlgTool *&tool)
Create Tool standard way with automatically assigned name.
Definition: ToolSvc.cpp:396
std::string
STL class.
gaudirun.toolname
toolname
Definition: gaudirun.py:338

StatusCode ToolSvc::create | ( | const std::string & | tooltype,
|  | const std::string & | toolname,
|  | const IInterface * | parent,
|  | IAlgTool *& | tool
| ) |  |

Create Tool standard way with specified name.

Now able to handle clones.

The test of tool existence is performed according to three criteria: name, type and parent. If a tool is private, i.e. the parent is not the tool Svc, and it exist but the parent is not the specified one, a clone is handed over. No clones of public tools are allowed since they would be undistinguishable.

invoke create callbacks...

Definition at line 461 of file ToolSvc.cpp.

464 {
465
466 std::lock_guard<CallMutex> lock( m_mut );
467 // protect against empty type
468 if ( UNLIKELY( tooltype.empty() ) ) {
469 error() << "create(): No Tool Type given" << endmsg;
470 return StatusCode::FAILURE;
471 }
472
473 // If parent has not been specified, assume it is the ToolSvc
474 if ( !parent ) parent = this;
475
476 tool = nullptr;
477 // Automatically deletes the tool if not explicitly kept (i.e. on success).
478 // The tool is removed from the list of known tools too.
479 auto toolguard = make_toolCreateGuard( m_instancesTools );
480
481 // Check if the tool already exist : this could happen with clones
482 std::string fullname = nameTool( toolname, parent );
483 if ( UNLIKELY( existsTool( fullname ) ) ) {
484 // Now check if the parent is the same. This allows for clones
485 for ( IAlgTool* iAlgTool : m_instancesTools ) {
486 if ( iAlgTool->name() == toolname && iAlgTool->parent() == parent ) {
487 // The tool exist with this name, type and parent: this is bad!
488 // This excludes the possibility of cloning public tools intrinsecally
489 error() << "Tool " << fullname << " already exists with the same parent" << endmsg;
490 if ( parent == this )
491 error() << "... In addition, the parent is the ToolSvc: public tools cannot be cloned!" << endmsg;
492
493 return StatusCode::FAILURE;
494 }
495 }
496 ON_DEBUG debug() << "Creating clone of " << fullname << endmsg;
497 }
498 // instantiate the tool using the factory
499 try {
500 toolguard.create( tooltype, fullname, parent );
501 if ( UNLIKELY( !toolguard.get() ) ) {
502 error() << "Cannot create tool " << tooltype << " (No factory found)" << endmsg;
503 return StatusCode::FAILURE;
504 }
505 } catch ( const GaudiException& Exception ) {
506 // (1) perform the printout of message
507 fatal() << "Exception with tag=" << Exception.tag() << " is caught whilst instantiating tool '" << tooltype << "'"
508 << endmsg;
509 // (2) print the exception itself
510 // (NB! - GaudiException is a linked list of all "previous exceptions")
511 fatal() << Exception << endmsg;
512 return StatusCode::FAILURE;
513 } catch ( const std::exception& Exception ) {
514 // (1) perform the printout of message
515 fatal() << "Standard std::exception is caught whilst instantiating tool '" << tooltype << "'" << endmsg;
516 // (2) print the exception itself
517 // (NB! - GaudiException is a linked list of all "previous exceptions")
518 fatal() << Exception.what() << endmsg;
519 return StatusCode::FAILURE;
520 } catch ( ... ) {
521 // (1) perform the printout
522 fatal() << "UNKNOWN Exception is caught whilst instantiating tool '" << tooltype << "'" << endmsg;
523 return StatusCode::FAILURE;
524 }
525 ON_VERBOSE verbose() << "Created tool " << tooltype << "/" << fullname << endmsg;
526
527 // Since only AlgTool has the setProperties() method it is necessary to cast
528 // to downcast IAlgTool to AlgTool in order to set the properties via the JobOptions
529 // service
530 AlgTool* mytool = dynamic_cast<AlgTool*>( toolguard.get() );
531 if ( mytool ) {
532 StatusCode sc = mytool->setProperties();
533 if ( UNLIKELY( sc.isFailure() ) ) {
534 error() << "Error setting properties for tool '" << fullname << "'" << endmsg;
535 return sc;
536 }
537 }
538
539 // Initialize the Tool
540 StatusCode sc( StatusCode::FAILURE, true );
541 try {
542 sc = toolguard->sysInitialize();
543 }
544 // Catch any exceptions
545 catch ( const GaudiException& Exception ) {
546 error() << "GaudiException with tag=" << Exception.tag() << " caught whilst initializing tool '" << fullname << "'"
547 << endmsg << Exception << endmsg;
548 return StatusCode::FAILURE;
549 } catch ( const std::exception& Exception ) {
550 error() << "Standard std::exception caught whilst initializing tool '" << fullname << "'" << endmsg
551 << Exception.what() << endmsg;
552 return StatusCode::FAILURE;
553 } catch ( ... ) {
554 error() << "UNKNOWN Exception caught whilst initializing tool '" << fullname << "'" << endmsg;
555 return StatusCode::FAILURE;
556 }
557
558 // Status of tool initialization
559 if ( UNLIKELY( sc.isFailure() ) ) {
560 error() << "Error initializing tool '" << fullname << "'" << endmsg;
561 return sc;
562 }
563
564 // Start the tool if we are running.
565 if ( m_state == Gaudi::StateMachine::RUNNING ) {
566 sc = toolguard->sysStart();
567
568 if ( UNLIKELY( sc.isFailure() ) ) {
569 error() << "Error starting tool '" << fullname << "'" << endmsg;
570 return sc;
571 }
572 }
573
574 // The tool has been successfully created and initialized,
575 // so we inform the guard that it can release it
576 tool = toolguard.release();
577
581 std::for_each( m_observers.begin(), m_observers.end(), [&]( IToolSvc::Observer* obs ) { obs->onCreate( tool ); } );
582 // TODO: replace by generic callback
583 // Register the tool with the HistorySvc
584 if ( m_pHistorySvc || service( "HistorySvc", m_pHistorySvc, false ).isSuccess() ) {
585 m_pHistorySvc->registerAlgTool( *tool ).ignore();
586 }
587 return StatusCode::SUCCESS;
588 }
ToolSvc::m_pHistorySvc
IHistorySvc * m_pHistorySvc
Pointer to HistorySvc.
Definition: ToolSvc.h:99
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
StatusCode::SUCCESS
Definition: StatusCode.h:31
std::string::empty
T empty(T...args)
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
Service::m_state
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:160
StatusCode::FAILURE
Definition: StatusCode.h:31
ToolSvc::nameTool
std::string nameTool(const std::string &nameByUser, const IInterface *parent)
Get Tool full name by combining nameByUser and "parent" part.
Definition: ToolSvc.cpp:591
IToolSvc::Observer
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:223
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:118
std::vector::end
T end(T...args)
ToolSvc::m_observers
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:101
ToolSvc::existsTool
bool existsTool(const std::string &toolname) const
Check if the tool instance exists.
Definition: ToolSvc.cpp:612
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
AlgTool::setProperties
StatusCode setProperties()
Method for setting declared properties to the values specified in the jobOptions via the job option s...
Definition: AlgTool.cpp:117
std::string
STL class.
IToolSvc::Observer::onCreate
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:232
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
std::exception::what
T what(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
IHistorySvc::registerAlgTool
virtual StatusCode registerAlgTool(const IAlgTool &)=0
std::lock
T lock(T...args)
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:109
std::exception
STL class.
GaudiPython.GaudiAlgs.iAlgTool
iAlgTool
Definition: GaudiAlgs.py:55
Gaudi::StateMachine::RUNNING
Definition: StateMachine.h:18
IInterface::release
virtual unsigned long release()=0
Release Interface instance.
std::lock_guard
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:115
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
std::vector::begin
T begin(T...args)
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:48
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
ON_DEBUG
#define ON_DEBUG
Definition: ToolSvc.cpp:21
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&#39;t already exist.
Definition: Service.h:85
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:109
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:100
ToolSvc::m_mut
CallMutex m_mut
Definition: ToolSvc.h:104
std::for_each
T for_each(T...args)
ON_VERBOSE
#define ON_VERBOSE
Definition: ToolSvc.cpp:22
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

bool ToolSvc::existsTool | ( | const std::string & | toolname | ) | const

Check if the tool instance exists.

Definition at line 612 of file ToolSvc.cpp.

614 {
615 std::lock_guard<CallMutex> lock( m_mut );
616 auto i = std::find_if( std::begin( m_instancesTools ), std::end( m_instancesTools ),
617 [&]( const IAlgTool* tool ) { return tool->name() == fullname; } );
618 return i != std::end( m_instancesTools );
619 }
std::end
T end(T...args)
std::lock
T lock(T...args)
std::find_if
T find_if(T...args)
std::lock_guard
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
std::begin
T begin(T...args)
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
ToolSvc::m_mut
CallMutex m_mut
Definition: ToolSvc.h:104
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.

StatusCode ToolSvc::finalize | ( |  | ) |
| override

Finalize the service.

Algorithm: 2 passes. First pass:

- do not explicitly release any tools
- finalize tools, in the order of increasing number of refCounts Second pass:
- explicitly release all tools, one release() on all tools per loop. -> tools are deleted in the order of increasing number of refCounts.

Inner loop: full loop over all left-over tools

- finalize tools with the minimum number of refCounts in the list.
- Remove finalized tools from list of tools, and add them to the list of finalized tools, to be deleted at the end. This way, any non-finalized tools who still reference already finalized tools in their finalize() will still find a live tool. Outer loop: keep on going until nothing changes in the list of tools. Checking for:
- number of left-over tools
- total number of refcounts
- minimum number of refcounts

Definition at line 82 of file ToolSvc.cpp.

84 {
85 // Finalize and delete all left-over tools. Normally all tools created with
86 // ToolSvc are left over, since ToolSvc holds a refCount (via AlgTool ctor).
87 // Several cases need to be covered:
88 // 1) Simple dependencies: no circular dependencies between tools,
89 // and tools not using other tools
90 // 2) Tools-using-tools (but no circular dependencies)
91 // a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm)
92 // b) release() is called in the tool destructor (e.g. via ToolHandle)
93 // 3) Circular dependencies between tools
94 // a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm)
95 // b) release() is called in the tool destructor (e.g. via ToolHandle)
96 // 4) In addition to each of the above cases, refCounting of a particular tool
97 // might not have been done correctly in the code. Typically release()
98 // is not called, so we are left with a too high refCount.
99 // What to do with those, and how to avoid a crash while handling them...
100
109 info() << "Removing all tools created by ToolSvc" << endmsg;
110
111 // Print out list of tools
112 ON_DEBUG
113 {
114 auto& log = debug();
115 log << " Tool List : ";
116 for ( const auto& iTool : m_instancesTools ) {
117 log << iTool->name() << ":" << iTool->refCount() << " ";
118 }
119 log << endmsg;
120 }
121
122 //
123 // first pass: Finalize all tools (but don't delete them)
124 //
137 boost::circular_buffer<IAlgTool*> finalizedTools( m_instancesTools.size() ); // list of tools that have been finalized
138 bool fail( false );
139 size_t toolCount = m_instancesTools.size();
140 unsigned long startRefCount = 0;
141 unsigned long endRefCount = totalToolRefCount();
142 unsigned long startMinRefCount = 0;
143 unsigned long endMinRefCount = minimumToolRefCount();
144 while ( toolCount > 0 && endRefCount > 0 && ( endRefCount != startRefCount || endMinRefCount != startMinRefCount ) ) {
145 ON_DEBUG if ( endMinRefCount != startMinRefCount )
146 {
147 debug() << toolCount << " tools left to finalize. Summed refCounts: " << endRefCount << endmsg;
148 debug() << "Will finalize tools with refCount <= " << endMinRefCount << endmsg;
149 }
150 startMinRefCount = endMinRefCount;
151 startRefCount = endRefCount;
152 unsigned long maxLoop = toolCount + 1;
153 while ( --maxLoop > 0 && !m_instancesTools.empty() ) {
154 IAlgTool* pTool = m_instancesTools.back();
155 // removing tool from list makes ToolSvc::releaseTool( IAlgTool* ) a noop
156 m_instancesTools.pop_back();
157 unsigned long count = pTool->refCount();
158 // cache tool name
159 const std::string& toolName = pTool->name();
160 if ( count <= startMinRefCount ) {
161 ON_DEBUG debug() << " Performing finalization of " << toolName << " (refCount " << count << ")" << endmsg;
162 // finalize of one tool may trigger a release of another tool
163 // pTool->sysFinalize().ignore();
164 if ( !finalizeTool( pTool ).isSuccess() ) {
165 warning() << " FAILURE finalizing " << toolName << endmsg;
166 fail = true;
167 }
168 // postpone deletion
169 finalizedTools.push_back( pTool );
170 } else {
171 // Place back at the front of the list to try again later
172 // ToolSvc::releaseTool( IAlgTool* ) remains active for this tool
173 ON_DEBUG debug() << " Delaying finalization of " << toolName << " (refCount " << count << ")" << endmsg;
174 m_instancesTools.insert( std::begin( m_instancesTools ), pTool );
175 }
176 } // end of inner loop
177 toolCount = m_instancesTools.size();
178 endRefCount = totalToolRefCount();
179 endMinRefCount = minimumToolRefCount();
180 }; // end of outer loop
181
182 //
183 // Second pass: Delete all finalized tools
184 //
185 // Delete in the order of increasing number of refCounts.
186 // Loop over tools in the same order as the order in which they were finalized.
187 // All tools in the list of finalized tools are no longer in the instancesTools list.
188 // If a tool destructor calls releaseTool() on another tool, this will have no
189 // effect on the 'other tool' if this 'other tool' is in the list of finalized tools.
190 // If this 'other tool' is still in the instancesTools list, it may trigger finalization
191 // (in releaseTool()), deletion and removal from the instancesTools list.
192 // Therefore, the check on non-finalised tools should happen *after* the deletion
193 // of the finalized tools.
194 ON_DEBUG debug() << "Deleting " << finalizedTools.size() << " finalized tools" << endmsg;
195 auto maxLoop = totalRefCount( finalizedTools ) + 1;
196 while ( --maxLoop > 0 && !finalizedTools.empty() ) {
197 IAlgTool* pTool = finalizedTools.front();
198 finalizedTools.pop_front();
199 auto count = pTool->refCount();
200 if ( count == 1 ) {
201 ON_DEBUG debug() << " Performing deletion of " << pTool->name() << endmsg;
202 } else {
203 ON_VERBOSE verbose() << " Delaying deletion of " << pTool->name() << " (refCount " << count << ")" << endmsg;
204 // Move to the end when refCount still not zero
205 finalizedTools.push_back( pTool );
206 }
207 // do a forced release
208 pTool->release();
209 }
210
211 // Error if by now not all tools are properly finalised
212 if ( !m_instancesTools.empty() ) {
213 error() << "Unable to finalize and delete the following tools : ";
214 for ( const auto& iTool : m_instancesTools ) {
215 error() << iTool->name() << ": " << iTool->refCount() << " ";
216 }
217 error() << endmsg;
218 }
219
220 // by now, all tools should be deleted and removed.
221 if ( !finalizedTools.empty() ) {
222 error() << "Failed to delete the following " << finalizedTools.size()
223 << " finalized tools. Bug in ToolSvc::finalize()?: ";
224 for ( const auto& iTool : finalizedTools ) {
225 error() << iTool->name() << ": " << iTool->refCount() << " ";
226 }
227 error() << endmsg;
228 }
229
230 if ( m_pHistorySvc ) m_pHistorySvc->release();
231
232 // Finalize this specific service
233 return ( Service::finalize().isSuccess() && !fail ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
234 }
ToolSvc::m_pHistorySvc
IHistorySvc * m_pHistorySvc
Pointer to HistorySvc.
Definition: ToolSvc.h:99
StatusCode::SUCCESS
Definition: StatusCode.h:31
StatusCode::FAILURE
Definition: StatusCode.h:31
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:174
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:112
ToolSvc::minimumToolRefCount
unsigned long minimumToolRefCount() const
The minimum number of refCounts of all tools.
Definition: ToolSvc.cpp:658
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:118
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
ToolSvc::totalToolRefCount
unsigned long totalToolRefCount() const
The total number of refCounts on all tools in the instancesTools list.
Definition: ToolSvc.cpp:652
ToolSvc::finalizeTool
StatusCode finalizeTool(IAlgTool *itool) const
Finalize the given tool, with exception handling.
Definition: ToolSvc.cpp:622
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:109
std::count
T count(T...args)
IInterface::release
virtual unsigned long release()=0
Release Interface instance.
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:115
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
std::begin
T begin(T...args)
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
ON_DEBUG
#define ON_DEBUG
Definition: ToolSvc.cpp:21
IInterface::refCount
virtual unsigned long refCount() const =0
Current reference count.
ON_VERBOSE
#define ON_VERBOSE
Definition: ToolSvc.cpp:22
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
Gaudi.Configuration.log
log
Definition: Configuration.py:13

StatusCode ToolSvc::finalizeTool | ( | IAlgTool * | itool | ) | const
| private

Finalize the given tool, with exception handling.

Definition at line 622 of file ToolSvc.cpp.

624 {
625
626 // Cache tool name in case of errors
627 const std::string toolName = itool->name();
628 StatusCode sc;
629
630 // Finalise the tool inside a try block
631 try {
632 sc = itool->sysFinalize();
633 }
634 // Catch any exceptions
635 catch ( const GaudiException& Exception ) {
636 error() << "GaudiException with tag=" << Exception.tag() << " caught whilst finalizing tool '" << toolName << "'"
637 << endmsg << Exception << endmsg;
638 sc = StatusCode::FAILURE;
639 } catch ( const std::exception& Exception ) {
640 error() << "Standard std::exception caught whilst finalizing tool '" << toolName << "'" << endmsg
641 << Exception.what() << endmsg;
642 sc = StatusCode::FAILURE;
643 } catch ( ... ) {
644 error() << "UNKNOWN Exception caught whilst finalizing tool '" << toolName << "'" << endmsg;
645 sc = StatusCode::FAILURE;
646 }
647
648 return sc;
649 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
StatusCode::FAILURE
Definition: StatusCode.h:31
IAlgTool::sysFinalize
virtual StatusCode sysFinalize()=0
Finalization of the Tool.
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
std::exception::what
T what(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:109
std::exception
STL class.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.

std::vector< std::string > ToolSvc::getInstances | ( | const std::string & | toolType | ) |
| override

Get names of all tool instances of a given type.

Definition at line 337 of file ToolSvc.cpp.

339 {
340
341 std::lock_guard<CallMutex> lock( m_mut );
342 std::vector<std::string> tools;
343 for ( const auto& tool : m_instancesTools ) {
344 if ( tool->type() == toolType ) tools.push_back( tool->name() );
345 }
346 return tools;
347 }
std::vector::push_back
T push_back(T...args)
std::lock
T lock(T...args)
std::vector< std::string >
std::lock_guard
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
ToolSvc::m_mut
CallMutex m_mut
Definition: ToolSvc.h:104

std::vector< std::string > ToolSvc::getInstances | ( |  | ) | const
| override

Get names of all tool instances.

Definition at line 349 of file ToolSvc.cpp.

351 {
352 std::lock_guard<CallMutex> lock( m_mut );
353 std::vector<std::string> tools{m_instancesTools.size()};
354 std::transform( std::begin( m_instancesTools ), std::end( m_instancesTools ), std::begin( tools ),
355 []( const IAlgTool* t ) { return t->name(); } );
356 return tools;
357 }
std::end
T end(T...args)
std::lock
T lock(T...args)
std::vector::size
T size(T...args)
std::vector< std::string >
std::lock_guard
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
std::begin
T begin(T...args)
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
std::transform
T transform(T...args)
ToolSvc::m_mut
CallMutex m_mut
Definition: ToolSvc.h:104
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.

std::vector< IAlgTool * > ToolSvc::getTools | ( |  | ) | const
| override

Get pointers to all tool instances.

Definition at line 359 of file ToolSvc.cpp.

361 {
362 std::lock_guard<CallMutex> lock( m_mut );
363 return std::vector<IAlgTool*>{std::begin( m_instancesTools ), std::end( m_instancesTools )};
364 }
std::end
T end(T...args)
std::lock
T lock(T...args)
std::vector< IAlgTool * >
std::lock_guard
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
std::begin
T begin(T...args)
ToolSvc::m_mut
CallMutex m_mut
Definition: ToolSvc.h:104

StatusCode ToolSvc::initialize | ( |  | ) |
| override

Initialize the service.

Definition at line 61 of file ToolSvc.cpp.

63 {
64
65 // initialize the Service Base class
66 StatusCode status = Service::initialize();
67 if ( UNLIKELY( status.isFailure() ) ) {
68 error() << "Unable to initialize the Service" << endmsg;
69 return status;
70 }
71
72 // set my own (ToolSvc) properties via the jobOptionService
73 if ( UNLIKELY( setProperties().isFailure() ) ) {
74 error() << "Unable to set base properties" << endmsg;
75 return StatusCode::FAILURE;
76 }
77
78 return status;
79 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
StatusCode::FAILURE
Definition: StatusCode.h:31
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
Service::setProperties
StatusCode setProperties()
Method for setting declared properties to the values specified for the job.
Definition: Service.cpp:295
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

unsigned long ToolSvc::minimumToolRefCount | ( |  | ) | const
| private

The minimum number of refCounts of all tools.

Definition at line 658 of file ToolSvc.cpp.

660 {
661 auto i =
662 std::min_element( std::begin( m_instancesTools ), std::end( m_instancesTools ),
663 []( const IAlgTool* lhs, const IAlgTool* rhs ) { return lhs->refCount() < rhs->refCount(); } );
664 return i != std::end( m_instancesTools ) ? ( *i )->refCount() : 0;
665 }
std::end
T end(T...args)
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
std::begin
T begin(T...args)
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
IInterface::refCount
virtual unsigned long refCount() const =0
Current reference count.
std::min_element
T min_element(T...args)

std::string ToolSvc::nameTool | ( | const std::string & | nameByUser,
|  | const IInterface * | parent
| ) |  |

Get Tool full name by combining nameByUser and "parent" part.

Definition at line 591 of file ToolSvc.cpp.

593 {
594
595 if ( !parent ) {
596 return this->name() + "." + toolname;
597 } // RETURN
598
599 // check that parent has a name!
600 auto named_parent = SmartIF<INamedInterface>( const_cast<IInterface*>( parent ) );
601 if ( named_parent ) {
602 auto fullname = named_parent->name() + "." + toolname;
603 return fullname; // RETURN
604 }
605
606 error() << "Private Tools only allowed for components implementing INamedInterface" << endmsg;
607 //
608 return "." + toolname;
609 }
SmartIF< INamedInterface >
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
IInterface
Definition of the basic interface.
Definition: IInterface.h:277
gaudirun.toolname
toolname
Definition: gaudirun.py:338
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

void ToolSvc::registerObserver | ( | IToolSvc::Observer * | obs | ) |
| override

Definition at line 668 of file ToolSvc.cpp.

669 {
670 //------------------------------------------------------------------------------
671 if ( !obs ) throw GaudiException( "Received NULL pointer", this->name() + "::registerObserver", StatusCode::FAILURE );
672
673 std::lock_guard<CallMutex> lock( m_mut );
674 obs->setUnregister( [this, obs]() {
675 std::lock_guard<CallMutex> lock( m_mut );
676 auto i = std::find( m_observers.begin(), m_observers.end(), obs );
677 if ( i != m_observers.end() ) m_observers.erase( i );
678 } );
679 m_observers.push_back( obs );
680 }
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
StatusCode::FAILURE
Definition: StatusCode.h:31
std::vector::end
T end(T...args)
ToolSvc::m_observers
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:101
std::vector::push_back
T push_back(T...args)
std::vector::erase
T erase(T...args)
std::lock
T lock(T...args)
std::find
T find(T...args)
IToolSvc::Observer::setUnregister
void setUnregister(std::function< void()> unregister)
Definition: IToolSvc.h:230
std::lock_guard
std::vector::begin
T begin(T...args)
ToolSvc::m_mut
CallMutex m_mut
Definition: ToolSvc.h:104

StatusCode ToolSvc::releaseTool | ( | IAlgTool * | tool | ) |
| override

Release tool.

Definition at line 366 of file ToolSvc.cpp.

368 {
369 std::lock_guard<CallMutex> lock( m_mut );
370 StatusCode sc( StatusCode::SUCCESS );
371 // test if tool is in known list (protect trying to access a previously deleted tool)
372 if ( m_instancesTools.rend() != std::find( m_instancesTools.rbegin(), m_instancesTools.rend(), tool ) ) {
373 unsigned long count = tool->refCount();
374 if ( count == 1 ) {
375 // finalize the tool
376
377 if ( Gaudi::StateMachine::OFFLINE == m_targetState ) {
378 // We are being called during ToolSvc::finalize()
379 // message format matches the one in ToolSvc::finalize()
380 debug() << " Performing finalization of " << tool->name() << " (refCount " << count << ")" << endmsg;
381 // message format matches the one in ToolSvc::finalize()
382 debug() << " Performing deletion of " << tool->name() << endmsg;
383 } else {
384 debug() << "Performing finalization and deletion of " << tool->name() << endmsg;
385 }
386 sc = finalizeTool( tool );
387 // remove from known tools...
388 remove( m_instancesTools, tool );
389 }
390 tool->release();
391 }
392 return sc;
393 }
Service::m_targetState
Gaudi::StateMachine::State m_targetState
Service state.
Definition: Service.h:162
StatusCode::SUCCESS
Definition: StatusCode.h:31
std::vector::rend
T rend(T...args)
ToolSvc::finalizeTool
StatusCode finalizeTool(IAlgTool *itool) const
Finalize the given tool, with exception handling.
Definition: ToolSvc.cpp:622
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
std::lock
T lock(T...args)
std::count
T count(T...args)
std::find
T find(T...args)
IInterface::release
virtual unsigned long release()=0
Release Interface instance.
std::lock_guard
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:115
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
IInterface::refCount
virtual unsigned long refCount() const =0
Current reference count.
ToolSvc::m_mut
CallMutex m_mut
Definition: ToolSvc.h:104
Gaudi::StateMachine::OFFLINE
Definition: StateMachine.h:15
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
std::vector::rbegin
T rbegin(T...args)

StatusCode ToolSvc::retrieve | ( | const std::string & | type,
|  | const InterfaceID & | iid,
|  | IAlgTool *& | tool,
|  | const IInterface * | parent,
|  | bool | createIf
| ) |  |
| override

Retrieve tool, create it by default as common tool if it does not already exist.

Definition at line 247 of file ToolSvc.cpp.

250 {
251 // check for tools, which by name are required to be public:
252 if ( ba::ends_with( tooltype, s_PUBLIC ) ) {
253 // parent for PUBLIC tool is 'this', i.e. ToolSvc
254 return retrieve( ba::erase_tail_copy( tooltype, s_PUBLIC.size() ), iid, tool, this, createIf );
255 }
256
257 // protect against empty type
258 if ( tooltype.empty() ) {
259 error() << "retrieve(): No Tool Type/Name given" << endmsg;
260 return StatusCode::FAILURE;
261 }
262 auto pos = tooltype.find( '/' );
263 if ( std::string::npos == pos ) {
264 return retrieve( tooltype, tooltype, iid, tool, parent, createIf );
265 }
266 return retrieve( tooltype.substr( 0, pos ), tooltype.substr( pos + 1 ), iid, tool, parent, createIf );
267 }
StatusCode::FAILURE
Definition: StatusCode.h:31
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
ToolSvc::retrieve
StatusCode retrieve(const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf) override
Retrieve tool, create it by default as common tool if it does not already exist.
Definition: ToolSvc.cpp:247

StatusCode ToolSvc::retrieve | ( | const std::string & | tooltype,
|  | const std::string & | toolname,
|  | const InterfaceID & | iid,
|  | IAlgTool *& | tool,
|  | const IInterface * | parent,
|  | bool | createIf
| ) |  |
| override

Retrieve tool, create it by default as common tool if it does not already exist.

invoke retrieve callbacks...

Definition at line 272 of file ToolSvc.cpp.

275 {
276 // check the applicability of another method:
277 // ignore the provided name if it is empty or the type contains a name
278 if ( toolname.empty() || ( std::string::npos != tooltype.find( '/' ) ) ) {
279 return retrieve( tooltype, iid, tool, parent, createIf );
280 }
281
282 // check for tools, which by name are required to be public:
283 if ( ba::ends_with( toolname, s_PUBLIC ) ) {
284 // parent for PUBLIC tool is this, i.e. ToolSvc
285 return retrieve( tooltype, ba::erase_tail_copy( toolname, s_PUBLIC.size() ), iid, tool, this, createIf );
286 }
287
288 std::lock_guard<CallMutex> lock( m_mut );
289
290 IAlgTool* itool = nullptr;
291 StatusCode sc( StatusCode::FAILURE );
292
293 tool = nullptr;
294
295 // If parent is not specified it means it is the ToolSvc itself
296 if ( !parent ) parent = this;
297 const std::string fullname = nameTool( toolname, parent );
298
299 // Find tool in list of those already existing, and tell its
300 // interface that it has been used one more time
301 auto it = std::find_if( std::begin( m_instancesTools ), std::end( m_instancesTools ),
302 [&]( const IAlgTool* i ) { return i->name() == fullname && i->parent() == parent; } );
303 if ( it != std::end( m_instancesTools ) ) {
304 ON_DEBUG debug() << "Retrieved tool " << toolname << " with parent " << parent << endmsg;
305 itool = *it;
306 }
307
308 if ( !itool ) {
309 // Instances of this tool do not exist, create an instance if desired
310 // otherwise return failure
311 if ( UNLIKELY( !createIf ) ) {
312 warning() << "Tool " << toolname << " not found and creation not requested" << endmsg;
313 return sc;
314 }
315 sc = create( tooltype, toolname, parent, itool );
316 if ( sc.isFailure() ) {
317 return sc;
318 }
319 }
320
321 // Get the right interface of it
322 sc = itool->queryInterface( iid, pp_cast<void>( &tool ) );
323 if ( UNLIKELY( sc.isFailure() ) ) {
324 error() << "Tool " << toolname << " either does not implement the correct interface, or its version is incompatible"
325 << endmsg;
326 return sc;
327 }
328
332 std::for_each( std::begin( m_observers ), std::end( m_observers ),
333 [&]( IToolSvc::Observer* obs ) { obs->onRetrieve( itool ); } );
334 return sc;
335 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
std::string::empty
T empty(T...args)
StatusCode::FAILURE
Definition: StatusCode.h:31
ToolSvc::nameTool
std::string nameTool(const std::string &nameByUser, const IInterface *parent)
Get Tool full name by combining nameByUser and "parent" part.
Definition: ToolSvc.cpp:591
IToolSvc::Observer
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:223
ToolSvc::create
StatusCode create(const std::string &type, const IInterface *parent, IAlgTool *&tool)
Create Tool standard way with automatically assigned name.
Definition: ToolSvc.cpp:396
std::end
T end(T...args)
ToolSvc::m_observers
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:101
std::string
STL class.
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:109
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
std::lock
T lock(T...args)
std::string::find
T find(T...args)
std::string::size
T size(T...args)
std::lock_guard
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:115
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
std::begin
T begin(T...args)
IToolSvc::Observer::onRetrieve
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:233
IAlgTool
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
ON_DEBUG
#define ON_DEBUG
Definition: ToolSvc.cpp:21
ToolSvc::m_mut
CallMutex m_mut
Definition: ToolSvc.h:104
std::for_each
T for_each(T...args)
IAlgTool::parent
virtual const IInterface * parent() const =0
The parent of the concrete AlgTool.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
IInterface::queryInterface
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
ToolSvc::retrieve
StatusCode retrieve(const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf) override
Retrieve tool, create it by default as common tool if it does not already exist.
Definition: ToolSvc.cpp:247

StatusCode ToolSvc::start | ( |  | ) |
| override

Definition at line 683 of file ToolSvc.cpp.

685 {
686
687 ON_DEBUG debug() << "START transition for AlgTools" << endmsg;
688
689 bool fail( false );
690 for ( auto& iTool : m_instancesTools ) {
691 ON_VERBOSE verbose() << iTool->name() << "::start()" << endmsg;
692
693 if ( UNLIKELY( !iTool->sysStart().isSuccess() ) ) {
694 fail = true;
695 error() << iTool->name() << " failed to start()" << endmsg;
696 }
697 }
698
699 if ( UNLIKELY( fail ) ) {
700 error() << "One or more AlgTools failed to start()" << endmsg;
701 return StatusCode::FAILURE;
702 }
703 return StatusCode::SUCCESS;
704 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
StatusCode::SUCCESS
Definition: StatusCode.h:31
StatusCode::FAILURE
Definition: StatusCode.h:31
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:118
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:115
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
ON_DEBUG
#define ON_DEBUG
Definition: ToolSvc.cpp:21
ON_VERBOSE
#define ON_VERBOSE
Definition: ToolSvc.cpp:22
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

StatusCode ToolSvc::stop | ( |  | ) |
| override

Definition at line 707 of file ToolSvc.cpp.

709 {
710
711 ON_DEBUG debug() << "STOP transition for AlgTools" << endmsg;
712
713 bool fail( false );
714 for ( auto& iTool : m_instancesTools ) {
715 ON_VERBOSE verbose() << iTool->name() << "::stop()" << endmsg;
716
717 if ( UNLIKELY( !iTool->sysStop().isSuccess() ) ) {
718 fail = true;
719 error() << iTool->name() << " failed to stop()" << endmsg;
720 }
721 }
722
723 if ( UNLIKELY( fail ) ) {
724 error() << "One or more AlgTools failed to stop()" << endmsg;
725 return StatusCode::FAILURE;
726 }
727 return StatusCode::SUCCESS;
728 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
StatusCode::SUCCESS
Definition: StatusCode.h:31
StatusCode::FAILURE
Definition: StatusCode.h:31
CommonMessagingBase::verbose
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Definition: CommonMessaging.h:118
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:106
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:115
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96
ON_DEBUG
#define ON_DEBUG
Definition: ToolSvc.cpp:21
ON_VERBOSE
#define ON_VERBOSE
Definition: ToolSvc.cpp:22
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

unsigned long ToolSvc::totalToolRefCount | ( |  | ) | const
| private

The total number of refCounts on all tools in the instancesTools list.

Definition at line 652 of file ToolSvc.cpp.

654 {
655 return totalRefCount( m_instancesTools );
656 }
ToolSvc::m_instancesTools
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:96

## Member Data Documentation

std::vector<IAlgTool*> ToolSvc::m_instancesTools
| private

Common Tools.

Definition at line 96 of file ToolSvc.h.

CallMutex ToolSvc::m_mut
| mutable private

Definition at line 104 of file ToolSvc.h.

std::vector<IToolSvc::Observer*> ToolSvc::m_observers
| private

Definition at line 101 of file ToolSvc.h.

IHistorySvc* ToolSvc::m_pHistorySvc = nullptr
| private

Pointer to HistorySvc.

Definition at line 99 of file ToolSvc.h.

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

- GaudiCoreSvc/src/ApplicationMgr/ToolSvc.h
- GaudiCoreSvc/src/ApplicationMgr/ToolSvc.cpp