16 #include <framework/logging/Logger.h>
45 template<
class ContainerType,
class NodeType,
class NeighbourContainerType,
class NodeCompatibilityCheckerType>
46 class PathCollectorRecursive {
49 using Path = std::vector<NodeType*>;
58 bool findPaths(ContainerType& aNetwork, std::vector<Path>& paths,
unsigned int pathLimit,
bool storeSubsets =
false)
62 std::vector<Path> allNodePaths;
63 for (NodeType* aNode : aNetwork) {
64 if (aNode->getMetaInfo().isSeed() ==
false) {
68 NeighbourContainerType& innerNeighbours = aNode->getInnerNodes();
69 if (innerNeighbours.empty()) {
72 if (aNode->getOuterNodes().empty()) {
82 if (allNodePaths.size() > pathLimit) {
83 B2ERROR(
"Number of collected paths to large. Aborting Event!");
93 static std::string
printPaths(std::vector<Path>& allPaths)
95 std::stringstream out;
96 unsigned int longestPath = 0, longesPathIndex = 0, index = 0;
97 out <<
"Print " << allPaths.size() <<
" paths:";
98 for (
Path const& aPath : allPaths) {
99 if (longestPath < aPath.size()) {
100 longestPath = aPath.size();
101 longesPathIndex = index;
103 out <<
"\n" <<
"path " << index <<
": length " << aPath.size() <<
", entries:\n";
104 for (
auto* entry : aPath) {
105 out << entry->getEntry() <<
"| ";
109 out <<
"\n" <<
"longest path was " << longesPathIndex <<
" with length of " << longestPath <<
"\n";
120 for (
auto* entry : aPath) {
121 newPath.push_back(entry);
131 allNodePaths.push_back(newPath);
137 void findPathsRecursive(std::vector<Path >& allNodePaths,
Path& currentPath, NeighbourContainerType& innerNeighbours)
141 if (currentPath.size() > 30) {
142 B2WARNING(
"findPathsRecursive reached a path length of over 30. Stopping Path here!");
147 NeighbourContainerType viableNeighbours;
148 for (
size_t iNeighbour = 0; iNeighbour < innerNeighbours.size(); ++iNeighbour) {
150 viableNeighbours.push_back(innerNeighbours[iNeighbour]);
160 for (
size_t iNeighbour = 0; iNeighbour < viableNeighbours.size(); ++iNeighbour) {
162 if (iNeighbour == viableNeighbours.size() - 1) {
163 currentPath.push_back(viableNeighbours[iNeighbour]);
164 NeighbourContainerType& newNeighbours = viableNeighbours[iNeighbour]->getInnerNodes();
170 newPath.push_back(viableNeighbours[iNeighbour]);
171 NeighbourContainerType& newNeighbours = viableNeighbours[iNeighbour]->getInnerNodes();