14 #include <framework/logging/Logger.h>
43 template<
class ContainerType,
class NodeType,
class NeighbourContainerType,
class NodeCompatibilityCheckerType>
47 using Path = std::vector<NodeType*>;
57 bool findPaths(ContainerType& aNetwork, std::vector<Path>& paths,
unsigned int pathLimit,
bool storeSubsets =
false)
61 std::vector<Path> allNodePaths;
62 for (NodeType* aNode : aNetwork) {
63 if (aNode->getMetaInfo().isSeed() ==
false) {
67 NeighbourContainerType& innerNeighbours = aNode->getInnerNodes();
68 if (innerNeighbours.empty()) {
71 if (aNode->getOuterNodes().empty()) {
81 if (allNodePaths.size() > pathLimit) {
82 B2ERROR(
"Number of collected paths to large: skipping the event and not processing it.");
92 static std::string
printPaths(std::vector<Path>& allPaths)
94 std::stringstream out;
95 unsigned int longestPath = 0, longesPathIndex = 0, index = 0;
96 out <<
"Print " << allPaths.size() <<
" paths:";
97 for (
Path const& aPath : allPaths) {
98 if (longestPath < aPath.size()) {
99 longestPath = aPath.size();
100 longesPathIndex = index;
102 out <<
"\n" <<
"path " << index <<
": length " << aPath.size() <<
", entries:\n";
103 for (
auto* entry : aPath) {
104 out << entry->getEntry() <<
"| ";
108 out <<
"\n" <<
"longest path was " << longesPathIndex <<
" with length of " << longestPath <<
"\n";
119 for (
auto* entry : aPath) {
120 newPath.push_back(entry);
130 allNodePaths.push_back(newPath);
140 if (currentPath.size() > 30) {
141 B2WARNING(
"findPathsRecursive reached a path length of over 30. Stopping Path here!");
146 NeighbourContainerType viableNeighbours;
147 for (
size_t iNeighbour = 0; iNeighbour < innerNeighbours.size(); ++iNeighbour) {
149 viableNeighbours.push_back(innerNeighbours[iNeighbour]);
159 for (
size_t iNeighbour = 0; iNeighbour < viableNeighbours.size(); ++iNeighbour) {
161 if (iNeighbour == viableNeighbours.size() - 1) {
162 currentPath.push_back(viableNeighbours[iNeighbour]);
163 NeighbourContainerType& newNeighbours = viableNeighbours[iNeighbour]->getInnerNodes();
169 newPath.push_back(viableNeighbours[iNeighbour]);
170 NeighbourContainerType& newNeighbours = viableNeighbours[iNeighbour]->getInnerNodes();
Path finder for generic ContainerType.
unsigned int nRecursiveCalls
Counter for number of recursive calls.
void storeAcceptedPath(Path newPath, std::vector< Path > &allNodePaths) const
Tests length requirement on a path before adding it to path vector.
NodeCompatibilityCheckerType m_compatibilityChecker
protected Data members:
std::vector< NodeType * > Path
Using Path for vector of pointers to NodeTypes.
Path clone(const Path &aPath) const
Copies path to create an identical one.
unsigned int nTrees
Counter for number of trees found.
static std::string printPaths(std::vector< Path > &allPaths)
Prints information about all paths provided in a vector of paths.
unsigned int minPathLength
public Data members:
void findPathsRecursive(std::vector< Path > &allNodePaths, Path ¤tPath, NeighbourContainerType &innerNeighbours)
Recursive pathFinder: Collects all possible segment combinations to build paths.
bool m_storeSubsets
flag if subsets should be stored or not
bool findPaths(ContainerType &aNetwork, std::vector< Path > &paths, unsigned int pathLimit, bool storeSubsets=false)
Main functionality of this class Evaluates provided network and creates all allowed paths.
Abstract base class for different kinds of events.