ToolSvc Class Reference

This service manages tools. More...

#include <src/ApplicationMgr/ToolSvc.h>

Inheritance diagram for ToolSvc:
Collaboration diagram for ToolSvc:

Public Types

typedef std::list< IAlgTool * > ListTools
 
- Public Types inherited from extends1< Service, IToolSvc >
typedef extends1 base_class
 Typedef to this class. More...
 
typedef extends1 base_class
 Typedef to this class. More...
 
typedef extend_interfaces1< IToolSvcextend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces1< IToolSvcextend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- Public Types inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
typedef CommonMessaging base_class
 
typedef CommonMessaging base_class
 
- Public Types inherited from implements3< IService, IProperty, IStateful >
typedef implements3 base_class
 Typedef to this class. More...
 
typedef implements3 base_class
 Typedef to this class. More...
 
typedef extend_interfaces3< IService, IProperty, IStatefulextend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces3< IService, IProperty, IStatefulextend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces3< IService, IProperty, IStateful >
typedef mpl::fold< typename IService::iid::iids::type, typename mpl::fold< typename IProperty::iid::iids::type, typename IStateful::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
 MPL set of interfaces extended by this one. More...
 
typedef mpl::fold< typename IService::iid::iids::type, typename mpl::fold< typename IProperty::iid::iids::type, typename IStateful::iid::iids::type, mpl::insert< mpl::_1, mpl::_2 > >::type, mpl::insert< mpl::_1, mpl::_2 > >::type ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IInterface
enum  Status {
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR,
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR
}
 Return status. More...
 
enum  Status {
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR,
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR
}
 Return status. More...
 
typedef Gaudi::InterfaceId< IInterface, 0, 0 > iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
typedef Gaudi::InterfaceId< IInterface, 0, 0 > iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Public Types inherited from extend_interfaces1< IToolSvc >
typedef IToolSvc::iid::iids::type ext_iids
 MPL set of interfaces extended by this one. More...
 
typedef IToolSvc::iid::iids::type ext_iids
 MPL set of interfaces extended by this one. More...
 

Public Member Functions

virtual StatusCode initialize ()
 Initialize the service. More...
 
virtual StatusCode finalize ()
 Finalize the service. More...
 
virtual StatusCode start ()
 Start (from INITIALIZED to RUNNING). More...
 
virtual StatusCode stop ()
 Stop (from RUNNING to INITIALIZED). More...
 
virtual StatusCode retrieve (const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf)
 Retrieve tool, create it by default as common tool if it does not already exist. More...
 
virtual StatusCode retrieve (const std::string &tooltype, const std::string &toolname, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf)
 Retrieve tool, create it by default as common tool if it does not already exist. More...
 
virtual std::vector< std::string > getInstances (const std::string &toolType)
 Get names of all tool instances of a given type. More...
 
virtual std::vector< std::string > getInstances () const
 Get names of all tool instances. More...
 
virtual std::vector< IAlgTool * > getTools () const
 Get pointers to all tool instances. More...
 
virtual StatusCode releaseTool (IAlgTool *tool)
 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...
 
unsigned long refCountTool (IAlgTool *tool) const
 Get current refcount for tool. More...
 
 ToolSvc (const std::string &name, ISvcLocator *svc)
 Standard Constructor. More...
 
virtual ~ToolSvc ()
 Destructor. More...
 
virtual void registerObserver (IToolSvc::Observer *obs)
 
virtual void unRegisterObserver (IToolSvc::Observer *obs)
 
- Public Member Functions inherited from extends1< Service, IToolSvc >
 extends1 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments. More...
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments. More...
 
 extends1 (A1 a1)
 Templated constructor with 1 argument. More...
 
 extends1 ()
 Default constructor. More...
 
 extends1 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments. More...
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments. More...
 
 extends1 (A1 a1)
 Templated constructor with 1 argument. More...
 
 extends1 ()
 Default constructor. More...
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast. More...
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface. More...
 
virtual std::vector< std::string > getInterfaceNames () const
 Implementation of IInterface::getInterfaceNames. More...
 
virtual std::vector< std::string > getInterfaceNames () const
 Implementation of IInterface::getInterfaceNames. More...
 
virtual ~extends1 ()
 Virtual destructor. More...
 
virtual ~extends1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance. More...
 
virtual const std::string & name () const
 Retrieve name of the service. More...
 
virtual StatusCode configure ()
 Configuration (from OFFLINE to CONFIGURED). More...
 
virtual StatusCode terminate ()
 Initialization (from CONFIGURED to OFFLINE). More...
 
virtual Gaudi::StateMachine::State FSMState () const
 Get the current state. More...
 
virtual Gaudi::StateMachine::State targetFSMState () const
 When we are in the middle of a transition, get the state where the transition is leading us. More...
 
virtual StatusCode reinitialize ()
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED). More...
 
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
virtual StatusCode sysInitialize ()
 Initialize Service. More...
 
virtual StatusCode sysStart ()
 Initialize Service. More...
 
virtual StatusCode sysStop ()
 Initialize Service. More...
 
virtual StatusCode sysFinalize ()
 Finalize Service. More...
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service. More...
 
virtual StatusCode sysRestart ()
 Re-initialize the Service. More...
 
virtual StatusCode setProperty (const Property &p)
 Set the property by property. More...
 
virtual StatusCode setProperty (const std::string &s)
 Set the property by string. More...
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Set the property by std::string. More...
 
