Loading [MathJax]/jax/output/HTML-CSS/config.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ToolVisitor.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include <GaudiKernel/AlgTool.h>
13 
14 namespace {
15  void reverseAppend( const std::vector<IAlgTool*>& src, std::vector<IAlgTool*>& dest, const std::regex& reject_filter,
16  bool use_filter ) {
17  dest.reserve( dest.size() + src.size() );
18  std::copy_if( src.rbegin(), src.rend(), std::back_inserter( dest ), [&]( const auto& i ) {
19  return !use_filter || !std::regex_match( i->name(), reject_filter );
20  } ); // @TODO include type ?
21  }
22 } // namespace
23 
24 const std::regex ToolVisitor::s_noFilter{};
25 
26 void ToolVisitor::recursiveVisit( const std::vector<IAlgTool*>& tools, IVisitor const& visitor,
27  const std::regex& reject_filter ) {
28  bool use_filter = ( &reject_filter != &ToolVisitor::s_noFilter ) &&
29  ( !std::regex_match( "", reject_filter ) ); // @TODO remove empty string match-test ?
30  std::vector<IAlgTool*> stack;
31  // reverse tool lost to process tools in given order
32  reverseAppend( tools, stack, reject_filter, use_filter );
33 
34  // keep track of tools which have been visited to prevent infinite loops in case of circular tool dependencies.
35  std::set<IAlgTool*> visited;
36  while ( !stack.empty() ) {
37  auto* a_tool = stack.back();
38  stack.pop_back();
39  if ( a_tool ) {
40  if ( visited.insert( a_tool ).second ) {
41  visitor.visit( a_tool );
42  // also visit all child tools
43  if ( auto* tool_impl = dynamic_cast<AlgTool*>( a_tool ); tool_impl ) {
44  reverseAppend( tool_impl->tools(), stack, reject_filter, use_filter );
45  }
46  }
47  // @TODO warn about cicular tool dependencies ?
48  }
49  }
50 }
gaudirun.dest
dest
Definition: gaudirun.py:224
AlgTool
Definition: AlgTool.h:55
AlgTool.h
ToolVisitor.h