ToolSvc.cpp
Go to the documentation of this file.
1 // Include Files
2 #include "GaudiKernel/MsgStream.h"
3 #include "GaudiKernel/Service.h"
4 #include "GaudiKernel/ISvcLocator.h"
5 #include "GaudiKernel/IAlgorithm.h"
6 #include "GaudiKernel/GaudiException.h"
7 #include "GaudiKernel/AlgTool.h"
8 #include "GaudiKernel/IHistorySvc.h"
9 #include "ToolSvc.h"
10 #include <algorithm>
11 #include <map>
12 #include <string>
13 #include <cassert>
14 #include <functional>
15 #include "boost/circular_buffer.hpp"
16 #include "boost/algorithm/string/predicate.hpp"
17 #include "boost/algorithm/string/erase.hpp"
18 namespace ba = boost::algorithm;
19 
20 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
21 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
22 
23 namespace {
24 //------------------------------------------------------------------------------
25 template <typename C>
26 unsigned long totalRefCount( const C& toolList )
27 //------------------------------------------------------------------------------
28 {
29  return std::accumulate( std::begin(toolList), std::end(toolList), 0ul,
30  [&](unsigned long count, const IAlgTool* tool ) {
31  return count + tool->refCount();
32  });
33 }
34 
36 template <typename C> void remove(C& c, typename C::const_reference i) {
37  c.erase( std::remove(std::begin(c),std::end(c),i), std::end(c) );
38 }
39 
40 }
41 
42 // Instantiation of a static factory class used by clients to create
43 // instances of this service
45 
46 //------------------------------------------------------------------------------
47 ToolSvc::ToolSvc( const std::string& name, ISvcLocator* svc )
48  //------------------------------------------------------------------------------
49  : base_class( name, svc) { }
50 
51 //------------------------------------------------------------------------------
53  //------------------------------------------------------------------------------
54 {
55 
56  // initialize the Service Base class
58  if (UNLIKELY(status.isFailure()))
59  {
60  error() << "Unable to initialize the Service" << endmsg;
61  return status;
62  }
63 
64  // set my own (ToolSvc) properties via the jobOptionService
65  if (UNLIKELY(setProperties().isFailure())) {
66  error() << "Unable to set base properties" << endmsg;
67  return StatusCode::FAILURE;
68  }
69 
70  return status;
71 }
72 
73 //------------------------------------------------------------------------------
75  //------------------------------------------------------------------------------
76 {
77  // Finalize and delete all left-over tools. Normally all tools created with
78  // ToolSvc are left over, since ToolSvc holds a refCount (via AlgTool ctor).
79  // Several cases need to be covered:
80  // 1) Simple dependencies: no circular dependencies between tools,
81  // and tools not using other tools
82  // 2) Tools-using-tools (but no circular dependencies)
83  // a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm)
84  // b) release() is called in the tool destructor (e.g. via ToolHandle)
85  // 3) Circular dependencies between tools
86  // a) release() is called in the tool::finalize() (e.g. via GaudiAlgorithm)
87  // b) release() is called in the tool destructor (e.g. via ToolHandle)
88  // 4) In addition to each of the above cases, refCounting of a particular tool
89  // might not have been done correctly in the code. Typically release()
90  // is not called, so we are left with a too high refCount.
91  // What to do with those, and how to avoid a crash while handling them...
92 
101  info() << "Removing all tools created by ToolSvc" << endmsg;
102 
103  // Print out list of tools
104  ON_DEBUG {
105  MsgStream &log = debug();
106  log << " Tool List : ";
107  for ( const auto& iTool : m_instancesTools ) {
108  log << iTool->name() << ":" << iTool->refCount( ) << " ";
109  }
110  log << endmsg;
111  }
112 
113  //
114  // first pass: Finalize all tools (but don't delete them)
115  //
128  boost::circular_buffer<IAlgTool*> finalizedTools(m_instancesTools.size()); // list of tools that have been finalized
129  bool fail(false);
130  size_t toolCount = m_instancesTools.size();
131  unsigned long startRefCount = 0;
132  unsigned long endRefCount = totalToolRefCount();
133  unsigned long startMinRefCount = 0;
134  unsigned long endMinRefCount = minimumToolRefCount();
135  while ( toolCount > 0 &&
136  endRefCount > 0 &&
137  (endRefCount != startRefCount || endMinRefCount != startMinRefCount) ) {
138  ON_DEBUG if ( endMinRefCount != startMinRefCount ) {
139  debug() << toolCount << " tools left to finalize. Summed refCounts: "
140  << endRefCount << endmsg;
141  debug() << "Will finalize tools with refCount <= "
142  << endMinRefCount << endmsg;
143  }
144  startMinRefCount = endMinRefCount;
145  startRefCount = endRefCount;
146  unsigned long maxLoop = toolCount + 1;
147  while ( --maxLoop > 0 && !m_instancesTools.empty() ) {
148  IAlgTool* pTool = m_instancesTools.back();
149  // removing tool from list makes ToolSvc::releaseTool( IAlgTool* ) a noop
150  m_instancesTools.pop_back();
151  unsigned long count = pTool->refCount( );
152  // cache tool name
153  const std::string& toolName = pTool->name();
154  if ( count <= startMinRefCount ) {
155  ON_DEBUG debug() << " Performing finalization of " << toolName
156  << " (refCount " << count << ")" << endmsg;
157  // finalize of one tool may trigger a release of another tool
158  // pTool->sysFinalize().ignore();
159  if (!finalizeTool(pTool).isSuccess()) {
160  warning() << " FAILURE finalizing " << toolName << endmsg;
161  fail = true;
162  }
163  // postpone deletion
164  finalizedTools.push_back(pTool);
165  } else {
166  // Place back at the front of the list to try again later
167  // ToolSvc::releaseTool( IAlgTool* ) remains active for this tool
168  ON_DEBUG debug() << " Delaying finalization of " << toolName
169  << " (refCount " << count << ")" << endmsg;
170  m_instancesTools.insert( std::begin(m_instancesTools), pTool );
171  }
172  } // end of inner loop
173  toolCount = m_instancesTools.size();
174  endRefCount = totalToolRefCount();
175  endMinRefCount = minimumToolRefCount();
176  }; // end of outer loop
177 
178  //
179  // Second pass: Delete all finalized tools
180  //
181  // Delete in the order of increasing number of refCounts.
182  // Loop over tools in the same order as the order in which they were finalized.
183  // All tools in the list of finalized tools are no longer in the instancesTools list.
184  // If a tool destructor calls releaseTool() on another tool, this will have no
185  // effect on the 'other tool' if this 'other tool' is in the list of finalized tools.
186  // If this 'other tool' is still in the instancesTools list, it may trigger finalization
187  // (in releaseTool()), deletion and removal from the instancesTools list.
188  // Therefore, the check on non-finalised tools should happen *after* the deletion
189  // of the finalized tools.
190  ON_DEBUG debug() << "Deleting " << finalizedTools.size() << " finalized tools" << endmsg;
191  auto maxLoop = totalRefCount( finalizedTools ) + 1;
192  while ( --maxLoop > 0 && !finalizedTools.empty() ) {
193  IAlgTool* pTool = finalizedTools.front();
194  finalizedTools.pop_front();
195  auto count = pTool->refCount( );
196  if ( count == 1 ) {
197  ON_DEBUG debug() << " Performing deletion of " << pTool->name() << endmsg;
198  } else {
199  ON_VERBOSE verbose() << " Delaying deletion of " << pTool->name()
200  << " (refCount " << count << ")" << endmsg;
201  // Move to the end when refCount still not zero
202  finalizedTools.push_back(pTool);
203  }
204  // do a forced release
205  pTool->release();
206  }
207 
208  // Error if by now not all tools are properly finalised
209  if ( !m_instancesTools.empty() ) {
210  error() << "Unable to finalize and delete the following tools : ";
211  for ( const auto& iTool : m_instancesTools ) {
212  error() << iTool->name() << ": " << iTool->refCount( ) << " ";
213  }
214  error() << endmsg;
215  }
216 
217  // by now, all tools should be deleted and removed.
218  if ( !finalizedTools.empty() ) {
219  error() << "Failed to delete the following " << finalizedTools.size()
220  << " finalized tools. Bug in ToolSvc::finalize()?: ";
221  for ( const auto& iTool : finalizedTools ) {
222  error() << iTool->name() << ": " << iTool->refCount( ) << " ";
223  }
224  error() << endmsg;
225  }
226 
227  if ( m_pHistorySvc ) m_pHistorySvc->release();
228 
229  // Finalize this specific service
230  return ( Service::finalize().isSuccess() && !fail ) ?
233 
234 }
235 
236 // ===================================================================================
240 // ===================================================================================
241 namespace
242 {
243  static const std::string s_PUBLIC = ":PUBLIC" ;
244 }
245 
246 //------------------------------------------------------------------------------
247 StatusCode ToolSvc::retrieve ( const std::string& tooltype ,
248  const InterfaceID& iid ,
249  IAlgTool*& tool ,
250  const IInterface* parent ,
251  bool createIf )
252 //------------------------------------------------------------------------------
253 {
254  // check for tools, which by name are required to be public:
255  if ( ba::ends_with( tooltype, s_PUBLIC ) ) {
256  // parent for PUBLIC tool is 'this', i.e. ToolSvc
257  return retrieve ( ba::erase_tail_copy(tooltype, s_PUBLIC.size()),
258  iid , tool , this , createIf ) ;
259  }
260 
261  // protect against empty type
262  if ( tooltype.empty() ) {
263  error() << "retrieve(): No Tool Type/Name given" << endmsg;
264  return StatusCode::FAILURE;
265  }
266  auto pos = tooltype.find('/');
267  if ( std::string::npos == pos ) {
268  return retrieve ( tooltype , tooltype , iid , tool , parent , createIf );
269  }
270  return retrieve ( tooltype.substr( 0 , pos ),
271  tooltype.substr( pos + 1 ),
272  iid , tool , parent , createIf ) ;
273 }
274 
275 // ===================================================================================
276 
277 //------------------------------------------------------------------------------
278 StatusCode ToolSvc::retrieve ( const std::string& tooltype ,
279  const std::string& toolname ,
280  const InterfaceID& iid ,
281  IAlgTool*& tool ,
282  const IInterface* parent ,
283  bool createIf )
284  //------------------------------------------------------------------------------
285 {
286  // check the applicability of another method:
287  // ignore the provided name if it is empty or the type contains a name
288  if( toolname.empty() || (std::string::npos != tooltype.find('/')) )
289  { return retrieve ( tooltype , iid , tool , parent , createIf ) ; }
290 
291  // check for tools, which by name are required to be public:
292  if ( ba::ends_with( toolname, s_PUBLIC ) )
293  {
294  // parent for PUBLIC tool is this, i.e. ToolSvc
295  return retrieve ( tooltype , ba::erase_tail_copy(toolname, s_PUBLIC.size() ),
296  iid , tool , this , createIf ) ;
297  }
298 
299  IAlgTool* itool = nullptr;
301 
302  tool = nullptr;
303 
304  // If parent is not specified it means it is the ToolSvc itself
305  if( !parent ) parent = this;
306  const std::string fullname = nameTool( toolname, parent );
307 
308  // Find tool in list of those already existing, and tell its
309  // interface that it has been used one more time
310  auto it = std::find_if( std::begin(m_instancesTools), std::end(m_instancesTools),
311  [&](const IAlgTool* i) { return i->name() == fullname; } );
312  if (it!=std::end(m_instancesTools)) {
313  ON_DEBUG debug() << "Retrieved tool " << toolname << endmsg;
314  itool = *it;
315  }
316 
317  if ( !itool ) {
318  // Instances of this tool do not exist, create an instance if desired
319  // otherwise return failure
320  if( UNLIKELY(!createIf) ) {
321  warning() << "Tool " << toolname
322  << " not found and creation not requested" << endmsg;
323  return sc;
324  }
325  sc = create( tooltype, toolname, parent, itool );
326  if ( sc.isFailure() ) { return sc; }
327  }
328 
329  // Get the right interface of it
330  sc = itool->queryInterface( iid, pp_cast<void>(&tool) );
331  if( UNLIKELY(sc.isFailure()) ) {
332  error() << "Tool " << toolname
333  << " either does not implement the correct interface, or its version is incompatible"
334  << endmsg;
335  return sc;
336  }
340  std::for_each( std::begin(m_observers),
342  [&]( IToolSvc::Observer* obs ) { obs->onRetrieve(itool); } );
343  return sc;
344 }
345 //------------------------------------------------------------------------------
346 std::vector<std::string> ToolSvc::getInstances( const std::string& toolType )
347 //------------------------------------------------------------------------------
348 {
349 
350  std::vector<std::string> tools;
351  for(const auto& tool: m_instancesTools) {
352  if (tool->type() == toolType) tools.push_back( tool->name() );
353  }
354  return tools;
355 
356 }
357 //------------------------------------------------------------------------------
358 std::vector<std::string> ToolSvc::getInstances() const
359 //------------------------------------------------------------------------------
360 {
361  std::vector<std::string> tools{m_instancesTools.size()};
363  std::begin(tools), std::mem_fn(&IAlgTool::name) );
364  return tools;
365 }
366 //------------------------------------------------------------------------------
367 std::vector<IAlgTool*> ToolSvc::getTools() const
368 //------------------------------------------------------------------------------
369 {
370  return m_instancesTools;
371 }
372 //------------------------------------------------------------------------------
374  //------------------------------------------------------------------------------
375 {
377  // test if tool is in known list (protect trying to access a previously deleted tool)
378  if ( m_instancesTools.rend() != std::find( m_instancesTools.rbegin(),
379  m_instancesTools.rend(),
380  tool ) ) {
381  unsigned long count = tool->refCount();
382  if ( count == 1 ) {
383  MsgStream log( msgSvc(), name() );
384  // finalize the tool
385 
386  if ( Gaudi::StateMachine::OFFLINE == m_targetState ) {
387  // We are being called during ToolSvc::finalize()
388  // message format matches the one in ToolSvc::finalize()
389  log << MSG::DEBUG << " Performing finalization of " << tool->name()
390  << " (refCount " << count << ")" << endmsg;
391  // message format matches the one in ToolSvc::finalize()
392  log << MSG::DEBUG << " Performing deletion of " << tool->name() << endmsg;
393  } else {
394  log << MSG::DEBUG << "Performing finalization and deletion of " << tool->name() << endmsg;
395  }
396  sc = finalizeTool(tool);
397  // remove from known tools...
398  remove(m_instancesTools,tool);
399  }
400  tool->release();
401  }
402  return sc;
403 }
404 
405 //------------------------------------------------------------------------------
406 StatusCode ToolSvc::create(const std::string& tooltype,
407  const IInterface* parent,
408  IAlgTool*& tool)
409  //------------------------------------------------------------------------------
410 {
411  const std::string & toolname = tooltype;
412  return create( tooltype, toolname, parent, tool);
413 }
414 
415 namespace {
418 template <typename T>
419 class ToolCreateGuard {
421  T& m_tools;
423  std::unique_ptr<IAlgTool> m_tool;
424 
425 public:
426  ToolCreateGuard(T& tools): m_tools(tools) {}
427  // we don't get a move constructor by default because we
428  // have a non-trivial destructor... However, the default
429  // one is just fine...
430  ToolCreateGuard(ToolCreateGuard&&) = default;
432  void create( const std::string& tooltype, const std::string& fullname, const IInterface* parent ) {
433  // remove previous content
434  if (m_tool) remove(m_tools,m_tool.get());
435  m_tool.reset(AlgTool::Factory::create(tooltype, tooltype, fullname, parent)) ;
436  // set new content
437  if (m_tool) m_tools.push_back(m_tool.get());
438  }
440  IAlgTool* get() {
441  return m_tool.get();
442  }
443  IAlgTool* operator->() const {
444  assert(m_tool);
445  return m_tool.get();
446  }
448  IAlgTool* release() {
449  return m_tool.release();
450  }
452  ~ToolCreateGuard(){
453  if (m_tool) remove(m_tools,m_tool.get());
454  }
455 };
456 
457 template <typename C>
458 ToolCreateGuard<C> make_toolCreateGuard(C& c) {
459  return ToolCreateGuard<C>{ c };
460 }
461 }
462 //------------------------------------------------------------------------------
463 StatusCode ToolSvc::create(const std::string& tooltype,
464  const std::string& toolname,
465  const IInterface* parent,
466  IAlgTool*& tool)
467  //------------------------------------------------------------------------------
468 {
469  // protect against empty type
470  if ( UNLIKELY(tooltype.empty()) ) {
471  error() << "create(): No Tool Type given" << endmsg;
472  return StatusCode::FAILURE;
473  }
474 
475  // If parent has not been specified, assume it is the ToolSvc
476  if ( !parent ) parent = this;
477 
478  tool = nullptr;
479  // Automatically deletes the tool if not explicitly kept (i.e. on success).
480  // The tool is removed from the list of known tools too.
481  auto toolguard = make_toolCreateGuard(m_instancesTools);
482 
483  // Check if the tool already exist : this should never happen
484  std::string fullname = nameTool(toolname, parent);
485  if( UNLIKELY(existsTool(fullname)) ) {
486  error() << "Tool " << fullname << " already exists" << endmsg;
487  return StatusCode::FAILURE;
488  }
489  // instantiate the tool using the factory
490  try {
491  toolguard.create( tooltype, fullname, parent );
492  if ( UNLIKELY(! toolguard.get()) ){
493  error() << "Cannot create tool " << tooltype << " (No factory found)" << endmsg;
494  return StatusCode::FAILURE;
495  }
496  }
497  catch ( const GaudiException& Exception ) {
498  // (1) perform the printout of message
499  fatal() << "Exception with tag=" << Exception.tag()
500  << " is caught whilst instantiating tool '" << tooltype << "'" << endmsg;
501  // (2) print the exception itself
502  // (NB! - GaudiException is a linked list of all "previous exceptions")
503  fatal() << Exception << endmsg;
504  return StatusCode::FAILURE;
505  }
506  catch( const std::exception& Exception ) {
507  // (1) perform the printout of message
508  fatal() << "Standard std::exception is caught whilst instantiating tool '"
509  << tooltype << "'" << endmsg;
510  // (2) print the exception itself
511  // (NB! - GaudiException is a linked list of all "previous exceptions")
512  fatal() << Exception.what() << endmsg;
513  return StatusCode::FAILURE;
514  }
515  catch(...) {
516  // (1) perform the printout
517  fatal() << "UNKNOWN Exception is caught whilst instantiating tool '"
518  << tooltype << "'" << endmsg;
519  return StatusCode::FAILURE;
520  }
521  ON_VERBOSE verbose() << "Created tool " << tooltype << "/" << fullname << endmsg;
522 
523  // Since only AlgTool has the setProperties() method it is necessary to cast
524  // to downcast IAlgTool to AlgTool in order to set the properties via the JobOptions
525  // service
526  AlgTool* mytool = dynamic_cast<AlgTool*> (toolguard.get());
527  if ( mytool ) {
528  StatusCode sc = mytool->setProperties();
529  if ( UNLIKELY(sc.isFailure()) ) {
530  error() << "Error setting properties for tool '"
531  << fullname << "'" << endmsg;
532  return sc;
533  }
534  }
535 
536  // Initialize the Tool
538  try {
539  sc = toolguard->sysInitialize();
540  }
541  // Catch any exceptions
542  catch ( const GaudiException & Exception )
543  {
544  error()
545  << "GaudiException with tag=" << Exception.tag()
546  << " caught whilst initializing tool '" << fullname << "'" << endmsg
547  << Exception << endmsg;
548  return StatusCode::FAILURE;
549  }
550  catch( const std::exception & Exception )
551  {
552  error()
553  << "Standard std::exception caught whilst initializing tool '"
554  << fullname << "'" << endmsg << Exception.what() << endmsg;
555  return StatusCode::FAILURE;
556  }
557  catch (...)
558  {
559  error()
560  << "UNKNOWN Exception caught whilst initializing tool '"
561  << fullname << "'" << endmsg;
562  return StatusCode::FAILURE;
563  }
564 
565  // Status of tool initialization
566  if ( UNLIKELY(sc.isFailure()) ) {
567  error() << "Error initializing tool '" << fullname << "'" << endmsg;
568  return sc;
569  }
570 
571  // Start the tool if we are running.
572  if (m_state == Gaudi::StateMachine::RUNNING) {
573  sc = toolguard->sysStart();
574 
575  if (UNLIKELY(sc.isFailure())) {
576  error() << "Error starting tool '" << fullname << "'" << endmsg;
577  return sc;
578  }
579  }
580 
581 
582  // The tool has been successfully created and initialized,
583  // so we inform the guard that it can release it
584  tool = toolguard.release();
585 
589  std::for_each( m_observers.begin(),
590  m_observers.end(),
591  [&](IToolSvc::Observer* obs) { obs->onCreate(tool); } );
592  // TODO: replace by generic callback
593  // Register the tool with the HistorySvc
594  if (m_pHistorySvc || service("HistorySvc",m_pHistorySvc,false).isSuccess() ) {
596  }
597  return StatusCode::SUCCESS;
598 
599 }
600 
601 //------------------------------------------------------------------------------
602 std::string ToolSvc::nameTool( const std::string& toolname,
603  const IInterface* parent )
604  //------------------------------------------------------------------------------
605 {
606 
607  if ( !parent ) { return this->name() + "." + toolname; } // RETURN
608 
609  // check that parent has a name!
610  auto named_parent = SmartIF<INamedInterface>( const_cast<IInterface*>(parent) );
611  if ( named_parent )
612  {
613  auto fullname = named_parent->name() + "." + toolname ;
614  return fullname ; // RETURN
615  }
616 
617  MsgStream log ( msgSvc(), name() );
618  log << MSG::ERROR
619  << "Private Tools only allowed for components implementing INamedInterface"
620  << endmsg;
621  //
622  return "." + toolname ;
623 }
624 
625 //------------------------------------------------------------------------------
626 bool ToolSvc::existsTool( const std::string& fullname) const
627  //------------------------------------------------------------------------------
628 {
629  auto i = std::find_if( std::begin(m_instancesTools), std::end(m_instancesTools),
630  [&](const IAlgTool* tool) { return tool->name() == fullname; } );
631  return i != std::end(m_instancesTools);
632 }
633 
634 //------------------------------------------------------------------------------
636  //------------------------------------------------------------------------------
637 {
638 
639  // Cache tool name in case of errors
640  const std::string toolName = itool->name();
641  StatusCode sc;
642 
643  // Finalise the tool inside a try block
644  try {
645  sc = itool->sysFinalize();
646  }
647  // Catch any exceptions
648  catch ( const GaudiException & Exception )
649  {
650  error()
651  << "GaudiException with tag=" << Exception.tag()
652  << " caught whilst finalizing tool '" << toolName << "'" << endmsg
653  << Exception << endmsg;
654  sc = StatusCode::FAILURE;
655  }
656  catch( const std::exception & Exception )
657  {
658  error()
659  << "Standard std::exception caught whilst finalizing tool '"
660  << toolName << "'" << endmsg << Exception.what() << endmsg;
661  sc = StatusCode::FAILURE;
662  }
663  catch (...)
664  {
665  error()
666  << "UNKNOWN Exception caught whilst finalizing tool '"
667  << toolName << "'" << endmsg;
668  sc = StatusCode::FAILURE;
669  }
670 
671  return sc;
672 
673 }
674 
675 //------------------------------------------------------------------------------
676 unsigned long ToolSvc::totalToolRefCount() const
677 //------------------------------------------------------------------------------
678 {
679  return totalRefCount( m_instancesTools );
680 }
681 //------------------------------------------------------------------------------
682 unsigned long ToolSvc::minimumToolRefCount() const
683 //------------------------------------------------------------------------------
684 {
685  auto i = std::min_element( std::begin(m_instancesTools), std::end(m_instancesTools),
686  [](const IAlgTool* lhs, const IAlgTool* rhs) {
687  return lhs->refCount() < rhs->refCount();
688  } );
689  return i!=std::end(m_instancesTools) ? (*i)->refCount() : 0;
690 }
691 
693  if ( !obs )
694  throw GaudiException( "Received NULL pointer", this->name() + "::registerObserver", StatusCode::FAILURE );
695  m_observers.push_back(obs);
696 }
697 
699  auto i = std::find(m_observers.begin(),m_observers.end(),obs);
700  if (i!=m_observers.end()) m_observers.erase(i);
701 }
702 
703 //------------------------------------------------------------------------------
706 //------------------------------------------------------------------------------
707 {
708 
709  ON_DEBUG debug() << "START transition for AlgTools" << endmsg;
710 
711  bool fail(false);
712  for ( auto& iTool : m_instancesTools ) {
713  ON_VERBOSE verbose() << iTool->name() << "::start()" << endmsg;
714 
715  if (UNLIKELY(!iTool->sysStart().isSuccess())) {
716  fail = true;
717  error() << iTool->name() << " failed to start()" << endmsg;
718  }
719 
720  }
721 
722  if (UNLIKELY(fail)) {
723  error() << "One or more AlgTools failed to start()" << endmsg;
724  return StatusCode::FAILURE;
725  } else {
726  return StatusCode::SUCCESS;
727  }
728 
729 }
730 
731 //------------------------------------------------------------------------------
734 //------------------------------------------------------------------------------
735 {
736 
737  ON_DEBUG debug() << "STOP transition for AlgTools" << endmsg;
738 
739  bool fail(false);
740  for ( auto& iTool : m_instancesTools ) {
741  ON_VERBOSE verbose() << iTool->name() << "::stop()" << endmsg;
742 
743  if (UNLIKELY(!iTool->sysStop().isSuccess())) {
744  fail = true;
745  error() << iTool->name() << " failed to stop()" << endmsg;
746  }
747 
748  }
749 
750  if (UNLIKELY(fail)) {
751  error() << "One or more AlgTools failed to stop()" << endmsg;
752  return StatusCode::FAILURE;
753  } else {
754  return StatusCode::SUCCESS;
755  }
756 
757 }
IHistorySvc * m_pHistorySvc
Pointer to HistorySvc.
Definition: ToolSvc.h:104
std::vector< std::string > getInstances() const override
Get names of all tool instances.
Definition: ToolSvc.cpp:358
tuple c
Definition: gaudirun.py:392
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode initialize() override
Definition: Service.cpp:62
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
StatusCode releaseTool(IAlgTool *tool) override
Release tool.
Definition: ToolSvc.cpp:373
void unRegisterObserver(IToolSvc::Observer *obs) override
Definition: ToolSvc.cpp:698
def remove(file, logdir)
Definition: install.py:153
StatusCode finalize() override
Definition: Service.cpp:187
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::string nameTool(const std::string &nameByUser, const IInterface *parent)
Get Tool full name by combining nameByUser and "parent" part.
Definition: ToolSvc.cpp:602
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:240
auto begin(reverse_wrapper< T > &w)
Definition: reverse.h:45
unsigned long minimumToolRefCount() const
The minimum number of refCounts of all tools.
Definition: ToolSvc.cpp:682
StatusCode create(const std::string &type, const IInterface *parent, IAlgTool *&tool)
Create Tool standard way with automatically assigned name.
Definition: ToolSvc.cpp:406
STL namespace.
void registerObserver(IToolSvc::Observer *obs) override
Definition: ToolSvc.cpp:692
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:106
bool existsTool(const std::string &toolname) const
Check if the tool instance exists.
Definition: ToolSvc.cpp:626
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
StatusCode initialize() override
Initialize the service.
Definition: ToolSvc.cpp:52
This service manages tools.
Definition: ToolSvc.h:22
StatusCode setProperties()
Method for setting declared properties to the values specified in the jobOptions via the job option s...
Definition: AlgTool.cpp:162
StatusCode start() override
Definition: ToolSvc.cpp:705
Interface ID class.
Definition: IInterface.h:30
unsigned long totalToolRefCount() const
The total number of refCounts on all tools in the instancesTools list.
Definition: ToolSvc.cpp:676
StatusCode finalizeTool(IAlgTool *itool) const
Finalize the given tool, with exception handling.
Definition: ToolSvc.cpp:635
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
auto end(reverse_wrapper< T > &w)
Definition: reverse.h:47
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode registerAlgTool(const IAlgTool &)=0
Definition of the basic interface.
Definition: IInterface.h:234
std::vector< IAlgTool * > getTools() const override
Get pointers to all tool instances.
Definition: ToolSvc.cpp:367
virtual const std::string & tag() const
name tag for the exception, or exception type
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:101
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:244
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:34
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:22
#define ON_DEBUG
Definition: ToolSvc.cpp:20
StatusCode finalize() override
Finalize the service.
Definition: ToolSvc.cpp:74
#define UNLIKELY(x)
Definition: Kernel.h:126
void ignore() const
Definition: StatusCode.h:108
list i
Definition: ana.py:128
StatusCode stop() override
Definition: ToolSvc.cpp:733
#define ON_VERBOSE
Definition: ToolSvc.cpp:21
tuple toolname
Definition: gaudirun.py:328
StatusCode retrieve(const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf) override
Retrieve tool, create it by default as common tool if it does not already exist.
Definition: ToolSvc.cpp:247