virtual StatusCode getProperty (Property *p) const
 Get the property by property. More...
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name. More...
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Get the property by std::string. More...
 
virtual const std::vector< Property * > & getProperties () const
 Get list of properties. More...
 
virtual bool hasProperty (const std::string &name) const
 Return true if we have a property with the given name. More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 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<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 >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
virtual unsigned long release ()
 Release Interface instance. More...
 
virtual const std::string & name () const
 Retrieve name of the service. More...
 
virtual StatusCode configure ()
 Configuration (from OFFLINE to CONFIGURED). More...
 
virtual StatusCode terminate ()
 Initialization (from CONFIGURED to OFFLINE). More...
 
virtual Gaudi::StateMachine::State FSMState () const
 Get the current state. More...
 
virtual Gaudi::StateMachine::State targetFSMState () const
 When we are in the middle of a transition, get the state where the transition is leading us. More...
 
virtual StatusCode reinitialize ()
 Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED). More...
 
virtual StatusCode restart ()
 Initialization (from RUNNING to RUNNING, via INITIALIZED). More...
 
virtual StatusCode sysInitialize ()
 Initialize Service. More...
 
virtual StatusCode sysStart ()
 Initialize Service. More...
 
virtual StatusCode sysStop ()
 Initialize Service. More...
 
virtual StatusCode sysFinalize ()
 Finalize Service. More...
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service. More...
 
virtual StatusCode sysRestart ()
 Re-initialize the Service. More...
 
virtual StatusCode setProperty (const Property &p)
 Set the property by property. More...
 
virtual StatusCode setProperty (const std::string &s)
 Set the property by string. More...
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Set the property by std::string. More...
 
virtual StatusCode getProperty (Property *p) const
 Get the property by property. More...
 
virtual const PropertygetProperty (const std::string &name) const
 Get the property by name. More...
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Get the property by std::string. More...
 
virtual const std::vector< Property * > & getProperties () const
 Get list of properties. More...
 
virtual bool hasProperty (const std::string &name) const
 Return true if we have a property with the given name. More...
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 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<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 >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments. More...
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument. More...
 
 CommonMessaging ()
 Default constructor. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments. More...
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments. More...
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument. More...
 
 CommonMessaging ()
 Default constructor. More...
 
virtual ~CommonMessaging ()
 Virtual destructor. More...
 
virtual ~CommonMessaging ()
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces3< IService, IProperty, IStateful >
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
virtual ~extend_interfaces3 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IService
 DeclareInterfaceID (IService, 3, 0)
 InterfaceID. More...
 
virtual ~IService ()
 virtual destructor More...
 
 DeclareInterfaceID (IService, 3, 0)
 InterfaceID. More...
 
virtual ~IService ()
 virtual destructor More...
 
- Public Member Functions inherited from INamedInterface
 DeclareInterfaceID (INamedInterface, 1, 0)
 InterfaceID. More...
 
virtual ~INamedInterface ()
 Virtual destructor (always needed for abstract classes). More...
 
 DeclareInterfaceID (INamedInterface, 1, 0)
 InterfaceID. More...
 
virtual ~INamedInterface ()
 Virtual destructor (always needed for abstract classes). More...
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IProperty
 DeclareInterfaceID (IProperty, 2, 1)
 InterfaceID. More...
 
 DeclareInterfaceID (IProperty, 2, 1)
 InterfaceID. More...
 
- Public Member Functions inherited from IStateful
 DeclareInterfaceID (IStateful, 1, 0)
 InterfaceID. More...
 
virtual ~IStateful ()
 
 DeclareInterfaceID (IStateful, 1, 0)
 InterfaceID. More...
 
virtual ~IStateful ()
 
- Public Member Functions inherited from extend_interfaces1< IToolSvc >
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IToolSvc
 DeclareInterfaceID (IToolSvc, 2, 1)
 InterfaceID. More...
 
template<class T >
StatusCode retrieveTool (const std::string &type, T *&tool, const IInterface *parent=0, bool createIf=true)
 Retrieve specified tool sub-type with tool dependent part of the name automatically assigned. More...
 
template<class T >
StatusCode retrieveTool (const std::string &type, const std::string &name, T *&tool, const IInterface *parent=0, bool createIf=true)
 Retrieve specified tool sub-type with tool dependent part of the name tool dependent part of the name specified by the requester. More...
 
 DeclareInterfaceID (IToolSvc, 2, 1)
 InterfaceID. More...
 
template<class T >
StatusCode retrieveTool (const std::string &type, T *&tool, const IInterface *parent=0, bool createIf=true)
 Retrieve specified tool sub-type with tool dependent part of the name automatically assigned. More...
 
template<class T >
StatusCode retrieveTool (const std::string &type, const std::string &name, T *&tool, const IInterface *parent=0, bool createIf=true)
 Retrieve specified tool sub-type with tool dependent part of the name tool dependent part of the name specified by the requester. More...
 

Private Member Functions

unsigned long totalToolRefCount () const
 The total number of refCounts on all tools in the instancesTools list. More...
 
unsigned long totalToolRefCount (const ListTools &) const
 The total number of refCounts on all tools in the 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

ListTools m_instancesTools
 Common Tools. More...
 
IHistorySvcm_pHistorySvc
 Pointer to HistorySvc. More...
 
std::vector< IToolSvc::Observer * > m_observers
 

Additional Inherited Members

- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
- Protected Member Functions inherited from Service
virtual ~Service ()
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
virtual ~Service ()
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level. More...
 
Gaudi::StateMachine::State m_state
 Service state. More...
 
