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