Gaudi Framework, version v25r0

Home   Generated: Mon Feb 17 2014
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
ToolSvc Class Reference

This service manages tools. More...

#include <ToolSvc.h>

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

Public Types

typedef std::list< IAlgTool * > ListTools
 
- Public Types inherited from extends1< Service, IToolSvc >
typedef extends1 base_class
 Typedef to this class.
 
typedef extend_interfaces1
< IToolSvc
extend_interfaces_base
 Typedef to the base of this class.
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces.
 
- Public Types inherited from Service
typedef
Gaudi::PluginService::Factory2
< IService *, const
std::string &, ISvcLocator * > 
Factory
 
- Public Types inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
typedef CommonMessaging base_class
 
- Public Types inherited from implements3< IService, IProperty, IStateful >
typedef implements3 base_class
 Typedef to this class.
 
typedef extend_interfaces3
< IService, IProperty,
IStateful
extend_interfaces_base
 Typedef to the base of this class.
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces.
 
- Public Types inherited from extend_interfaces3< I1, I2, I3 >
typedef mpl::fold< typename
I1::iid::iids::type, typename
mpl::fold< typename
I2::iid::iids::type, typename
I3::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.
 
- Public Types inherited from extend_interfaces1< IToolSvc >
typedef IToolSvc::iid::iids::type ext_iids
 MPL set of interfaces extended by this one.
 

Public Member Functions

virtual StatusCode initialize ()
 Initialize the service.
 
virtual StatusCode finalize ()
 Finalize the service.
 
virtual StatusCode start ()
 
virtual StatusCode stop ()
 
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.
 
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.
 
virtual std::vector< std::stringgetInstances (const std::string &toolType)
 Get names of all tool instances of a given type.
 
virtual StatusCode releaseTool (IAlgTool *tool)
 Release tool.
 
StatusCode create (const std::string &type, const IInterface *parent, IAlgTool *&tool)
 Create Tool standard way with automatically assigned name.
 
StatusCode create (const std::string &type, const std::string &name, const IInterface *parent, IAlgTool *&tool)
 Create Tool standard way with specified name.
 
bool existsTool (const std::string &toolname) const
 Check if the tool instance exists.
 
std::string nameTool (const std::string &nameByUser, const IInterface *parent)
 Get Tool full name by combining nameByUser and "parent" part.
 
unsigned long refCountTool (IAlgTool *tool) const
 Get current refcount for tool.
 
 ToolSvc (const std::string &name, ISvcLocator *svc)
 Standard Constructor.
 
virtual ~ToolSvc ()
 Destructor.
 
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.
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments.
 
 extends1 (A1 a1)
 Templated constructor with 1 argument.
 
 extends1 ()
 Default constructor.
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast.
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface.
 
virtual std::vector< std::stringgetInterfaceNames () const
 Implementation of IInterface::getInterfaceNames.
 
virtual ~extends1 ()
 Virtual destructor.
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance.
 
virtual const std::stringname () const
 Retrieve name of the service.
 
virtual StatusCode configure ()
 
virtual StatusCode terminate ()
 
virtual Gaudi::StateMachine::State FSMState () const
 
virtual Gaudi::StateMachine::State targetFSMState () const
 
virtual StatusCode reinitialize ()
 
virtual StatusCode restart ()
 
virtual StatusCode sysInitialize ()
 Initialize Service.
 
virtual StatusCode sysStart ()
 Initialize Service.
 
virtual StatusCode sysStop ()
 Initialize Service.
 
virtual StatusCode sysFinalize ()
 Finalize Service.
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service.
 
virtual StatusCode sysRestart ()
 Re-initialize the Service.
 
virtual StatusCode setProperty (const Property &p)
 
virtual StatusCode setProperty (const std::string &s)
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 
virtual StatusCode getProperty (Property *p) const
 
virtual const PropertygetProperty (const std::string &name) const
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 
virtual const std::vector
< Property * > & 
getProperties () const
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator.
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job.
 
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.
 
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.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties.
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- 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.
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments.
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument.
 
 CommonMessaging ()
 Default constructor.
 