Gaudi::StateMachine::State m_targetState
 Service state. More...
 
- Protected Attributes inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
SmartIF< IMessageSvcm_msgsvc
 Pointer to the message service;. More...
 
std::auto_ptr< MsgStreamm_msgStream
 The predefined message stream. More...
 
bool m_streamWithService
 Flag to create a new MsgStream if it was created without the message 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 23 of file ToolSvc.h.

Member Typedef Documentation

typedef std::list<IAlgTool*> ToolSvc::ListTools

Definition at line 28 of file ToolSvc.h.

Constructor & Destructor Documentation

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

Standard Constructor.

Parameters
nameString with service name
svcPointer to service locator interface

Definition at line 31 of file ToolSvc.cpp.

33  : base_class(name, svc),
34  m_pHistorySvc(0)
35  { }
IHistorySvc * m_pHistorySvc
Pointer to HistorySvc.
Definition: ToolSvc.h:114
extends1 base_class
Typedef to this class.
Definition: extends.h:12
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
ToolSvc::~ToolSvc ( )
virtual

Destructor.

Definition at line 38 of file ToolSvc.cpp.

40 {
41 
42 }

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 436 of file ToolSvc.cpp.

440 {
441  const std::string & toolname = tooltype;
442  return create( tooltype, toolname, parent, tool);
443 }
StatusCode create(const std::string &type, const IInterface *parent, IAlgTool *&tool)
Create Tool standard way with automatically assigned name.
Definition: ToolSvc.cpp:436
tuple toolname
Definition: gaudirun.py:326
StatusCode ToolSvc::create ( const std::string &  type,
const std::string &  name,
const IInterface parent,
IAlgTool *&  tool 
)

Create Tool standard way with specified name.

invoke create callbacks...

Definition at line 495 of file ToolSvc.cpp.

500 {
501  // protect against empty type
502  if ( UNLIKELY(tooltype.empty()) ) {
503  error() << "create(): No Tool Type given" << endmsg;
504  return StatusCode::FAILURE;
505  }
506 
507  // If parent has not been specified, assume it is the ToolSvc
508  if ( 0 == parent ) parent = this;
509 
510  tool = 0;
511  // Automatically deletes the tool if not explicitly kept (i.e. on success).
512  // The tool is removed from the list of known tools too.
513  ToolCreateGuard toolguard(m_instancesTools);
514 
515  // Check if the tool already exist : this should never happen
516  const std::string fullname = nameTool(toolname, parent);
517  if( UNLIKELY(existsTool(fullname)) ) {
518  error() << "Tool " << fullname << " already exists" << endmsg;
519  return StatusCode::FAILURE;
520  }
521  // instantiate the tool using the factory
522  try {
523  toolguard = AlgTool::Factory::create(tooltype, tooltype, fullname, parent);
524  if ( UNLIKELY(! toolguard.get()) ){
525  error() << "Cannot create tool " << tooltype << " (No factory found)" << endmsg;
526  return StatusCode::FAILURE;
527  }
528  }
529  catch ( const GaudiException& Exception ) {
530  // (1) perform the printout of message
531  fatal() << "Exception with tag=" << Exception.tag()
532  << " is caught whilst instantiating tool '" << tooltype << "'" << endmsg;
533  // (2) print the exception itself
534  // (NB! - GaudiException is a linked list of all "previous exceptions")
535  fatal() << Exception << endmsg;
536  return StatusCode::FAILURE;
537  }
538  catch( const std::exception& Exception ) {
539  // (1) perform the printout of message
540  fatal() << "Standard std::exception is caught whilst instantiating tool '"
541  << tooltype << "'" << endmsg;
542  // (2) print the exception itself
543  // (NB! - GaudiException is a linked list of all "previous exceptions")
544  fatal() << Exception.what() << endmsg;
545  return StatusCode::FAILURE;
546  }
547  catch(...) {
548  // (1) perform the printout
549  fatal() << "UNKNOWN Exception is caught whilst instantiating tool '"
550  << tooltype << "'" << endmsg;
551  return StatusCode::FAILURE;
552  }
553  ON_VERBOSE verbose() << "Created tool " << tooltype << "/" << fullname << endmsg;
554 
555  // Since only AlgTool has the setProperties() method it is necessary to cast
556  // to downcast IAlgTool to AlgTool in order to set the properties via the JobOptions
557  // service
558  AlgTool* mytool = dynamic_cast<AlgTool*> (toolguard.get());
559  if ( mytool != 0 ) {
560  StatusCode sc = mytool->setProperties();
561  if ( UNLIKELY(sc.isFailure()) ) {
562  error() << "Error setting properties for tool '"
563  << fullname << "'" << endmsg;
564  return sc;
565  }
566  }
567 
568  // Initialize the Tool
570  try {
571  sc = toolguard->sysInitialize();
572  }
573  // Catch any exceptions
574  catch ( const GaudiException & Exception )
575  {
576  error()
577  << "GaudiException with tag=" << Exception.tag()
578  << " caught whilst initializing tool '" << fullname << "'" << endmsg
579  << Exception << endmsg;
580  return StatusCode::FAILURE;
581  }
582  catch( const std::exception & Exception )
583  {
584  error()
585  << "Standard std::exception caught whilst initializing tool '"
586  << fullname << "'" << endmsg << Exception.what() << endmsg;
587  return StatusCode::FAILURE;
588  }
589  catch (...)
590  {
591  error()
592  << "UNKNOWN Exception caught whilst initializing tool '"
593  << fullname << "'" << endmsg;
594  return StatusCode::FAILURE;
595  }
596 
597  // Status of tool initialization
598  if ( UNLIKELY(sc.isFailure()) ) {
599  error() << "Error initializing tool '" << fullname << "'" << endmsg;
600  return sc;
601  }
602 
603  // Start the tool if we are running.
605  sc = toolguard->sysStart();
606 
607  if (UNLIKELY(sc.isFailure())) {
608  error() << "Error starting tool '" << fullname << "'" << endmsg;
609  return sc;
610  }
611  }
612 
613 
614  // The tool has been successfully created and initialized,
615  // so we the guard can be released
616  tool = toolguard.release();
617 
621  if (!m_observers.empty()) {
622  std::for_each( m_observers.begin(),
623  m_observers.end(),
625  bl::_1,
626  tool));
627  }
628  // TODO: replace by generic callback
629  // Register the tool with the HistorySvc
630  if (m_pHistorySvc != 0 ||
631  service("HistorySvc",m_pHistorySvc,false).isSuccess() ) {
633  }
634 
635  return StatusCode::SUCCESS;
636 
637 }
IHistorySvc * m_pHistorySvc
Pointer to HistorySvc.
Definition: ToolSvc.h:114
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Define general base for Gaudi exception.
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:246
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::string nameTool(const std::string &nameByUser, const IInterface *parent)
Get Tool full name by combining nameByUser and "parent" part.
Definition: ToolSvc.cpp:640
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:116
bool existsTool(const std::string &toolname) const
Check if the tool instance exists.
Definition: ToolSvc.cpp:669
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
StatusCode setProperties()
Method for setting declared properties to the values specified in the jobOptions via the job option s...
Definition: AlgTool.cpp:151
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:243
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode registerAlgTool(const IAlgTool &)=0
virtual const std::string & tag() const
name tag for the exception, or exception type
virtual unsigned long release()=0
Release Interface instance.
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:34
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
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:143
#define UNLIKELY(x)
Definition: Kernel.h:127
void ignore() const
Definition: StatusCode.h:107
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
#define ON_VERBOSE
Definition: ToolSvc.cpp:22
tuple toolname
Definition: gaudirun.py:326
bool ToolSvc::existsTool ( const std::string &  toolname) const

