10 #include "boost/algorithm/string/erase.hpp"    11 #include "boost/algorithm/string/predicate.hpp"    12 #include "boost/circular_buffer.hpp"    19 namespace ba = boost::algorithm;
    21 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )    22 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )    28   unsigned long totalRefCount( 
const C& toolList )
    32                             [&]( 
unsigned long count, 
const IAlgTool* tool ) { 
return count + tool->
refCount(); } );
    37   void remove( C& 
c, 
typename C::const_reference i )
    68     error() << 
"Unable to initialize the Service" << 
endmsg;
    74     error() << 
"Unable to set base properties" << 
endmsg;
   109   info() << 
"Removing all tools created by ToolSvc" << 
endmsg;
   115     log << 
"  Tool List : ";
   117       log << iTool->name() << 
":" << iTool->refCount() << 
" ";
   140   unsigned long                     startRefCount    = 0;
   142   unsigned long                     startMinRefCount = 0;
   144   while ( toolCount > 0 && endRefCount > 0 && ( endRefCount != startRefCount || endMinRefCount != startMinRefCount ) ) {
   145     ON_DEBUG if ( endMinRefCount != startMinRefCount )
   147       debug() << toolCount << 
" tools left to finalize. Summed refCounts: " << endRefCount << 
endmsg;
   148       debug() << 
"Will finalize tools with refCount <= " << endMinRefCount << 
endmsg;
   150     startMinRefCount      = endMinRefCount;
   151     startRefCount         = endRefCount;
   152     unsigned long maxLoop = toolCount + 1;
   157       unsigned long count = pTool->
refCount();
   160       if ( count <= startMinRefCount ) {
   161         ON_DEBUG debug() << 
"  Performing finalization of " << toolName << 
" (refCount " << count << 
")" << 
endmsg;
   169         finalizedTools.push_back( pTool );
   173         ON_DEBUG debug() << 
"  Delaying   finalization of " << toolName << 
" (refCount " << count << 
")" << 
endmsg;
   195   auto     maxLoop = totalRefCount( finalizedTools ) + 1;
   196   while ( --maxLoop > 0 && !finalizedTools.empty() ) {
   197     IAlgTool* pTool = finalizedTools.front();
   198     finalizedTools.pop_front();
   205       finalizedTools.push_back( pTool );
   213     error() << 
"Unable to finalize and delete the following tools : ";
   215       error() << iTool->name() << 
": " << iTool->refCount() << 
" ";
   221   if ( !finalizedTools.empty() ) {
   222     error() << 
"Failed to delete the following " << finalizedTools.size()
   223             << 
" finalized tools. Bug in ToolSvc::finalize()?: ";
   224     for ( 
const auto& iTool : finalizedTools ) {
   225       error() << iTool->name() << 
": " << iTool->refCount() << 
" ";
   252   if ( ba::ends_with( tooltype, s_PUBLIC ) ) {
   254     return retrieve( ba::erase_tail_copy( tooltype, s_PUBLIC.
size() ), iid, tool, 
this, createIf );
   258   if ( tooltype.
empty() ) {
   259     error() << 
"retrieve(): No Tool Type/Name given" << 
endmsg;
   262   auto pos = tooltype.
find( 
'/' );
   263   if ( std::string::npos == pos ) {
   264     return retrieve( tooltype, tooltype, iid, tool, parent, createIf );
   266   return retrieve( tooltype.
substr( 0, pos ), tooltype.
substr( pos + 1 ), iid, tool, parent, createIf );
   278   if ( toolname.
empty() || ( std::string::npos != tooltype.
find( 
'/' ) ) ) {
   279     return retrieve( tooltype, iid, tool, parent, createIf );
   283   if ( ba::ends_with( toolname, s_PUBLIC ) ) {
   285     return retrieve( tooltype, ba::erase_tail_copy( toolname, s_PUBLIC.
size() ), iid, tool, 
this, createIf );
   296   if ( !parent ) parent      = 
this;
   302                           [&]( 
const IAlgTool* i ) { 
return i->
name() == fullname && i->
parent() == parent; } );
   312       warning() << 
"Tool " << toolname << 
" not found and creation not requested" << 
endmsg;
   315     sc = 
create( tooltype, toolname, parent, itool );
   324     error() << 
"Tool " << toolname << 
" either does not implement the correct interface, or its version is incompatible"   344     if ( tool->type() == toolType ) tools.
push_back( tool->name() );
   373     unsigned long count = tool->
refCount();
   380         debug() << 
"  Performing finalization of " << tool->
name() << 
" (refCount " << count << 
")" << 
endmsg;
   384         debug() << 
"Performing finalization and deletion of " << tool->
name() << 
endmsg;
   400   return create( tooltype, toolname, parent, tool );
   407   template <
typename T>
   408   class ToolCreateGuard
   416     explicit ToolCreateGuard( T& tools ) : m_tools( tools ) {}
   420     ToolCreateGuard( ToolCreateGuard&& ) noexcept = 
default;
   425       if ( m_tool ) 
remove( m_tools, m_tool.
get() );
   426       m_tool.
reset( AlgTool::Factory::create( tooltype, tooltype, fullname, parent ) );
   428       if ( m_tool ) m_tools.push_back( m_tool.
get() );
   442       if ( m_tool ) 
remove( m_tools, m_tool.
get() );
   446   template <
typename C>
   447   ToolCreateGuard<C> make_toolCreateGuard( C& 
c )
   449     return ToolCreateGuard<C>{c};
   469     error() << 
"create(): No Tool Type given" << 
endmsg;
   474   if ( !parent ) parent = 
this;
   489         error() << 
"Tool " << fullname << 
" already exists with the same parent" << 
endmsg;
   490         if ( parent == 
this )
   491           error() << 
"... In addition, the parent is the ToolSvc: public tools cannot be cloned!" << 
endmsg;
   500     toolguard.create( tooltype, fullname, parent );
   501     if ( 
UNLIKELY( !toolguard.get() ) ) {
   502       error() << 
"Cannot create tool " << tooltype << 
" (No factory found)" << 
endmsg;
   507     fatal() << 
"Exception with tag=" << Exception.
tag() << 
" is caught whilst instantiating tool '" << tooltype << 
"'"   515     fatal() << 
"Standard std::exception is caught whilst instantiating tool '" << tooltype << 
"'" << 
endmsg;
   522     fatal() << 
"UNKNOWN Exception is caught whilst instantiating tool '" << tooltype << 
"'" << 
endmsg;
   534       error() << 
"Error setting properties for tool '" << fullname << 
"'" << 
endmsg;
   542     sc = toolguard->sysInitialize();
   546     error() << 
"GaudiException with tag=" << Exception.
tag() << 
" caught whilst initializing tool '" << fullname << 
"'"   547             << endmsg << Exception << 
endmsg;
   550     error() << 
"Standard std::exception caught whilst initializing tool '" << fullname << 
"'" << endmsg
   554     error() << 
"UNKNOWN Exception caught whilst initializing tool '" << fullname << 
"'" << 
endmsg;
   560     error() << 
"Error initializing tool '" << fullname << 
"'" << 
endmsg;
   566     sc = toolguard->sysStart();
   569       error() << 
"Error starting tool '" << fullname << 
"'" << 
endmsg;
   601   if ( named_parent ) {
   602     auto fullname = named_parent->name() + 
"." + 
toolname;
   606   error() << 
"Private Tools only allowed for components implementing INamedInterface" << 
endmsg;
   617                          [&]( 
const IAlgTool* tool ) { 
return tool->
name() == fullname; } );
   632     sc = itool->sysFinalize();
   636     error() << 
"GaudiException with tag=" << Exception.
tag() << 
" caught whilst finalizing tool '" << toolName << 
"'"   640     error() << 
"Standard std::exception caught whilst finalizing tool '" << toolName << 
"'" << 
endmsg   644     error() << 
"UNKNOWN Exception caught whilst finalizing tool '" << toolName << 
"'" << 
endmsg;
   693     if ( 
UNLIKELY( !iTool->sysStart().isSuccess() ) ) {
   695       error() << iTool->name() << 
" failed to start()" << 
endmsg;
   700     error() << 
"One or more AlgTools failed to start()" << 
endmsg;
   717     if ( 
UNLIKELY( !iTool->sysStop().isSuccess() ) ) {
   719       error() << iTool->name() << 
" failed to stop()" << 
endmsg;
   724     error() << 
"One or more AlgTools failed to stop()" << 
endmsg;
 
Gaudi::StateMachine::State m_targetState
Service state. 
StatusCode initialize() override
Define general base for Gaudi exception. 
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
const std::string & name() const  override
Retrieve name of the service. 
Gaudi::StateMachine::State m_state
Service state. 
StatusCode finalize() override
MsgStream & info() const 
shortcut for the method msgStream(MSG::INFO) 
bool isSuccess() const 
Test for a status code of SUCCESS. 
MsgStream & verbose() const 
shortcut for the method msgStream(MSG::VERBOSE) 
bool isFailure() const 
Test for a status code of FAILURE. 
#define DECLARE_COMPONENT(type)
MsgStream & error() const 
shortcut for the method msgStream(MSG::ERROR) 
MsgStream & warning() const 
shortcut for the method msgStream(MSG::WARNING) 
This class is used for returning status codes from appropriate routines. 
virtual StatusCode registerAlgTool(const IAlgTool &)=0
Definition of the basic interface. 
virtual const std::string & tag() const 
name tag for the exception, or exception type 
StatusCode setProperties()
Method for setting declared properties to the values specified for the job. 
virtual unsigned long release()=0
Release Interface instance. 
MsgStream & debug() const 
shortcut for the method msgStream(MSG::DEBUG) 
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. 
virtual unsigned long refCount() const  =0
Current reference count. 
MsgStream & fatal() const 
shortcut for the method msgStream(MSG::FATAL) 
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream. 
virtual const std::string & name() const  =0
Retrieve the name of the instance. 
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.