19 #pragma warning(disable:177)
21 #include "boost/lambda/bind.hpp"
23 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
24 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
30 using
ROOT::Reflex::PluginService;
31 namespace bl = boost::lambda;
56 error() <<
"Unable to initialize the Service" <<
endmsg;
62 error() <<
"Unable to set base properties" <<
endmsg;
98 info() <<
"Removing all tools created by ToolSvc" <<
endmsg;
103 log <<
" Tool List : ";
106 log << (*iTool)->name() <<
":" <<
refCountTool( *iTool ) <<
" ";
128 unsigned long startRefCount = 0;
130 unsigned long startMinRefCount = 0;
132 while ( toolCount > 0 &&
134 (endRefCount != startRefCount || endMinRefCount != startMinRefCount) ) {
135 ON_DEBUG if ( endMinRefCount != startMinRefCount ) {
136 debug() << toolCount <<
" tools left to finalize. Summed refCounts: "
138 debug() <<
"Will finalize tools with refCount <= "
139 << endMinRefCount <<
endmsg;
141 startMinRefCount = endMinRefCount;
142 startRefCount = endRefCount;
143 unsigned long maxLoop = toolCount + 1;
151 if ( count <= startMinRefCount ) {
152 ON_DEBUG debug() <<
" Performing finalization of " << toolName
153 <<
" (refCount " << count <<
")" <<
endmsg;
166 <<
" (refCount " << count <<
")" <<
endmsg;
189 while ( --maxLoop > 0 && finalizedTools.
size() > 0 ) {
197 <<
" (refCount " << count <<
")" <<
endmsg;
207 error() <<
"Unable to finalize and delete the following tools : ";
216 if ( finalizedTools.
size() > 0 ) {
217 error() <<
"Failed to delete the following " << finalizedTools.
size()
218 <<
" finalized tools. Bug in ToolSvc::finalize()?: ";
220 iTool != finalizedTools.
end(); ++iTool ) {
260 if ( tooltype.empty() ) {
261 error() <<
"retrieve(): No Tool Type/Name given" <<
endmsg;
268 if ( std::string::npos != pos )
273 iid , tool , parent , createIf ) ;
278 if( std::string::npos == pos ) {
279 return retrieve ( tooltype , tooltype , iid , tool , parent , createIf );
282 const std::string newname ( tooltype , pos + 1 , std::string::npos ) ;
283 return retrieve ( newtype , newname , iid , tool , parent , createIf ) ;
299 if( toolname.empty() || (std::string::npos != tooltype.find(
'/')) )
300 {
return retrieve ( tooltype , iid , tool , parent , createIf ) ; }
305 if ( std::string::npos != pos )
310 iid , tool , parent , createIf ) ;
329 if( (*it)->name() == fullname ) {
340 warning() <<
"Tool " << toolname
341 <<
" not found and creation not requested" <<
endmsg;
345 sc =
create( tooltype, toolname, parent, itool );
353 error() <<
"Tool " << toolname
354 <<
" either does not implement the correct interface, or its version is incompatible"
380 if ((*it)->type() == toolType) {
405 log <<
MSG::DEBUG <<
" Performing finalization of " << tool->
name()
406 <<
" (refCount " << count <<
")" <<
endmsg;
429 return create( tooltype, toolname, parent, tool);
435 class ToolCreateGuard {
444 m_list.remove(m_tool);
449 m_list.push_back(m_tool);
452 ToolCreateGuard& operator=(
IAlgTool* tool) {
490 error() <<
"create(): No Tool Type given" <<
endmsg;
495 if ( 0 == parent ) parent =
this;
505 error() <<
"Tool " << fullname <<
" already exists" <<
endmsg;
510 toolguard = PluginService::Create<IAlgTool*>(tooltype, tooltype, fullname, parent);
512 error() <<
"Cannot create tool " << tooltype <<
" (No factory found)" <<
endmsg;
518 fatal() <<
"Exception with tag=" << Exception.
tag()
519 <<
" is caught whilst instantiating tool '" << tooltype <<
"'" <<
endmsg;
527 fatal() <<
"Standard std::exception is caught whilst instantiating tool '"
528 << tooltype <<
"'" <<
endmsg;
536 fatal() <<
"UNKNOWN Exception is caught whilst instantiating tool '"
537 << tooltype <<
"'" <<
endmsg;
549 error() <<
"Error setting properties for tool '"
550 << fullname <<
"'" <<
endmsg;
558 sc = toolguard->sysInitialize();
564 <<
"GaudiException with tag=" << Exception.
tag()
565 <<
" caught whilst initializing tool '" << fullname <<
"'" << endmsg
572 <<
"Standard std::exception caught whilst initializing tool '"
573 << fullname <<
"'" << endmsg << Exception.
what() <<
endmsg;
579 <<
"UNKNOWN Exception caught whilst initializing tool '"
580 << fullname <<
"'" <<
endmsg;
586 error() <<
"Error initializing tool '" << fullname <<
"'" <<
endmsg;
592 sc = toolguard->sysStart();
595 error() <<
"Error starting tool '" << fullname <<
"'" <<
endmsg;
603 tool = toolguard.release();
633 if ( parent == 0 ) {
return this->
name() +
"." + toolname; }
642 fullname = _p->
name() +
"." + toolname ;
649 <<
"Private Tools only allowed for components implementing INamedInterface"
652 return "." + toolname ;
660 it != m_instancesTools.end(); ++it ) {
661 if ( (*it)->name() == fullname ) {
return true; }
677 sc = itool->sysFinalize();
683 <<
"GaudiException with tag=" << Exception.
tag()
684 <<
" caught whilst finalizing tool '" << toolName <<
"'" <<
endmsg
691 <<
"Standard std::exception caught whilst finalizing tool '"
698 <<
"UNKNOWN Exception caught whilst finalizing tool '"
699 << toolName <<
"'" <<
endmsg;
711 unsigned long count = 0;
713 iTool != toolList.end(); ++iTool ) {
714 count += refCountTool( *iTool );
729 unsigned long count = 0;
767 if (
UNLIKELY(!(*iTool)->sysStart().isSuccess())) {
769 error() << (*iTool)->name() <<
" failed to start()" <<
endmsg;
775 error() <<
"One or more AlgTools failed to start()" <<
endmsg;
796 if (
UNLIKELY(!(*iTool)->sysStop().isSuccess())) {
798 error() << (*iTool)->name() <<
" failed to stop()" <<
endmsg;
804 error() <<
"One or more AlgTools failed to stop()" <<
endmsg;