virtual ~CommonMessaging ()
 Virtual destructor.
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from extend_interfaces1< IToolSvc >
virtual ~extend_interfaces1 ()
 Virtual destructor.
 
- Public Member Functions inherited from IToolSvc
 DeclareInterfaceID (IToolSvc, 2, 0)
 InterfaceID.
 
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.
 
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.
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance.
 
virtual unsigned long release ()=0
 Release Interface instance.
 
virtual unsigned long refCount () const =0
 Current reference count.
 
virtual ~IInterface ()
 Virtual destructor.
 

Private Member Functions

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

Private Attributes

ListTools m_instancesTools
 Common Tools.
 
IHistorySvcm_pHistorySvc
 Pointer to HistorySvc.
 
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.
 
- Protected Member Functions inherited from Service
virtual ~Service ()
 Standard Destructor.
 
int outputLevel () const
 get the Service's output level
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level.
 
Gaudi::StateMachine::State m_state
 Service state.
 
Gaudi::StateMachine::State m_targetState
 Service state.
 

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

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.

: base_class(name, svc),
{ }
ToolSvc::~ToolSvc ( )
virtual

Destructor.

Definition at line 38 of file ToolSvc.cpp.

{
}

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

{
const std::string & toolname = tooltype;
return create( tooltype, toolname, parent, tool);
}
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 479 of file ToolSvc.cpp.

{
// protect against empty type
if ( UNLIKELY(tooltype.empty()) ) {
error() << "create(): No Tool Type given" << endmsg;
}
// If parent has not been specified, assume it is the ToolSvc
if ( 0 == parent ) parent = this;
tool = 0;
// Automatically deletes the tool if not explicitly kept (i.e. on success).
// The tool is removed from the list of known tools too.
ToolCreateGuard toolguard(m_instancesTools);
// Check if the tool already exist : this should never happen
const std::string fullname = nameTool(toolname, parent);
if( UNLIKELY(existsTool(fullname)) ) {
error() << "Tool " << fullname << " already exists" << endmsg;
}
// instantiate the tool using the factory
try {
toolguard = AlgTool::Factory::create(tooltype, tooltype, fullname, parent);
if ( UNLIKELY(! toolguard.get()) ){
error() << "Cannot create tool " << tooltype << " (No factory found)" << endmsg;
}
}
catch ( const GaudiException& Exception ) {
// (1) perform the printout of message
fatal() << "Exception with tag=" << Exception.tag()
<< " is caught whilst instantiating tool '" << tooltype << "'" << endmsg;
// (2) print the exception itself
// (NB! - GaudiException is a linked list of all "previous exceptions")
fatal() << Exception << endmsg;
}
catch( const std::exception& Exception ) {
// (1) perform the printout of message
fatal() << "Standard std::exception is caught whilst instantiating tool '"
<< tooltype << "'" << endmsg;
// (2) print the exception itself
// (NB! - GaudiException is a linked list of all "previous exceptions")
fatal() << Exception.what() << endmsg;
}
catch(...) {
// (1) perform the printout
fatal() << "UNKNOWN Exception is caught whilst instantiating tool '"
<< tooltype << "'" << endmsg;
}
ON_VERBOSE verbose() << "Created tool " << tooltype << "/" << fullname << endmsg;
// Since only AlgTool has the setProperties() method it is necessary to cast
// to downcast IAlgTool to AlgTool in order to set the properties via the JobOptions
// service
AlgTool* mytool = dynamic_cast<AlgTool*> (toolguard.get());
if ( mytool != 0 ) {
if ( UNLIKELY(sc.isFailure()) ) {
error() << "Error setting properties for tool '"
<< fullname << "'" << endmsg;
return sc;
}
}
// Initialize the Tool
try {
sc = toolguard->sysInitialize();
}
// Catch any exceptions
catch ( const GaudiException & Exception )
{
<< "GaudiException with tag=" << Exception.tag()
<< " caught whilst initializing tool '" << fullname << "'" << endmsg
<< Exception << endmsg;
}
catch( const std::exception & Exception )
{
<< "Standard std::exception caught whilst initializing tool '"
<< fullname << "'" << endmsg << Exception.what() << endmsg;
}
catch (...)
{
<< "UNKNOWN Exception caught whilst initializing tool '"
<< fullname << "'" << endmsg;
}
// Status of tool initialization
if ( UNLIKELY(sc.isFailure()) ) {
error() << "Error initializing tool '" << fullname << "'" << endmsg;
return sc;
}
// Start the tool if we are running.
sc = toolguard->sysStart();
if (UNLIKELY(sc.isFailure())) {
error() << "Error starting tool '" << fullname << "'" << endmsg;
return sc;
}
}
// The tool has been successfully created and initialized,
// so we the guard can be released
tool = toolguard.release();
if (!m_observers.empty()) {
bl::_1,
tool));
}
// TODO: replace by generic callback
// Register the tool with the HistorySvc
if (m_pHistorySvc != 0 ||
service("HistorySvc",m_pHistorySvc,false).isSuccess() ) {
}
}
bool ToolSvc::existsTool ( const std::string toolname) const