Check if the tool instance exists.

Definition at line 669 of file ToolSvc.cpp.

671 {
672  for ( ListTools::const_iterator it = m_instancesTools.begin();
673  it != m_instancesTools.end(); ++it ) {
674  if ( (*it)->name() == fullname ) { return true; }
675  }
676  return false;
677 }
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
StatusCode ToolSvc::finalize ( )
virtual

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

Reimplemented from Service.

Definition at line 67 of file ToolSvc.cpp.

69 {
70  // Finalize and delete all left-over tools. Normally all tools created with
71  // ToolSvc are left over, since ToolSvc holds a refCount (via AlgTool ctor).
72  // Several cases need to be covered:
73  // 1) Simple dependencies: no circular dependencies between tools,
74  // and tools not using other tools
75  // 2) Tools-using-tools (but no circular dependencies)
76  // a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm)
77  // b) release() is called in the tool destructor (e.g. via ToolHandle)
78  // 3) Circular dependencies between tools
79  // a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm)
80  // b) release() is called in the tool destructor (e.g. via ToolHandle)
81  // 4) In addition to each of the above cases, refCounting of a particular tool
82  // might not have been done correctly in the code. Typically release()
83  // is not called, so we are left with a too high refCount.
84  // What to do with those, and how to avoid a crash while handling them...
85 
94  ListTools finalizedTools; // list of tools that have been finalized
95  info() << "Removing all tools created by ToolSvc" << endmsg;
96 
97  // Print out list of tools
98  ON_DEBUG {
99  MsgStream &log = debug();
100  log << " Tool List : ";
101  for ( ListTools::const_iterator iTool = m_instancesTools.begin();
102  iTool != m_instancesTools.end(); ++iTool ) {
103  log << (*iTool)->name() << ":" << refCountTool( *iTool ) << " ";
104  }
105  log << endmsg;
106  }
107 
108  //
109  // first pass: Finalize all tools (but don't delete them)
110  //
123  bool fail(false);
124  size_t toolCount = m_instancesTools.size();
125  unsigned long startRefCount = 0;
126  unsigned long endRefCount = totalToolRefCount();
127  unsigned long startMinRefCount = 0;
128  unsigned long endMinRefCount = minimumToolRefCount();
129  while ( toolCount > 0 &&
130  endRefCount > 0 &&
131  (endRefCount != startRefCount || endMinRefCount != startMinRefCount) ) {
132  ON_DEBUG if ( endMinRefCount != startMinRefCount ) {
133  debug() << toolCount << " tools left to finalize. Summed refCounts: "
134  << endRefCount << endmsg;
135  debug() << "Will finalize tools with refCount <= "
136  << endMinRefCount << endmsg;
137  }
138  startMinRefCount = endMinRefCount;
139  startRefCount = endRefCount;
140  unsigned long maxLoop = toolCount + 1;
141  while ( --maxLoop > 0 && m_instancesTools.size() > 0 ) {
142  IAlgTool* pTool = m_instancesTools.back();
143  // removing tool from list makes ToolSvc::releaseTool( IAlgTool* ) a noop
144  m_instancesTools.pop_back();
145  unsigned long count = refCountTool( pTool );
146  // cache tool name
147  std::string toolName = pTool->name();
148  if ( count <= startMinRefCount ) {
149  ON_DEBUG debug() << " Performing finalization of " << toolName
150  << " (refCount " << count << ")" << endmsg;
151  // finalize of one tool may trigger a release of another tool
152  // pTool->sysFinalize().ignore();
153  if (!finalizeTool(pTool).isSuccess()) {
154  warning() << " FAILURE finalizing " << toolName << endmsg;
155  fail = true;
156  }
157  // postpone deletion
158  finalizedTools.push_back(pTool);
159  } else {
160  // Place back in list to try again later
161  // ToolSvc::releaseTool( IAlgTool* ) remains active for this tool
162  ON_DEBUG debug() << " Delaying finalization of " << toolName
163  << " (refCount " << count << ")" << endmsg;
164  m_instancesTools.push_front(pTool);
165  }
166  } // end of inner loop
167  toolCount = m_instancesTools.size();
168  endRefCount = totalToolRefCount();
169  endMinRefCount = minimumToolRefCount();
170  }; // end of outer loop
171 
172  //
173  // Second pass: Delete all finalized tools
174  //
175  // Delete in the order of increasing number of refCounts.
176  // Loop over tools in the same order as the order in which they were finalized.
177  // All tools in the list of finalized tools are no longer in the instancesTools list.
178  // If a tool destructor calls releaseTool() on another tool, this will have no
179  // effect on the 'other tool' if this 'other tool' is in the list of finalized tools.
180  // If this 'other tool' is still in the instancesTools list, it may trigger finalization
181  // (in releaseTool()), deletion and removal from the instancesTools list.
182  // Therefore, the check on non-finalised tools should happen *after* the deletion
183  // of the finalized tools.
184  ON_DEBUG debug() << "Deleting " << finalizedTools.size() << " finalized tools" << endmsg;
185  unsigned long maxLoop = totalToolRefCount( finalizedTools ) + 1;
186  while ( --maxLoop > 0 && finalizedTools.size() > 0 ) {
187  IAlgTool* pTool = finalizedTools.front();
188  finalizedTools.pop_front();
189  unsigned long count = refCountTool( pTool );
190  if ( count == 1 ) {
191  ON_DEBUG debug() << " Performing deletion of " << pTool->name() << endmsg;
192  } else {
193  ON_VERBOSE verbose() << " Delaying deletion of " << pTool->name()
194  << " (refCount " << count << ")" << endmsg;
195  // Put it back at the end of the list if refCount still not zero
196  finalizedTools.push_back(pTool);
197  }
198  // do a forced release
199  pTool->release();
200  }
201 
202  // Error if by now not all tools are properly finalised
203  if ( !m_instancesTools.empty() ) {
204  error() << "Unable to finalize and delete the following tools : ";
205  for ( ListTools::const_iterator iTool = m_instancesTools.begin();
206  iTool != m_instancesTools.end(); ++iTool ) {
207  error() << (*iTool)->name() << ": " << refCountTool( *iTool ) << " ";
208  }
209  error() << endmsg;
210  }
211 
212  // by now, all tools should be deleted and removed.
213  if ( finalizedTools.size() > 0 ) {
214  error() << "Failed to delete the following " << finalizedTools.size()
215  << " finalized tools. Bug in ToolSvc::finalize()?: ";
216  for ( ListTools::const_iterator iTool = finalizedTools.begin();
217  iTool != finalizedTools.end(); ++iTool ) {
218  error() << (*iTool)->name() << ": " << refCountTool( *iTool ) << " ";
219  }
220  error() << endmsg;
221  }
222 
223  if ( 0 != m_pHistorySvc ) {
225  }
226 
227  // Finalize this specific service
228  if (! Service::finalize().isSuccess() || fail) {
229  return StatusCode::FAILURE;
230  } else {
231  return StatusCode::SUCCESS;
232  }
233 
234 
235 }
IHistorySvc * m_pHistorySvc
Pointer to HistorySvc.
Definition: ToolSvc.h:114
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
unsigned long minimumToolRefCount() const
The minimum number of refCounts of all tools.
Definition: ToolSvc.cpp:739
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
virtual const std::string & name() const =0
Retrieve the name of the instance.
unsigned long totalToolRefCount() const
The total number of refCounts on all tools in the instancesTools list.
Definition: ToolSvc.cpp:733
StatusCode finalizeTool(IAlgTool *itool) const
Finalize the given tool, with exception handling.
Definition: ToolSvc.cpp:680
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
virtual unsigned long release()=0
Release Interface instance.
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
#define ON_DEBUG
Definition: ToolSvc.cpp:21
std::list< IAlgTool * > ListTools
Definition: ToolSvc.h:28
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
#define ON_VERBOSE
Definition: ToolSvc.cpp:22
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
Definition: Service.cpp:197
unsigned long refCountTool(IAlgTool *tool) const
Get current refcount for tool.
Definition: ToolSvc.h:79
StatusCode ToolSvc::finalizeTool ( IAlgTool itool) const
private

