12 #include <tracking/trackFindingCDC/ca/CellularAutomaton.h>
13 #include <tracking/trackFindingCDC/ca/CellularPathFollower.h>
15 #include <tracking/trackFindingCDC/ca/Path.h>
16 #include <tracking/trackFindingCDC/ca/CellHolder.h>
18 #include <tracking/trackFindingCDC/utilities/StringManipulation.h>
20 #include <framework/core/ModuleParamList.h>
21 #include <framework/logging/Logger.h>
30 namespace TrackFindingCDC {
37 template <
class ACellHolder>
38 class MultipassCellularPathFinder {
45 static_assert_isCellHolder<ACellHolder>();
52 moduleParamList->
addParameter(prefixed(prefix,
"caMode"),
54 "Mode for the cellular automaton application"
55 "* * 'normal' normal path search for high value paths"
56 "* * 'cells' make path for each individual cell for debugging"
57 "* * 'relations' make path for each individual relation for debugging",
60 moduleParamList->
addParameter(prefixed(prefix,
"minState"),
62 "The minimal accumulated state to follow",
65 moduleParamList->
addParameter(prefixed(prefix,
"minPathLength"),
67 "The minimal path length to that is written to output",
73 void apply(
const std::vector<ACellHolder*>& cellHolders,
75 std::vector<Path<ACellHolder> >& paths)
77 B2ASSERT(
"Expected the relations to be sorted",
78 std::is_sorted(cellHolderRelations.begin(), cellHolderRelations.end()));
82 for (ACellHolder* cellHolder : cellHolders) {
83 paths.push_back({cellHolder});
91 paths.push_back({cellHolderRelation.getFrom(), cellHolderRelation.getTo()});
98 B2WARNING(
"Unrecognised caMode parameter value " <<
m_param_caMode);
106 for (ACellHolder* cellHolder : cellHolders) {
107 cellHolder->unsetAndForwardMaskedFlag();
110 B2DEBUG(100,
"Apply multipass cellular automat");
114 auto lessStartCellState = [
this](ACellHolder * lhs, ACellHolder * rhs) {
115 AutomatonCell& lhsCell = lhs->getAutomatonCell();
116 AutomatonCell& rhsCell = rhs->getAutomatonCell();
122 return (std::make_tuple(lhsCell.hasPriorityPathFlag(),
123 lhsCell.hasStartFlag(),
124 lhsCell.getCellState()) <
125 std::make_tuple(rhsCell.hasPriorityPathFlag(),
126 rhsCell.hasStartFlag(),
127 rhsCell.getCellState()));
130 auto itStartCellHolder =
131 std::max_element(cellHolders.begin(), cellHolders.end(), lessStartCellState);
132 if (itStartCellHolder == cellHolders.end())
break;
133 else if (not(*itStartCellHolder)->getAutomatonCell().hasStartFlag())
break;
134 else if ((*itStartCellHolder)->getAutomatonCell().getCellState() <
m_param_minState)
break;
136 const ACellHolder* highestCellHolder = *itStartCellHolder;
142 if (newPath.empty())
break;
145 for (ACellHolder* cellHolderPtr : newPath) {
146 cellHolderPtr->setAndForwardMaskedFlag();
150 for (ACellHolder* cellHolder : cellHolders) {
151 cellHolder->receiveMaskedFlag();
155 paths.push_back(std::move(newPath));