Check if the tool instance exists.

Definition at line 653 of file ToolSvc.cpp.

{
it != m_instancesTools.end(); ++it ) {
if ( (*it)->name() == fullname ) { return true; }
}
return false;
}
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.

{
// Finalize and delete all left-over tools. Normally all tools created with
// ToolSvc are left over, since ToolSvc holds a refCount (via AlgTool ctor).
// Several cases need to be covered:
// 1) Simple dependencies: no circular dependencies between tools,
// and tools not using other tools
// 2) Tools-using-tools (but no circular dependencies)
// a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm)
// b) release() is called in the tool destructor (e.g. via ToolHandle)
// 3) Circular dependencies between tools
// a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm)
// b) release() is called in the tool destructor (e.g. via ToolHandle)
// 4) In addition to each of the above cases, refCounting of a particular tool
// might not have been done correctly in the code. Typically release()
// is not called, so we are left with a too high refCount.
// What to do with those, and how to avoid a crash while handling them...
ListTools finalizedTools; // list of tools that have been finalized
info() << "Removing all tools created by ToolSvc" << endmsg;
// Print out list of tools
log << " Tool List : ";
iTool != m_instancesTools.end(); ++iTool ) {
log << (*iTool)->name() << ":" << refCountTool( *iTool ) << " ";
}
log << endmsg;
}
//
// first pass: Finalize all tools (but don't delete them)
//
bool fail(false);
size_t toolCount = m_instancesTools.size();
unsigned long startRefCount = 0;
unsigned long endRefCount = totalToolRefCount();
unsigned long startMinRefCount = 0;
unsigned long endMinRefCount = minimumToolRefCount();
while ( toolCount > 0 &&
endRefCount > 0 &&
(endRefCount != startRefCount || endMinRefCount != startMinRefCount) ) {
ON_DEBUG if ( endMinRefCount != startMinRefCount ) {
debug() << toolCount << " tools left to finalize. Summed refCounts: "
<< endRefCount << endmsg;
debug() << "Will finalize tools with refCount <= "
<< endMinRefCount << endmsg;
}
startMinRefCount = endMinRefCount;
startRefCount = endRefCount;
unsigned long maxLoop = toolCount + 1;
while ( --maxLoop > 0 && m_instancesTools.size() > 0 ) {
// removing tool from list makes ToolSvc::releaseTool( IAlgTool* ) a noop
unsigned long count = refCountTool( pTool );
// cache tool name
std::string toolName = pTool->name();
if ( count <= startMinRefCount ) {
ON_DEBUG debug() << " Performing finalization of " << toolName
<< " (refCount " << count << ")" << endmsg;
// finalize of one tool may trigger a release of another tool
// pTool->sysFinalize().ignore();
if (!finalizeTool(pTool).isSuccess()) {
warning() << " FAILURE finalizing " << toolName << endmsg;
fail = true;
}
// postpone deletion
finalizedTools.push_back(pTool);
} else {
// Place back in list to try again later
// ToolSvc::releaseTool( IAlgTool* ) remains active for this tool
ON_DEBUG debug() << " Delaying finalization of " << toolName
<< " (refCount " << count << ")" << endmsg;
}
} // end of inner loop
toolCount = m_instancesTools.size();
endRefCount = totalToolRefCount();
endMinRefCount = minimumToolRefCount();
}; // end of outer loop
//
// Second pass: Delete all finalized tools
//
// Delete in the order of increasing number of refCounts.
// Loop over tools in the same order as the order in which they were finalized.
// All tools in the list of finalized tools are no longer in the instancesTools list.
// If a tool destructor calls releaseTool() on another tool, this will have no
// effect on the 'other tool' if this 'other tool' is in the list of finalized tools.
// If this 'other tool' is still in the instancesTools list, it may trigger finalization
// (in releaseTool()), deletion and removal from the instancesTools list.
// Therefore, the check on non-finalised tools should happen *after* the deletion
// of the finalized tools.
ON_DEBUG debug() << "Deleting " << finalizedTools.size() << " finalized tools" << endmsg;
unsigned long maxLoop = totalToolRefCount( finalizedTools ) + 1;
while ( --maxLoop > 0 && finalizedTools.size() > 0 ) {
IAlgTool* pTool = finalizedTools.front();
finalizedTools.pop_front();
unsigned long count = refCountTool( pTool );
if ( count == 1 ) {
ON_DEBUG debug() << " Performing deletion of " << pTool->name() << endmsg;
} else {
ON_VERBOSE verbose() << " Delaying deletion of " << pTool->name()
<< " (refCount " << count << ")" << endmsg;
// Put it back at the end of the list if refCount still not zero
finalizedTools.push_back(pTool);
}
// do a forced release
pTool->release();
}
// Error if by now not all tools are properly finalised
if ( !m_instancesTools.empty() ) {
error() << "Unable to finalize and delete the following tools : ";
iTool != m_instancesTools.end(); ++iTool ) {
error() << (*iTool)->name() << ": " << refCountTool( *iTool ) << " ";
}
error() << endmsg;
}
// by now, all tools should be deleted and removed.
if ( finalizedTools.size() > 0 ) {
error() << "Failed to delete the following " << finalizedTools.size()
<< " finalized tools. Bug in ToolSvc::finalize()?: ";
for ( ListTools::const_iterator iTool = finalizedTools.begin();
iTool != finalizedTools.end(); ++iTool ) {
error() << (*iTool)->name() << ": " << refCountTool( *iTool ) << " ";
}
error() << endmsg;
}
if ( 0 != m_pHistorySvc ) {
}
// Finalize this specific service
if (! Service::finalize().isSuccess() || fail) {
} else {
}
}
StatusCode ToolSvc::finalizeTool ( IAlgTool itool) const
private

