![]() |
|
|
Generated: 24 Nov 2008 |
#include <ToolSvc.h>


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.
Definition at line 23 of file ToolSvc.h.
Public Types | |
| typedef std::list< IAlgTool * > | ListTools |
Public Member Functions | |
| virtual StatusCode | initialize () |
| Initialize the service. | |
| virtual StatusCode | finalize () |
| Finalize the service. | |
| virtual StatusCode | queryInterface (const InterfaceID &riid, void **ppvInterface) |
| Query the interfaces. | |
| 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::string > | getInstances (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) |
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 |
| Finalise the given tool, with exception handling. | |
Private Attributes | |
| ListTools | m_instancesTools |
| Common Tools. | |
| IHistorySvc * | m_pHistorySvc |
| Pointer to HistorySvc. | |
| std::vector< IToolSvc::Observer * > | m_observers |
| typedef std::list<IAlgTool*> ToolSvc::ListTools |
| ToolSvc::ToolSvc | ( | const std::string & | name, | |
| ISvcLocator * | svc | |||
| ) |
Standard Constructor.
| name | String with service name | |
| svc | Pointer to service locator interface |
Definition at line 30 of file ToolSvc.cpp.
00032 : Service(name, svc), 00033 m_pHistorySvc(0) 00034 { }
| ToolSvc::~ToolSvc | ( | ) | [virtual] |
| StatusCode ToolSvc::initialize | ( | ) | [virtual] |
Initialize the service.
Reimplemented from Service.
Definition at line 44 of file ToolSvc.cpp.
00046 { 00047 00048 // initialize the Service Base class 00049 StatusCode status = Service::initialize(); 00050 if ( status.isFailure() ) 00051 { 00052 MsgStream log( msgSvc(), name() ); 00053 log << MSG::ERROR << "Unable to initialize the Service" << endreq; 00054 return status; 00055 } 00056 00057 // set my own (ToolSvc) properties via the jobOptionService 00058 if (setProperties().isFailure()) { 00059 MsgStream log( msgSvc(), name() ); 00060 log << MSG::ERROR << "Unable to set base properties" << endreq; 00061 return StatusCode::FAILURE; 00062 } 00063 00064 return status; 00065 }
| StatusCode ToolSvc::finalize | ( | void | ) | [virtual] |
Finalize the service.
Algorithm: 2 passes. First pass:
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 68 of file ToolSvc.cpp.
00070 { 00071 // Finalize and delete all left-over tools. Normally all tools created with 00072 // ToolSvc are left over, since ToolSvc holds a refCount (via AlgTool ctor). 00073 // Several cases need to be covered: 00074 // 1) Simple dependencies: no circular dependencies between tools, 00075 // and tools not using other tools 00076 // 2) Tools-using-tools (but no circular dependencies) 00077 // a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm) 00078 // b) release() is called in the tool destructor (e.g. via ToolHandle) 00079 // 3) Circular dependencies between tools 00080 // a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm) 00081 // b) release() is called in the tool destructor (e.g. via ToolHandle) 00082 // 4) In addition to each of the above cases, refCounting of a particular tool 00083 // might not have been done correctly in the code. Typically release() 00084 // is not called, so we are left with a too high refCount. 00085 // What to do with those, and how to avoid a crash while handling them... 00086 00095 MsgStream log( msgSvc(), name() ); 00096 ListTools finalizedTools; // list of tools that have been finalized 00097 log << MSG::INFO << "Removing all tools created by ToolSvc" << endreq; 00098 00099 // Print out list of tools 00100 log << MSG::DEBUG << " Tool List : "; 00101 for ( ListTools::const_iterator iTool = m_instancesTools.begin(); 00102 iTool != m_instancesTools.end(); ++iTool ) { 00103 log << (*iTool)->name() << ":" << refCountTool( *iTool ) << " "; 00104 } 00105 log << endreq; 00106 00107 // 00108 // first pass: Finalize all tools (but don't delete them) 00109 // 00122 bool fail(false); 00123 size_t toolCount = m_instancesTools.size(); 00124 unsigned long startRefCount = 0; 00125 unsigned long endRefCount = totalToolRefCount(); 00126 unsigned long startMinRefCount = 0; 00127 unsigned long endMinRefCount = minimumToolRefCount(); 00128 while ( toolCount > 0 && 00129 endRefCount > 0 && 00130 (endRefCount != startRefCount || endMinRefCount != startMinRefCount) ) { 00131 if ( endMinRefCount != startMinRefCount ) { 00132 log << MSG::DEBUG << toolCount << " tools left to finalize. Summed refCounts: " 00133 << endRefCount << endreq; 00134 log << MSG::DEBUG << "Will finalize tools with refCount <= " 00135 << endMinRefCount << endreq; 00136 } 00137 startMinRefCount = endMinRefCount; 00138 startRefCount = endRefCount; 00139 unsigned long maxLoop = toolCount + 1; 00140 while ( --maxLoop > 0 && m_instancesTools.size() > 0 ) { 00141 IAlgTool* pTool = m_instancesTools.back(); 00142 // removing tool from list makes ToolSvc::releaseTool( IAlgTool* ) a noop 00143 m_instancesTools.pop_back(); 00144 unsigned long count = refCountTool( pTool ); 00145 // cache tool name 00146 std::string toolName = pTool->name(); 00147 if ( count <= startMinRefCount ) { 00148 log << MSG::DEBUG << " Performing finalization of " << toolName 00149 << " (refCount " << count << ")" << endreq; 00150 // finalize of one tool may trigger a release of another tool 00151 // pTool->sysFinalize().ignore(); 00152 if (!finalizeTool(pTool).isSuccess()) fail = true; 00153 // postpone deletion 00154 finalizedTools.push_back(pTool); 00155 } else { 00156 // Place back in list to try again later 00157 // ToolSvc::releaseTool( IAlgTool* ) remains active for this tool 00158 log << MSG::DEBUG << " Delaying finalization of " << toolName 00159 << " (refCount " << count << ")" << endreq; 00160 m_instancesTools.push_front(pTool); 00161 } 00162 } // end of inner loop 00163 toolCount = m_instancesTools.size(); 00164 endRefCount = totalToolRefCount(); 00165 endMinRefCount = minimumToolRefCount(); 00166 }; // end of outer loop 00167 00168 // 00169 // Second pass: Delete all finalized tools 00170 // 00171 // Delete in the order of increasing number of refCounts. 00172 // Loop over tools in the same order as the order in which they were finalized. 00173 // All tools in the list of finalized tools are no longer in the instancesTools list. 00174 // If a tool destructor calls releaseTool() on another tool, this will have no 00175 // effect on the 'other tool' if this 'other tool' is in the list of finalized tools. 00176 // If this 'other tool' is still in the instancesTools list, it may trigger finalization 00177 // (in releaseTool()), deletion and removal from the instancesTools list. 00178 // Therefore, the check on non-finalised tools should happen *after* the deletion 00179 // of the finalized tools. 00180 log << MSG::DEBUG << "Deleting " << finalizedTools.size() << " finalized tools" << endreq; 00181 unsigned long maxLoop = totalToolRefCount( finalizedTools ) + 1; 00182 while ( --maxLoop > 0 && finalizedTools.size() > 0 ) { 00183 IAlgTool* pTool = finalizedTools.front(); 00184 finalizedTools.pop_front(); 00185 unsigned long count = refCountTool( pTool ); 00186 if ( count == 1 ) { 00187 log << MSG::DEBUG << " Performing deletion of " << pTool->name() << endreq; 00188 } else { 00189 log << MSG::VERBOSE << " Delaying deletion of " << pTool->name() 00190 << " (refCount " << count << ")" << endreq; 00191 // Put it back at the end of the list if refCount still not zero 00192 finalizedTools.push_back(pTool); 00193 } 00194 // do a forced release 00195 pTool->release(); 00196 } 00197 00198 // Error if by now not all tools are properly finalised 00199 if ( !m_instancesTools.empty() ) { 00200 log << MSG::ERROR << "Unable to finalize and delete the following tools : "; 00201 for ( ListTools::const_iterator iTool = m_instancesTools.begin(); 00202 iTool != m_instancesTools.end(); ++iTool ) { 00203 log << (*iTool)->name() << ": " << refCountTool( *iTool ) << " "; 00204 } 00205 log << endreq; 00206 } 00207 00208 // by now, all tools should be deleted and removed. 00209 if ( finalizedTools.size() > 0 ) { 00210 log << MSG::ERROR << "Failed to delete the following " << finalizedTools.size() 00211 << " finalized tools. Bug in ToolSvc::finalize()?: "; 00212 for ( ListTools::const_iterator iTool = finalizedTools.begin(); 00213 iTool != finalizedTools.end(); ++iTool ) { 00214 log << (*iTool)->name() << ": " << refCountTool( *iTool ) << " "; 00215 } 00216 log << endreq; 00217 } 00218 00219 if ( 0 != m_pHistorySvc ) { 00220 m_pHistorySvc->release(); 00221 } 00222 00223 // Finalize this specific service 00224 if (! Service::finalize().isSuccess() || fail) { 00225 return StatusCode::FAILURE; 00226 } else { 00227 return StatusCode::SUCCESS; 00228 } 00229 00230 00231 }
| StatusCode ToolSvc::queryInterface | ( | const InterfaceID & | riid, | |
| void ** | ppvInterface | |||
| ) | [virtual] |
Query the interfaces.
Reimplemented from Service.
Definition at line 234 of file ToolSvc.cpp.
00236 { 00237 if ( IID_IToolSvc == riid ) { 00238 *ppvInterface = (IToolSvc*)this; 00239 } 00240 else { 00241 // Interface is not directly available: try out a base class 00242 return Service::queryInterface(riid, ppvInterface); 00243 } 00244 addRef(); 00245 return StatusCode::SUCCESS; 00246 }
| 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 259 of file ToolSvc.cpp.
00265 { 00266 00267 // protect against empty type 00268 if ( tooltype.empty() ) { 00269 MsgStream log( msgSvc(), name() ); 00270 log << MSG::ERROR << "retrieve(): No Tool Type/Name given" << endreq; 00271 return StatusCode::FAILURE; 00272 } 00273 00274 { 00275 // check for tools, which by name is required to be public: 00276 const std::string::size_type pos = tooltype.find ( s_PUBLIC ) ; 00277 if ( std::string::npos != pos ) 00278 { 00279 // set parent for PUBLIC tool 00280 parent = this ; 00281 return retrieve ( std::string( tooltype , 0 , pos ) , 00282 iid , tool , parent , createIf ) ; 00283 } 00284 } 00285 00286 const std::string::size_type pos = tooltype.find('/'); 00287 if( std::string::npos == pos ) 00288 { return retrieve ( tooltype , tooltype , iid , tool , parent , createIf );} 00289 const std::string newtype ( tooltype , 0 , pos ) ; 00290 const std::string newname ( tooltype , pos + 1 , std::string::npos ) ; 00291 return retrieve ( newtype , newname , iid , tool , parent , createIf ) ; 00292 }
| 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 297 of file ToolSvc.cpp.
00304 { 00305 MsgStream log( msgSvc(), name() ); 00306 00307 // check the applicability of another method: 00308 // ignore the provided name if it is empty or the type contains a name 00309 if( toolname.empty() || (std::string::npos != tooltype.find('/')) ) 00310 { return retrieve ( tooltype , iid , tool , parent , createIf ) ; } 00311 00312 { 00313 // check for tools, which by name is required to be public: 00314 const std::string::size_type pos = toolname.find ( s_PUBLIC ) ; 00315 if ( std::string::npos != pos ) 00316 { 00317 // set parent for PUBLIC tool 00318 parent = this ; 00319 return retrieve ( tooltype , std::string( toolname , 0 , pos ) , 00320 iid , tool , parent , createIf ) ; 00321 } 00322 } 00323 00324 IAlgTool* itool = 0; 00325 StatusCode sc(StatusCode::FAILURE); 00326 00327 tool = 0; 00328 00329 // If parent is not specified it means it is the ToolSvc itself 00330 if( 0 == parent ) { 00331 parent = this; 00332 } 00333 const std::string fullname = nameTool( toolname, parent ); 00334 00335 // Find tool in list of those already existing, and tell its 00336 // interface that it has been used one more time 00337 ListTools::const_iterator it; 00338 for( it = m_instancesTools.begin(); it != m_instancesTools.end(); ++it ) { 00339 if( (*it)->name() == fullname ) { 00340 log << MSG::DEBUG << "Retrieved tool " << toolname << endreq; 00341 itool = *it; 00342 break; 00343 } 00344 } 00345 00346 if ( 0 == itool ) { 00347 // Instances of this tool do not exist, create an instance if desired 00348 // otherwise return failure 00349 if( !createIf ) { 00350 log << MSG::WARNING << "Tool " << toolname 00351 << " not found and creation not requested" << endreq; 00352 return sc; 00353 } 00354 else { 00355 sc = create( tooltype, toolname, parent, itool ); 00356 if ( sc.isFailure() ) { return sc; } 00357 } 00358 } 00359 00360 // Get the right interface of it 00361 sc = itool->queryInterface( iid, (void**)&tool); 00362 if( sc.isFailure() ) { 00363 log << MSG::ERROR << "Tool " << toolname 00364 << " either does not implement the correct interface, or its version is incompatible" 00365 << endreq; 00366 return sc; 00367 } 00371 if (!m_observers.empty()) { 00372 std::for_each( m_observers.begin(), 00373 m_observers.end(), 00374 bl::bind(&IToolSvc::Observer::onRetrieve, 00375 bl::_1, 00376 itool)); 00377 } 00378 00379 return sc; 00380 }
| 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 382 of file ToolSvc.cpp.
00384 { 00385 00386 std::vector<std::string> tools; 00387 00388 ListTools::const_iterator it; 00389 for (it = m_instancesTools.begin(); it != m_instancesTools.end(); ++it) { 00390 if ((*it)->type() == toolType) { 00391 tools.push_back( (*it)->name() ); 00392 } 00393 } 00394 00395 return tools; 00396 00397 }
| StatusCode ToolSvc::releaseTool | ( | IAlgTool * | tool | ) | [virtual] |
Release tool.
Implements IToolSvc.
Definition at line 399 of file ToolSvc.cpp.
00401 { 00402 StatusCode sc(StatusCode::SUCCESS); 00403 // test if tool is in known list (protect trying to access a previously deleted tool) 00404 if ( m_instancesTools.rend() != std::find( m_instancesTools.rbegin(), 00405 m_instancesTools.rend(), 00406 tool ) ) { 00407 unsigned long count = refCountTool(tool); 00408 if ( count == 1 ) { 00409 MsgStream log( msgSvc(), name() ); 00410 // finalize the tool 00411 00412 if ( Gaudi::StateMachine::OFFLINE == m_targetState ) { 00413 // We are being called during ToolSvc::finalize() 00414 // message format matches the one in ToolSvc::finalize() 00415 log << MSG::DEBUG << " Performing finalization of " << tool->name() 00416 << " (refCount " << count << ")" << endreq; 00417 // message format matches the one in ToolSvc::finalize() 00418 log << MSG::DEBUG << " Performing deletion of " << tool->name() << endreq; 00419 } else { 00420 log << MSG::DEBUG << "Performing finalization and deletion of " << tool->name() << endreq; 00421 } 00422 sc = finalizeTool(tool); 00423 // remove from known tools... 00424 m_instancesTools.remove(tool); 00425 } 00426 tool->release(); 00427 } 00428 00429 return sc; 00430 }
| StatusCode ToolSvc::create | ( | const std::string & | type, | |
| const IInterface * | parent, | |||
| IAlgTool *& | tool | |||
| ) |
Create Tool standard way with automatically assigned name.
Definition at line 433 of file ToolSvc.cpp.
00437 { 00438 const std::string & toolname = tooltype; 00439 return create( tooltype, toolname, parent, tool); 00440 }
| 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 496 of file ToolSvc.cpp.
00501 { 00502 MsgStream log( msgSvc(), name() ); 00503 // protect against empty type 00504 if ( tooltype.empty() ) { 00505 log << MSG::ERROR << "create(): No Tool Type given" << endreq; 00506 return StatusCode::FAILURE; 00507 } 00508 00509 // If parent has not been specified, assume it is the ToolSvc 00510 if ( 0 == parent ) parent = this; 00511 00512 tool = 0; 00513 // Automatically deletes the tool if not explicitly kept (i.e. on success). 00514 // The tool is removed from the list of known tools too. 00515 ToolCreateGuard toolguard(m_instancesTools); 00516 00517 // Check if the tool already exist : this should never happen 00518 const std::string fullname = nameTool(toolname, parent); 00519 if( existsTool( fullname ) ) { 00520 log << MSG::ERROR << "Tool " << fullname << " already exists" << endreq; 00521 return StatusCode::FAILURE; 00522 } 00523 // instantiate the tool using the factory 00524 try { 00525 toolguard = PluginService::Create<IAlgTool*>(tooltype, tooltype, fullname, parent); 00526 if ( ! toolguard.get() ){ 00527 log << MSG::ERROR 00528 << "Cannot create tool " << tooltype << " (No factory found)" << endreq; 00529 return StatusCode::FAILURE; 00530 } 00531 } 00532 catch ( const GaudiException& Exception ) { 00533 // (1) perform the printout of message 00534 MsgStream log ( msgSvc() , name() ); 00535 log << MSG::FATAL << "Exception with tag=" << Exception.tag() 00536 << " is caught whilst instantiating tool '" << tooltype << "'" << endreq; 00537 // (2) print the exception itself 00538 // (NB! - GaudiException is a linked list of all "previous exceptions") 00539 log << MSG::FATAL << Exception << endreq; 00540 return StatusCode::FAILURE; 00541 } 00542 catch( const std::exception& Exception ) { 00543 // (1) perform the printout of message 00544 MsgStream log ( msgSvc() , name() ); 00545 log << MSG::FATAL 00546 << "Standard std::exception is caught whilst instantiating tool '" 00547 << tooltype << "'" << endreq; 00548 // (2) print the exception itself 00549 // (NB! - GaudiException is a linked list of all "previous exceptions") 00550 log << MSG::FATAL << Exception.what() << endreq; 00551 return StatusCode::FAILURE; 00552 } 00553 catch(...) { 00554 // (1) perform the printout 00555 MsgStream log ( msgSvc() , name() ); 00556 log << MSG::FATAL << "UNKNOWN Exception is caught whilst instantiating tool '" 00557 << tooltype << "'" << endreq; 00558 return StatusCode::FAILURE; 00559 } 00560 log << MSG::VERBOSE << "Created tool " << tooltype << "/" << fullname << endreq; 00561 00562 // Since only AlgTool has the setProperties() method it is necessary to cast 00563 // to downcast IAlgTool to AlgTool in order to set the properties via the JobOptions 00564 // service 00565 AlgTool* mytool = dynamic_cast<AlgTool*> (toolguard.get()); 00566 if ( mytool != 0 ) { 00567 StatusCode sc = mytool->setProperties(); 00568 if ( sc.isFailure() ) { 00569 MsgStream log ( msgSvc() , name() ); 00570 log << MSG::ERROR << "Error setting properties for tool '" 00571 << fullname << "'" << endreq; 00572 return sc; 00573 } 00574 } 00575 00576 // Initialize the Tool 00577 StatusCode sc (StatusCode::FAILURE,true); 00578 try { sc = toolguard->sysInitialize(); } 00579 00580 // Catch any exceptions 00581 catch ( const GaudiException & Exception ) 00582 { 00583 MsgStream msg ( msgSvc(), name() ); 00584 msg << MSG::ERROR 00585 << "GaudiException with tag=" << Exception.tag() 00586 << " caught whilst initializing tool '" << fullname << "'" << endreq 00587 << Exception << endreq; 00588 return StatusCode::FAILURE; 00589 } 00590 catch( const std::exception & Exception ) 00591 { 00592 MsgStream msg ( msgSvc(), name() ); 00593 msg << MSG::ERROR 00594 << "Standard std::exception caught whilst initializing tool '" 00595 << fullname << "'" << endreq << Exception.what() << endreq; 00596 return StatusCode::FAILURE; 00597 } 00598 catch (...) 00599 { 00600 MsgStream msg ( msgSvc(), name() ); 00601 msg << MSG::ERROR 00602 << "UNKNOWN Exception caught whilst initializing tool '" 00603 << fullname << "'" << endreq; 00604 return StatusCode::FAILURE; 00605 } 00606 00607 // Status of tool intialization 00608 if ( sc.isFailure() ) { 00609 MsgStream log( msgSvc(), name() ); 00610 log << MSG::ERROR << "Error initializing tool '" << fullname << "'" << endreq; 00611 return sc; 00612 } 00613 00614 // The tool has been successfully created and initialized, 00615 // so we the guard can be released 00616 tool = toolguard.release(); 00617 00621 if (!m_observers.empty()) { 00622 std::for_each( m_observers.begin(), 00623 m_observers.end(), 00624 bl::bind(&IToolSvc::Observer::onCreate, 00625 bl::_1, 00626 tool)); 00627 } 00628 // TODO: replace by generic callback 00629 // Register the tool with the HistorySvc 00630 if (m_pHistorySvc != 0 || 00631 service("HistorySvc",m_pHistorySvc,false).isSuccess() ) { 00632 m_pHistorySvc->registerAlgTool(*tool).ignore(); 00633 } 00634 00635 return StatusCode::SUCCESS; 00636 00637 }
| bool ToolSvc::existsTool | ( | const std::string & | toolname | ) | const |
Check if the tool instance exists.
Definition at line 669 of file ToolSvc.cpp.
00671 { 00672 for ( ListTools::const_iterator it = m_instancesTools.begin(); 00673 it != m_instancesTools.end(); ++it ) { 00674 if ( (*it)->name() == fullname ) { return true; } 00675 } 00676 return false; 00677 }
| 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.
00643 { 00644 00645 std::string fullname = ""; 00646 if ( parent == 0 ) { return this->name() + "." + toolname; } // RETURN 00647 00648 00649 IInterface* cparent = const_cast<IInterface*>( parent ) ; 00650 // check that parent has a name! 00651 INamedInterface* _p = 0 ; 00652 StatusCode sc = cparent->queryInterface( INamedInterface::interfaceID() , pp_cast<void>(&_p) ) ; 00653 if ( sc.isSuccess() ) 00654 { 00655 fullname = _p->name() + "." + toolname ; 00656 _p->release() ; 00657 return fullname ; // RETURN 00658 } 00659 00660 MsgStream log ( msgSvc(), name() ); 00661 log << MSG::ERROR 00662 << "Private Tools only allowed for INamedInterfaces" 00663 << endreq; 00664 // 00665 return "." + toolname ; 00666 }
| unsigned long ToolSvc::refCountTool | ( | IAlgTool * | tool | ) | const [inline] |
| void ToolSvc::registerObserver | ( | IToolSvc::Observer * | obs | ) | [virtual] |
Implements IToolSvc.
Definition at line 757 of file ToolSvc.cpp.
00757 { 00758 if ( 0 == obs ) 00759 throw GaudiException( "Received NULL pointer", this->name() + "::registerObserver", StatusCode::FAILURE ); 00760 m_observers.push_back(obs); 00761 }
| void ToolSvc::unRegisterObserver | ( | IToolSvc::Observer * | obs | ) | [virtual] |
Implements IToolSvc.
Definition at line 763 of file ToolSvc.cpp.
00763 { 00764 std::vector<IToolSvc::Observer*>::iterator i = 00765 find(m_observers.begin(),m_observers.end(),obs); 00766 if (i!=m_observers.end()) m_observers.erase(i); 00767 }
| unsigned long ToolSvc::totalToolRefCount | ( | ) | const [private] |
The total number of refCounts on all tools in the instancesTools list.
Definition at line 735 of file ToolSvc.cpp.
00737 { 00738 return totalToolRefCount( m_instancesTools ); 00739 }
| unsigned long ToolSvc::totalToolRefCount | ( | const ListTools & | toolList | ) | const [private] |
The total number of refCounts on all tools in the list.
Definition at line 723 of file ToolSvc.cpp.
00725 { 00726 unsigned long count = 0; 00727 for ( ListTools::const_iterator iTool = toolList.begin(); 00728 iTool != toolList.end(); ++iTool ) { 00729 count += refCountTool( *iTool ); 00730 } 00731 return count; 00732 }
| unsigned long ToolSvc::minimumToolRefCount | ( | ) | const [private] |
The minimum number of refCounts of all tools.
Definition at line 741 of file ToolSvc.cpp.
00743 { 00744 unsigned long count = 0; 00745 if ( m_instancesTools.size() > 0 ) { 00746 ListTools::const_iterator iTool = m_instancesTools.begin(); 00747 // start with first 00748 count = refCountTool( *iTool ); 00749 // then compare the others 00750 for( ++iTool; iTool != m_instancesTools.end(); ++iTool ) { 00751 count = std::min( count, refCountTool( *iTool ) ); 00752 } 00753 } 00754 return count; 00755 }
| StatusCode ToolSvc::finalizeTool | ( | IAlgTool * | itool | ) | const [private] |
Finalise the given tool, with exception handling.
Definition at line 680 of file ToolSvc.cpp.
00682 { 00683 00684 // Cache tool name in case of errors 00685 const std::string toolName = itool->name(); 00686 StatusCode sc; 00687 00688 // Finalise the tool inside a try block 00689 try { sc = itool->sysFinalize(); } 00690 00691 // Catch any exceptions 00692 catch ( const GaudiException & Exception ) 00693 { 00694 MsgStream msg ( msgSvc(), name() ); 00695 msg << MSG::ERROR 00696 << "GaudiException with tag=" << Exception.tag() 00697 << " caught whilst finalizing tool '" << toolName << "'" << endreq 00698 << Exception << endreq; 00699 sc = StatusCode::FAILURE; 00700 } 00701 catch( const std::exception & Exception ) 00702 { 00703 MsgStream msg ( msgSvc(), name() ); 00704 msg << MSG::ERROR 00705 << "Standard std::exception caught whilst finalizing tool '" 00706 << toolName << "'" << endreq << Exception.what() << endreq; 00707 sc = StatusCode::FAILURE; 00708 } 00709 catch (...) 00710 { 00711 MsgStream msg ( msgSvc(), name() ); 00712 msg << MSG::ERROR 00713 << "UNKNOWN Exception caught whilst finalizing tool '" 00714 << toolName << "'" << endreq; 00715 sc = StatusCode::FAILURE; 00716 } 00717 00718 return sc; 00719 00720 }
ListTools ToolSvc::m_instancesTools [private] |
IHistorySvc* ToolSvc::m_pHistorySvc [private] |
std::vector<IToolSvc::Observer*> ToolSvc::m_observers [private] |