17 #pragma warning(disable:177)
19 #include "boost/lambda/bind.hpp"
21 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
22 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
28 namespace bl = boost::lambda;
53 error() <<
"Unable to initialize the Service" <<
endmsg;
59 error() <<
"Unable to set base properties" <<
endmsg;
95 info() <<
"Removing all tools created by ToolSvc" <<
endmsg;
100 log <<
" Tool List : ";
103 log << (*iTool)->name() <<
":" <<
refCountTool( *iTool ) <<
" ";
125 unsigned long startRefCount = 0;
127 unsigned long startMinRefCount = 0;
129 while ( toolCount > 0 &&
131 (endRefCount != startRefCount || endMinRefCount != startMinRefCount) ) {
132 ON_DEBUG if ( endMinRefCount != startMinRefCount ) {
133 debug() << toolCount <<
" tools left to finalize. Summed refCounts: "
135 debug() <<
"Will finalize tools with refCount <= "
136 << endMinRefCount <<
endmsg;
138 startMinRefCount = endMinRefCount;
139 startRefCount = endRefCount;
140 unsigned long maxLoop = toolCount + 1;
147 std::string toolName = pTool->
name();
148 if ( count <= startMinRefCount ) {
149 ON_DEBUG debug() <<
" Performing finalization of " << toolName
150 <<
" (refCount " << count <<
")" <<
endmsg;
158 finalizedTools.push_back(pTool);
163 <<
" (refCount " << count <<
")" <<
endmsg;
186 while ( --maxLoop > 0 && finalizedTools.size() > 0 ) {
187 IAlgTool* pTool = finalizedTools.front();
188 finalizedTools.pop_front();
194 <<
" (refCount " << count <<
")" <<
endmsg;
196 finalizedTools.push_back(pTool);
204 error() <<
"Unable to finalize and delete the following tools : ";
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 ) {
244 const std::string s_PUBLIC =
":PUBLIC" ;
257 if ( tooltype.empty() ) {
258 error() <<
"retrieve(): No Tool Type/Name given" <<
endmsg;
264 const std::string::size_type pos = tooltype.find ( s_PUBLIC ) ;
265 if ( std::string::npos != pos )
269 return retrieve ( std::string( tooltype , 0 , pos ) ,
270 iid , tool , parent , createIf ) ;
274 const std::string::size_type pos = tooltype.find(
'/');
275 if( std::string::npos == pos ) {
276 return retrieve ( tooltype , tooltype , iid , tool , parent , createIf );
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 ) ;
296 if( toolname.empty() || (std::string::npos != tooltype.find(
'/')) )
297 {
return retrieve ( tooltype , iid , tool , parent , createIf ) ; }
301 const std::string::size_type pos = toolname.find ( s_PUBLIC ) ;
302 if ( std::string::npos != pos )
306 return retrieve ( tooltype , std::string( toolname , 0 , pos ) ,
307 iid , tool , parent , createIf ) ;
320 const std::string fullname =
nameTool( toolname, parent );
324 ListTools::const_iterator it;
326 if( (*it)->name() == fullname ) {
337 warning() <<
"Tool " << toolname
338 <<
" not found and creation not requested" <<
endmsg;
342 sc =
create( tooltype, toolname, parent, itool );
350 error() <<
"Tool " << toolname
351 <<
" either does not implement the correct interface, or its version is incompatible"
373 std::vector<std::string> tools;
375 ListTools::const_iterator it;
377 if ((*it)->type() == toolType) {
378 tools.push_back( (*it)->name() );
402 log <<
MSG::DEBUG <<
" Performing finalization of " << tool->
name()
403 <<
" (refCount " << count <<
")" <<
endmsg;
425 const std::string &
toolname = tooltype;
426 return create( tooltype, toolname, parent, tool);
432 class ToolCreateGuard {
441 m_list.remove(m_tool);
446 m_list.push_back(m_tool);
449 ToolCreateGuard& operator=(
IAlgTool* tool) {
487 error() <<
"create(): No Tool Type given" <<
endmsg;
492 if ( 0 == parent ) parent =
this;
500 const std::string fullname =
nameTool(toolname, parent);
502 error() <<
"Tool " << fullname <<
" already exists" <<
endmsg;
507 toolguard = AlgTool::Factory::create(tooltype, tooltype, fullname, parent);
509 error() <<
"Cannot create tool " << tooltype <<
" (No factory found)" <<
endmsg;
515 fatal() <<
"Exception with tag=" << Exception.
tag()
516 <<
" is caught whilst instantiating tool '" << tooltype <<
"'" <<
endmsg;
522 catch(
const std::exception& Exception ) {
524 fatal() <<
"Standard std::exception is caught whilst instantiating tool '"
525 << tooltype <<
"'" <<
endmsg;
533 fatal() <<
"UNKNOWN Exception is caught whilst instantiating tool '"
534 << tooltype <<
"'" <<
endmsg;
546 error() <<
"Error setting properties for tool '"
547 << fullname <<
"'" <<
endmsg;
555 sc = toolguard->sysInitialize();
561 <<
"GaudiException with tag=" << Exception.
tag()
562 <<
" caught whilst initializing tool '" << fullname <<
"'" << endmsg
566 catch(
const std::exception & Exception )
569 <<
"Standard std::exception caught whilst initializing tool '"
570 << fullname <<
"'" << endmsg << Exception.what() <<
endmsg;
576 <<
"UNKNOWN Exception caught whilst initializing tool '"
577 << fullname <<
"'" <<
endmsg;
583 error() <<
"Error initializing tool '" << fullname <<
"'" <<
endmsg;
589 sc = toolguard->sysStart();
592 error() <<
"Error starting tool '" << fullname <<
"'" <<
endmsg;
600 tool = toolguard.release();
629 std::string fullname =
"";
630 if ( parent == 0 ) {
return this->
name() +
"." +
toolname; }
646 <<
"Private Tools only allowed for components implementing INamedInterface"
656 for ( ListTools::const_iterator it = m_instancesTools.begin();
657 it != m_instancesTools.end(); ++it ) {
658 if ( (*it)->name() == fullname ) {
return true; }
669 const std::string toolName = itool->name();
674 sc = itool->sysFinalize();
680 <<
"GaudiException with tag=" << Exception.
tag()
681 <<
" caught whilst finalizing tool '" << toolName <<
"'" <<
endmsg
685 catch(
const std::exception & Exception )
688 <<
"Standard std::exception caught whilst finalizing tool '"
689 << toolName <<
"'" <<
endmsg << Exception.what() <<
endmsg;
695 <<
"UNKNOWN Exception caught whilst finalizing tool '"
696 << toolName <<
"'" <<
endmsg;
708 unsigned long count = 0;
709 for ( ListTools::const_iterator iTool = toolList.begin();
710 iTool != toolList.end(); ++iTool ) {
711 count += refCountTool( *iTool );
726 unsigned long count = 0;
746 std::vector<IToolSvc::Observer*>::iterator
i =
764 if (
UNLIKELY(!(*iTool)->sysStart().isSuccess())) {
766 error() << (*iTool)->name() <<
" failed to start()" <<
endmsg;
772 error() <<
"One or more AlgTools failed to start()" <<
endmsg;
793 if (
UNLIKELY(!(*iTool)->sysStop().isSuccess())) {
795 error() << (*iTool)->name() <<
" failed to stop()" <<
endmsg;
801 error() <<
"One or more AlgTools failed to stop()" <<
endmsg;
Gaudi::StateMachine::State m_targetState
Service state.
Definition of the MsgStream class used to transmit messages.
MsgStream & verbose() const
shortcut for the method msgStream(MSG::VERBOSE)
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Gaudi::StateMachine::State m_state
Service state.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
bool isFailure() const
Test for a status code of FAILURE.
#define DECLARE_COMPONENT(type)
virtual const std::string & name() const =0
Retrieve the name of the instance.
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
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 const std::string & name() const
Retrieve name of the service.
IInterface compliant class extending IInterface with the name() method.
virtual unsigned long release()=0
Release Interface instance.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
Templated class to add the standard messaging functionalities.
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.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.