Finalize the given tool, with exception handling.

Definition at line 664 of file ToolSvc.cpp.

{
// Cache tool name in case of errors
const std::string toolName = itool->name();
// Finalise the tool inside a try block
try {
sc = itool->sysFinalize();
}
// Catch any exceptions
catch ( const GaudiException & Exception )
{
<< "GaudiException with tag=" << Exception.tag()
<< " caught whilst finalizing tool '" << toolName << "'" << endmsg
<< Exception << endmsg;
}
catch( const std::exception & Exception )
{
<< "Standard std::exception caught whilst finalizing tool '"
<< toolName << "'" << endmsg << Exception.what() << endmsg;
}
catch (...)
{
<< "UNKNOWN Exception caught whilst finalizing tool '"
<< toolName << "'" << endmsg;
}
return sc;
}
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.

{
for (it = m_instancesTools.begin(); it != m_instancesTools.end(); ++it) {
if ((*it)->type() == toolType) {
tools.push_back( (*it)->name() );
}
}
return tools;
}
StatusCode ToolSvc::initialize ( )
virtual

Initialize the service.

Reimplemented from Service.

Definition at line 45 of file ToolSvc.cpp.

{
// initialize the Service Base class
if (UNLIKELY(status.isFailure()))
{
error() << "Unable to initialize the Service" << endmsg;
return status;
}
// set my own (ToolSvc) properties via the jobOptionService
if (UNLIKELY(setProperties().isFailure())) {
error() << "Unable to set base properties" << endmsg;
}
return status;
}
unsigned long ToolSvc::minimumToolRefCount ( ) const
private