Finalize the given tool, with exception handling.

Definition at line 680 of file ToolSvc.cpp.

682 {
683 
684  // Cache tool name in case of errors
685  const std::string toolName = itool->name();
686  StatusCode sc;
687 
688  // Finalise the tool inside a try block
689  try {
690  sc = itool->sysFinalize();
691  }
692  // Catch any exceptions
693  catch ( const GaudiException & Exception )
694  {
695  error()
696  << "GaudiException with tag=" << Exception.tag()
697  << " caught whilst finalizing tool '" << toolName << "'" << endmsg
698  << Exception << endmsg;
699  sc = StatusCode::FAILURE;
700  }
701  catch( const std::exception & Exception )
702  {
703  error()
704  << "Standard std::exception caught whilst finalizing tool '"
705  << toolName << "'" << endmsg << Exception.what() << endmsg;
706  sc = StatusCode::FAILURE;
707  }
708  catch (...)
709  {
710  error()
711  << "UNKNOWN Exception caught whilst finalizing tool '"
712  << toolName << "'" << endmsg;
713  sc = StatusCode::FAILURE;
714  }
715 
716  return sc;
717 
718 }
Define general base for Gaudi exception.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode sysFinalize()=0
Finalization of the Tool.
virtual const std::string & name() const =0
Retrieve the name of the instance.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual const std::string & tag() const
name tag for the exception, or exception type
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
std::vector< std::string > ToolSvc::getInstances ( const std::string &  toolType)
virtual

