12 #include <tracking/trackFindingCDC/findlets/base/Findlet.h>
14 #include <tracking/trackFindingCDC/utilities/Relation.h>
15 #include <tracking/trackFindingCDC/utilities/Range.h>
17 #include <framework/logging/Logger.h>
27 class ModuleParamList;
28 namespace TrackFindingCDC {
52 template <
class AStateRejecter,
class AState,
class AResult = std::vector<const AState*> >
53 class TreeTraversal :
public Findlet<const AState* const, const Relation<AState>, AResult> {
56 using Super = Findlet<const AState* const, const Relation<AState>, AResult>;
77 void apply(
const std::vector<const AState*>& seededStates,
79 std::vector<AResult>& results)
override;
85 std::vector<AResult>& results);
92 template <
class AStateRejecter,
class AState,
class AResult>
94 const std::vector<const AState*>& seededStates,
95 const std::vector<Relation<AState>>& stateRelations,
96 std::vector<AResult>& results)
98 B2ASSERT(
"Expected relation to be sorted",
99 std::is_sorted(stateRelations.begin(), stateRelations.end()));
101 std::vector<const AState*> path;
102 for (
const AState* state : seededStates) {
103 B2DEBUG(50,
"Starting with new seed...");
104 path.push_back(state);
105 traverseTree(path, stateRelations, results);
107 B2DEBUG(50,
"... finished with seed");
109 assert(path.empty());
112 template <
class AStateRejecter,
class AState,
class AResult>
114 std::vector<const AState*>& path,
115 const std::vector<Relation<AState>>& stateRelations,
116 std::vector<AResult>& results)
120 const AState* currentState = path.back();
122 std::equal_range(stateRelations.begin(), stateRelations.end(), currentState);
124 std::vector<AState*> childStates;
126 AState* childState = continuation.getTo();
127 childStates.push_back(childState);
132 const std::vector<const AState*>& constPath = path;
133 m_stateRejecter.apply(constPath, childStates);
135 if (childStates.empty()) {
136 B2DEBUG(50,
"Terminating this route, as there are no possible child states.");
137 results.emplace_back(path);
142 B2DEBUG(50,
"Having found " << childStates.size() <<
" child states.");
143 for (
const AState* childState : childStates) {
144 if (std::count(path.begin(), path.end(), childState)) {
149 path.push_back(childState);
150 traverseTree(path, stateRelations, results);