The minimum number of refCounts of all tools.

Definition at line 723 of file ToolSvc.cpp.

{
unsigned long count = 0;
if ( m_instancesTools.size() > 0 ) {
// start with first
count = refCountTool( *iTool );
// then compare the others
for( ++iTool; iTool != m_instancesTools.end(); ++iTool ) {
count = std::min( count, refCountTool( *iTool ) );
}
}
return count;
}
std::string ToolSvc::nameTool ( const std::string nameByUser,
const IInterface parent 
)

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

Definition at line 624 of file ToolSvc.cpp.

{
std::string fullname = "";
if ( parent == 0 ) { return this->name() + "." + toolname; } // RETURN
IInterface* cparent = const_cast<IInterface*>( parent ) ;
// check that parent has a name!
INamedInterface* _p = 0 ;
StatusCode sc = cparent->queryInterface( INamedInterface::interfaceID() , pp_cast<void>(&_p) ) ;
if ( sc.isSuccess() )
{
fullname = _p->name() + "." + toolname ;
_p->release() ;
return fullname ; // RETURN
}
<< "Private Tools only allowed for components implementing INamedInterface"
<< endmsg;
//
return "." + toolname ;
}
unsigned long ToolSvc::refCountTool ( IAlgTool tool) const
inline

Get current refcount for tool.

Definition at line 73 of file ToolSvc.h.

{ return tool->refCount(); }
void ToolSvc::registerObserver ( IToolSvc::Observer obs)
virtual

Implements IToolSvc.

Definition at line 739 of file ToolSvc.cpp.

{
if ( 0 == obs )
throw GaudiException( "Received NULL pointer", this->name() + "::registerObserver", StatusCode::FAILURE );
}
StatusCode ToolSvc::releaseTool ( IAlgTool tool)
virtual

Release tool.

Implements IToolSvc.

Definition at line 386 of file ToolSvc.cpp.

{
// test if tool is in known list (protect trying to access a previously deleted tool)
tool ) ) {
unsigned long count = refCountTool(tool);
if ( count == 1 ) {
// finalize the tool
// We are being called during ToolSvc::finalize()
// message format matches the one in ToolSvc::finalize()
log << MSG::DEBUG << " Performing finalization of " << tool->name()
<< " (refCount " << count << ")" << endmsg;
// message format matches the one in ToolSvc::finalize()
log << MSG::DEBUG << " Performing deletion of " << tool->name() << endmsg;
} else {
log << MSG::DEBUG << "Performing finalization and deletion of " << tool->name() << endmsg;
}
sc = finalizeTool(tool);
// remove from known tools...
}
tool->release();
}
return sc;
}
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.

{
// protect against empty type
if ( tooltype.empty() ) {
error() << "retrieve(): No Tool Type/Name given" << endmsg;
}
{
// check for tools, which by name is required to be public:
const std::string::size_type pos = tooltype.find ( s_PUBLIC ) ;
if ( std::string::npos != pos )
{
// set parent for PUBLIC tool
parent = this ;
return retrieve ( std::string( tooltype , 0 , pos ) ,
iid , tool , parent , createIf ) ;
}
}
const std::string::size_type pos = tooltype.find('/');
if( std::string::npos == pos ) {
return retrieve ( tooltype , tooltype , iid , tool , parent , createIf );
}
const std::string newtype ( tooltype , 0 , pos ) ;
const std::string newname ( tooltype , pos + 1 , std::string::npos ) ;
return retrieve ( newtype , newname , iid , tool , parent , createIf ) ;
}
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.