Get names of all tool instances of a given type.

Implements IToolSvc.

Definition at line 369 of file ToolSvc.cpp.

371 {
372 
373  std::vector<std::string> tools;
374 
375  for(auto tool: m_instancesTools) {
376  if (tool->type() == toolType) {
377  tools.push_back( tool->name() );
378  }
379  }
380 
381  return tools;
382 
383 }
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
std::vector< std::string > ToolSvc::getInstances ( ) const
virtual

Get names of all tool instances.

Implements IToolSvc.

Definition at line 385 of file ToolSvc.cpp.

387 {
388  std::vector<std::string> tools{m_instancesTools.size()};
389  std::transform(std::begin(m_instancesTools), std::end(m_instancesTools),
390  std::begin(tools),
391  [](IAlgTool* tool) {return tool->name();});
392  return tools;
393 }
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
virtual const std::string & name() const =0
Retrieve the name of the instance.
tuple end
Definition: IOTest.py:101
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
std::vector< IAlgTool * > ToolSvc::getTools ( ) const
virtual

Get pointers to all tool instances.

Implements IToolSvc.

Definition at line 395 of file ToolSvc.cpp.

397 {
398  return std::vector<IAlgTool*>{std::begin(m_instancesTools),
400 }
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
tuple end
Definition: IOTest.py:101
StatusCode ToolSvc::initialize ( )
virtual

Initialize the service.

Reimplemented from Service.

Definition at line 45 of file ToolSvc.cpp.

47 {
48 
49  // initialize the Service Base class
51  if (UNLIKELY(status.isFailure()))
52  {
53  error() << "Unable to initialize the Service" << endmsg;
54  return status;
55  }
56 
57  // set my own (ToolSvc) properties via the jobOptionService
58  if (UNLIKELY(setProperties().isFailure())) {
59  error() << "Unable to set base properties" << endmsg;
60  return StatusCode::FAILURE;
61  }
62 
63  return status;
64 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
StatusCode setProperties()
Method for setting declared properties to the values specified for the job.
Definition: Service.cpp:373
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Definition: Service.cpp:72
#define UNLIKELY(x)
Definition: Kernel.h:127
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
unsigned long ToolSvc::minimumToolRefCount ( ) const
private

The minimum number of refCounts of all tools.

Definition at line 739 of file ToolSvc.cpp.

741 {
742  unsigned long count = 0;
743  if ( m_instancesTools.size() > 0 ) {
744  ListTools::const_iterator iTool = m_instancesTools.begin();
745  // start with first
746  count = refCountTool( *iTool );
747  // then compare the others
748  for( ++iTool; iTool != m_instancesTools.end(); ++iTool ) {
749  count = std::min( count, refCountTool( *iTool ) );
750  }
751  }
752  return count;
753 }
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
#define min(a, b)
unsigned long refCountTool(IAlgTool *tool) const
Get current refcount for tool.
Definition: ToolSvc.h:79
std::string ToolSvc::nameTool ( const std::string &  nameByUser,
const IInterface parent 
)

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

Definition at line 640 of file ToolSvc.cpp.

643 {
644 
645  std::string fullname = "";
646  if ( parent == 0 ) { return this->name() + "." + toolname; } // RETURN
647 
648 
649  IInterface* cparent = const_cast<IInterface*>( parent ) ;
650  // check that parent has a name!
651  INamedInterface* _p = 0 ;
652  StatusCode sc = cparent->queryInterface( INamedInterface::interfaceID() , pp_cast<void>(&_p) ) ;
653  if ( sc.isSuccess() )
654  {
655  fullname = _p->name() + "." + toolname ;
656  _p->release() ;
657  return fullname ; // RETURN
658  }
659 
660  MsgStream log ( msgSvc(), name() );
661  log << MSG::ERROR
662  << "Private Tools only allowed for components implementing INamedInterface"
663  << endmsg;
664  //
665  return "." + toolname ;
666 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
virtual const std::string & name() const =0
Retrieve the name of the instance.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Definition of the basic interface.
Definition: IInterface.h:160
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
IInterface compliant class extending IInterface with the name() method.
virtual unsigned long release()=0
Release Interface instance.
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:171
tuple toolname
Definition: gaudirun.py:326
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
unsigned long ToolSvc::refCountTool ( IAlgTool tool) const
inline

Get current refcount for tool.

Definition at line 79 of file ToolSvc.h.

79 { return tool->refCount(); }
virtual unsigned long refCount() const =0
Current number of reference counts.
void ToolSvc::registerObserver ( IToolSvc::Observer obs)
virtual

Implements IToolSvc.

Definition at line 755 of file ToolSvc.cpp.

755  {
756  if ( 0 == obs )
757  throw GaudiException( "Received NULL pointer", this->name() + "::registerObserver", StatusCode::FAILURE );
758  m_observers.push_back(obs);
759 }
Define general base for Gaudi exception.
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:116
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
StatusCode ToolSvc::releaseTool ( IAlgTool tool)
virtual

Release tool.

Implements IToolSvc.

Definition at line 402 of file ToolSvc.cpp.

404 {
406  // test if tool is in known list (protect trying to access a previously deleted tool)
407  if ( m_instancesTools.rend() != std::find( m_instancesTools.rbegin(),
408  m_instancesTools.rend(),
409  tool ) ) {
410  unsigned long count = refCountTool(tool);
411  if ( count == 1 ) {
412  MsgStream log( msgSvc(), name() );
413  // finalize the tool
414 
416  // We are being called during ToolSvc::finalize()
417  // message format matches the one in ToolSvc::finalize()
418  log << MSG::DEBUG << " Performing finalization of " << tool->name()
419  << " (refCount " << count << ")" << endmsg;
420  // message format matches the one in ToolSvc::finalize()
421  log << MSG::DEBUG << " Performing deletion of " << tool->name() << endmsg;
422  } else {
423  log << MSG::DEBUG << "Performing finalization and deletion of " << tool->name() << endmsg;
424  }
425  sc = finalizeTool(tool);
426  // remove from known tools...
427  m_instancesTools.remove(tool);
428  }
429  tool->release();
430  }
431 
432  return sc;
433 }
Gaudi::StateMachine::State m_targetState
Service state.
Definition: Service.h:248
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
virtual const std::string & name() const =0
Retrieve the name of the instance.
StatusCode finalizeTool(IAlgTool *itool) const
Finalize the given tool, with exception handling.
Definition: ToolSvc.cpp:680
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
virtual unsigned long release()=0
Release Interface instance.
unsigned long refCountTool(IAlgTool *tool) const
Get current refcount for tool.
Definition: ToolSvc.h:79
StatusCode ToolSvc::retrieve ( const std::string &  type,
const InterfaceID iid,
IAlgTool *&  tool,
const IInterface parent,
bool  createIf 
)
virtual

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

Implements IToolSvc.

Definition at line 248 of file ToolSvc.cpp.

254 {
255 
256  // protect against empty type
257  if ( tooltype.empty() ) {
258  error() << "retrieve(): No Tool Type/Name given" << endmsg;
259  return StatusCode::FAILURE;
260  }
261 
262  {
263  // check for tools, which by name is required to be public:
264  const std::string::size_type pos = tooltype.find ( s_PUBLIC ) ;
265  if ( std::string::npos != pos )
266  {
267  // set parent for PUBLIC tool
268  parent = this ;
269  return retrieve ( std::string( tooltype , 0 , pos ) ,
270  iid , tool , parent , createIf ) ;
271  }
272  }
273 
274  const std::string::size_type pos = tooltype.find('/');
275  if( std::string::npos == pos ) {
276  return retrieve ( tooltype , tooltype , iid , tool , parent , createIf );
277  }
278  const std::string newtype ( tooltype , 0 , pos ) ;
279  const std::string newname ( tooltype , pos + 1 , std::string::npos ) ;
280  return retrieve ( newtype , newname , iid , tool , parent , createIf ) ;
281 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode retrieve(const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf)
Retrieve tool, create it by default as common tool if it does not already exist.
Definition: ToolSvc.cpp:248
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StatusCode ToolSvc::retrieve ( const std::string &  tooltype,
const std::string &  toolname,
const InterfaceID iid,
IAlgTool *&  tool,
const IInterface parent,
bool  createIf 
)
virtual

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

invoke retrieve callbacks...

Implements IToolSvc.

Definition at line 286 of file ToolSvc.cpp.

293 {
294  // check the applicability of another method:
295  // ignore the provided name if it is empty or the type contains a name
296  if( toolname.empty() || (std::string::npos != tooltype.find('/')) )
297  { return retrieve ( tooltype , iid , tool , parent , createIf ) ; }
298 
299  {
300  // check for tools, which by name is required to be public:
301  const std::string::size_type pos = toolname.find ( s_PUBLIC ) ;
302  if ( std::string::npos != pos )
303  {
304  // set parent for PUBLIC tool
305  parent = this ;
306  return retrieve ( tooltype , std::string( toolname , 0 , pos ) ,
307  iid , tool , parent , createIf ) ;
308  }
309  }
310 
311  IAlgTool* itool = 0;
313 
314  tool = 0;
315 
316  // If parent is not specified it means it is the ToolSvc itself
317  if( 0 == parent ) {
318  parent = this;
319  }
320  const std::string fullname = nameTool( toolname, parent );
321 
322  // Find tool in list of those already existing, and tell its
323  // interface that it has been used one more time
324  ListTools::const_iterator it;
325  for( it = m_instancesTools.begin(); it != m_instancesTools.end(); ++it ) {
326  if( (*it)->name() == fullname ) {
327  ON_DEBUG debug() << "Retrieved tool " << toolname << endmsg;
328  itool = *it;
329  break;
330  }
331  }
332 
333  if ( 0 == itool ) {
334  // Instances of this tool do not exist, create an instance if desired
335  // otherwise return failure
336  if( UNLIKELY(!createIf) ) {
337  warning() << "Tool " << toolname
338  << " not found and creation not requested" << endmsg;
339  return sc;
340  }
341  else {
342  sc = create( tooltype, toolname, parent, itool );
343  if ( sc.isFailure() ) { return sc; }
344  }
345  }
346 
347  // Get the right interface of it
348  sc = itool->queryInterface( iid, (void**)&tool);
349  if( UNLIKELY(sc.isFailure()) ) {
350  error() << "Tool " << toolname
351  << " either does not implement the correct interface, or its version is incompatible"
352  << endmsg;
353  return sc;
354  }
358  if (!m_observers.empty()) {
359  std::for_each( m_observers.begin(),
360  m_observers.end(),
362  bl::_1,
363  itool));
364  }
365 
366  return sc;
367 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::string nameTool(const std::string &nameByUser, const IInterface *parent)
Get Tool full name by combining nameByUser and "parent" part.
Definition: ToolSvc.cpp:640
StatusCode create(const std::string &type, const IInterface *parent, IAlgTool *&tool)
Create Tool standard way with automatically assigned name.
Definition: ToolSvc.cpp:436
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:116
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual StatusCode retrieve(const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf)
Retrieve tool, create it by default as common tool if it does not already exist.
Definition: ToolSvc.cpp:248
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:244
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
#define ON_DEBUG
Definition: ToolSvc.cpp:21
#define UNLIKELY(x)
Definition: Kernel.h:127
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
tuple toolname
Definition: gaudirun.py:326
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.
StatusCode ToolSvc::start ( )
virtual

Start (from INITIALIZED to RUNNING).

Reimplemented from Service.

Definition at line 769 of file ToolSvc.cpp.

771 {
772 
773  ON_DEBUG debug() << "START transition for AlgTools" << endmsg;
774 
775  bool fail(false);
776  for ( ListTools::const_iterator iTool = m_instancesTools.begin();
777  iTool != m_instancesTools.end(); ++iTool ) {
778  ON_VERBOSE verbose() << (*iTool)->name() << "::start()" << endmsg;
779 
780  if (UNLIKELY(!(*iTool)->sysStart().isSuccess())) {
781  fail = true;
782  error() << (*iTool)->name() << " failed to start()" << endmsg;
783  }
784 
785  }
786 
787  if (UNLIKELY(fail)) {
788  error() << "One or more AlgTools failed to start()" << endmsg;
789  return StatusCode::FAILURE;
790  } else {
791  return StatusCode::SUCCESS;
792  }
793 
794 }
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
Definition: ToolSvc.cpp:21
#define UNLIKELY(x)
Definition: Kernel.h:127
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
#define ON_VERBOSE
Definition: ToolSvc.cpp:22
StatusCode ToolSvc::stop ( )
virtual

Stop (from RUNNING to INITIALIZED).

Reimplemented from Service.

Definition at line 798 of file ToolSvc.cpp.

800 {
801 
802  ON_DEBUG debug() << "STOP transition for AlgTools" << endmsg;
803 
804  bool fail(false);
805  for ( ListTools::const_iterator iTool = m_instancesTools.begin();
806  iTool != m_instancesTools.end(); ++iTool ) {
807  ON_VERBOSE verbose() << (*iTool)->name() << "::stop()" << endmsg;
808 
809  if (UNLIKELY(!(*iTool)->sysStop().isSuccess())) {
810  fail = true;
811  error() << (*iTool)->name() << " failed to stop()" << endmsg;
812  }
813 
814  }
815 
816  if (UNLIKELY(fail)) {
817  error() << "One or more AlgTools failed to stop()" << endmsg;
818  return StatusCode::FAILURE;
819  } else {
820  return StatusCode::SUCCESS;
821  }
822 
823 }
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
#define ON_DEBUG
Definition: ToolSvc.cpp:21
#define UNLIKELY(x)
Definition: Kernel.h:127
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
#define ON_VERBOSE
Definition: ToolSvc.cpp:22
unsigned long ToolSvc::totalToolRefCount ( ) const
private

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

Definition at line 733 of file ToolSvc.cpp.

735 {
737 }
ListTools m_instancesTools
Common Tools.
Definition: ToolSvc.h:111
unsigned long totalToolRefCount() const
The total number of refCounts on all tools in the instancesTools list.
Definition: ToolSvc.cpp:733
unsigned long ToolSvc::totalToolRefCount ( const ListTools toolList) const
private

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

Definition at line 721 of file ToolSvc.cpp.

723 {
724  unsigned long count = 0;
725  for ( ListTools::const_iterator iTool = toolList.begin();
726  iTool != toolList.end(); ++iTool ) {
727  count += refCountTool( *iTool );
728  }
729  return count;
730 }
unsigned long refCountTool(IAlgTool *tool) const
Get current refcount for tool.
Definition: ToolSvc.h:79
void ToolSvc::unRegisterObserver ( IToolSvc::Observer obs)
virtual

Implements IToolSvc.

Definition at line 761 of file ToolSvc.cpp.

761  {
762  std::vector<IToolSvc::Observer*>::iterator i =
763  find(m_observers.begin(),m_observers.end(),obs);
764  if (i!=m_observers.end()) m_observers.erase(i);
765 }
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:116
list i
Definition: ana.py:128

Member Data Documentation

ListTools ToolSvc::m_instancesTools
private

Common Tools.

Definition at line 111 of file ToolSvc.h.

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

Definition at line 116 of file ToolSvc.h.

IHistorySvc* ToolSvc::m_pHistorySvc
private

Pointer to HistorySvc.

Definition at line 114 of file ToolSvc.h.


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