The Gaudi Framework
master (9cc87df9)
Toggle main menu visibility
Loading...
Searching...
No Matches
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
>
12
#include <
GaudiKernel/ToolVisitor.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
}
AlgTool.h
ToolVisitor.h
std::copy_if
constexpr _OutputIterator copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred)
std::regex
basic_regex< char > regex
std::regex_match
bool regex_match(_Bi_iter __s, _Bi_iter __e, match_results< _Bi_iter, _Alloc > &__m, const basic_regex< _Ch_type, _Rx_traits > &__re, regex_constants::match_flag_type __flags=regex_constants::match_default)
std::back_inserter
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
std::set
std::set::insert
void insert(_InputIterator __first, _InputIterator __last)
std::vector
std::vector::rend
constexpr const_reverse_iterator rend() const noexcept
std::vector::pop_back
constexpr void pop_back() noexcept
std::vector::back
constexpr const_reference back() const noexcept
std::vector::empty
constexpr bool empty() const noexcept
std::vector::rbegin
constexpr const_reverse_iterator rbegin() const noexcept
std::vector::size
constexpr size_type size() const noexcept
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition
AlgTool.h:55
gaudirun.dest
dest
Definition
gaudirun.py:224
GaudiKernel
src
Lib
ToolVisitor.cpp
Generated on
for The Gaudi Framework by
1.18.0