{
// check the applicability of another method:
// ignore the provided name if it is empty or the type contains a name
if( toolname.empty() || (std::string::npos != tooltype.find('/')) )
{ return retrieve ( tooltype , iid , tool , parent , createIf ) ; }
{
// check for tools, which by name is required to be public:
const std::string::size_type pos = toolname.find ( s_PUBLIC ) ;
if ( std::string::npos != pos )
{
// set parent for PUBLIC tool
parent = this ;
return retrieve ( tooltype , std::string( toolname , 0 , pos ) ,
iid , tool , parent , createIf ) ;
}
}
IAlgTool* itool = 0;
tool = 0;
// If parent is not specified it means it is the ToolSvc itself
if( 0 == parent ) {
parent = this;
}
const std::string fullname = nameTool( toolname, parent );
// Find tool in list of those already existing, and tell its
// interface that it has been used one more time
for( it = m_instancesTools.begin(); it != m_instancesTools.end(); ++it ) {
if( (*it)->name() == fullname ) {
ON_DEBUG debug() << "Retrieved tool " << toolname << endmsg;
itool = *it;
break;
}
}
if ( 0 == itool ) {
// Instances of this tool do not exist, create an instance if desired
// otherwise return failure
if( UNLIKELY(!createIf) ) {
warning() << "Tool " << toolname
<< " not found and creation not requested" << endmsg;
return sc;
}
else {
sc = create( tooltype, toolname, parent, itool );
if ( sc.isFailure() ) { return sc; }
}
}
// Get the right interface of it
sc = itool->queryInterface( iid, (void**)&tool);
if( UNLIKELY(sc.isFailure()) ) {
error() << "Tool " << toolname
<< " either does not implement the correct interface, or its version is incompatible"
<< endmsg;
return sc;
}
if (!m_observers.empty()) {
bl::_1,
itool));
}
return sc;
}
StatusCode ToolSvc::start ( )
virtual

Reimplemented from Service.

Definition at line 753 of file ToolSvc.cpp.

{
ON_DEBUG debug() << "START transition for AlgTools" << endmsg;
bool fail(false);
iTool != m_instancesTools.end(); ++iTool ) {
ON_VERBOSE verbose() << (*iTool)->name() << "::start()" << endmsg;
if (UNLIKELY(!(*iTool)->sysStart().isSuccess())) {
fail = true;
error() << (*iTool)->name() << " failed to start()" << endmsg;
}
}
if (UNLIKELY(fail)) {
error() << "One or more AlgTools failed to start()" << endmsg;
} else {
}
}
StatusCode ToolSvc::stop ( )
virtual

Reimplemented from Service.

Definition at line 782 of file ToolSvc.cpp.

{
ON_DEBUG debug() << "STOP transition for AlgTools" << endmsg;
bool fail(false);
iTool != m_instancesTools.end(); ++iTool ) {
ON_VERBOSE verbose() << (*iTool)->name() << "::stop()" << endmsg;
if (UNLIKELY(!(*iTool)->sysStop().isSuccess())) {
fail = true;
error() << (*iTool)->name() << " failed to stop()" << endmsg;
}
}
if (UNLIKELY(fail)) {
error() << "One or more AlgTools failed to stop()" << endmsg;
} else {
}
}
unsigned long ToolSvc::totalToolRefCount ( ) const
private

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

Definition at line 717 of file ToolSvc.cpp.

unsigned long ToolSvc::totalToolRefCount ( const ListTools toolList) const
private

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

Definition at line 705 of file ToolSvc.cpp.

{
unsigned long count = 0;
for ( ListTools::const_iterator iTool = toolList.begin();
iTool != toolList.end(); ++iTool ) {
count += refCountTool( *iTool );
}
return count;
}
void ToolSvc::unRegisterObserver ( IToolSvc::Observer obs)
virtual

Member Data Documentation

ListTools ToolSvc::m_instancesTools
private

Common Tools.

Definition at line 105 of file ToolSvc.h.

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

Definition at line 110 of file ToolSvc.h.

IHistorySvc* ToolSvc::m_pHistorySvc
private

Pointer to HistorySvc.

Definition at line 108 of file ToolSvc.h.


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

Generated at Mon Feb 17 2014 14:38:13 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004