10 #include <tracking/ckf/general/findlets/TreeSearcher.dcl.h>
12 #include <framework/logging/Logger.h>
14 #include <tracking/trackFindingCDC/utilities/Range.h>
15 #include <tracking/trackFindingCDC/utilities/Algorithms.h>
16 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
18 #include <framework/core/ModuleParamList.templateDetails.h>
25 template <
class AState,
class AStateRejecter,
class AResult>
31 template <
class AState,
class AStateRejecter,
class AResult>
34 m_stateRejecter.exposeParameters(moduleParamList, prefix);
36 moduleParamList->
addParameter(TrackFindingCDC::prefixed(prefix,
"endEarly"), m_param_endEarly,
37 "Make it possible to have all subresults in the end result vector.",
41 template <
class AState,
class AStateRejecter,
class AResult>
43 std::vector<AState>& hitStates,
45 std::vector<AResult>& results)
47 B2ASSERT(
"Expected relation to be sorted",
48 std::is_sorted(relations.begin(), relations.end()));
51 const std::vector<AState*>& statePointers = TrackFindingCDC::as_pointers<AState>(hitStates);
52 m_automaton.applyTo(statePointers, relations);
54 std::vector<TrackFindingCDC::WithWeight<const AState*>> path;
55 for (
const AState& state : seededStates) {
56 B2DEBUG(29,
"Starting with new seed...");
58 path.emplace_back(&state, 0);
59 traverseTree(path, relations, results);
61 B2ASSERT(
"Something went wrong during the path traversal", path.empty());
63 B2DEBUG(29,
"... finished with seed");
67 template <
class AState,
class AStateRejecter,
class AResult>
70 std::vector<AResult>& results)
72 if (m_param_endEarly) {
74 results.emplace_back(path);
79 const AState* currentState = path.back();
81 TrackFindingCDC::asRange(std::equal_range(relations.begin(), relations.end(), currentState));
83 std::vector<TrackFindingCDC::WithWeight<AState*>> childStates;
85 AState* childState = continuation.getTo();
86 TrackFindingCDC::Weight weight = continuation.getWeight();
89 if (std::count(path.begin(), path.end(), childState)) {
92 B2FATAL(
"Cycle detected!");
96 childStates.emplace_back(childState, weight);
101 const std::vector<TrackFindingCDC::WithWeight<const AState*>>& constPath = path;
102 m_stateRejecter.apply(constPath, childStates);
104 if (childStates.empty()) {
105 B2DEBUG(29,
"Terminating this route, as there are no possible child states.");
106 if (not m_param_endEarly) {
107 results.emplace_back(path);
113 const auto stateLess = [](
const auto & lhs,
const auto & rhs) {
114 return lhs->getAutomatonCell().getCellState() < rhs->getAutomatonCell().getCellState();
116 std::sort(childStates.begin(), childStates.end(), stateLess);
118 B2DEBUG(29,
"Having found " << childStates.size() <<
" child states.");
120 path.emplace_back(childState, childState.getWeight());
121 traverseTree(path, relations, results);
The Module parameter list class.
void addProcessingSignalListener(ProcessingSignalListener *psl)
Register a processing signal listener to be notified.
Type for two related objects with a weight.
A mixin class to attach a weight to an object.
AStateRejecter m_stateRejecter
State rejecter to decide which available continuations should be traversed next.
void addParameter(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module list.
void apply(const std::vector< AState > &seededStates, std::vector< AState > &hitStates, const std::vector< TrackFindingCDC::WeightedRelation< AState >> &relations, std::vector< AResult > &results) final
Main function of this findlet: traverse a tree starting from a given seed states.
void exposeParameters(ModuleParamList *moduleParamList, const std::string &prefix) final
Expose the parameters of the subfindlet.
TreeSearcher()
Construct this findlet and add the subfindlet as listener.
void traverseTree(std::vector< TrackFindingCDC::WithWeight< const AState * >> &path, const std::vector< TrackFindingCDC::WeightedRelation< AState >> &relations, std::vector< AResult > &results)
Implementation of the traverseTree function.
Abstract base class for different kinds of events.