Belle II Software development
PathCollectorRecursive< ContainerType, NodeType, NeighbourContainerType, NodeCompatibilityCheckerType > Class Template Reference

Path finder for generic ContainerType. More...

#include <PathCollectorRecursive.h>

Public Types

using Path = std::vector<NodeType*>
 Using Path for vector of pointers to NodeTypes.
 

Public Member Functions

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.
 

Static Public Member Functions

static std::string printPaths (const std::vector< Path > &allPaths)
 Prints information about all paths provided in a vector of paths.
 

Public Attributes

unsigned int minPathLength = 2
 public Data members:
 
unsigned int nTrees = 0
 Counter for number of trees found.
 
unsigned int nRecursiveCalls = 0
 Counter for number of recursive calls.
 
bool m_storeSubsets = false
 flag if subsets should be stored or not
 

Protected Member Functions

Path clone (const Path &aPath) const
 Copies path to create an identical one.
 
void storeAcceptedPath (Path newPath, std::vector< Path > &allNodePaths) const
 Tests length requirement on a path before adding it to path vector.
 
void findPathsRecursive (std::vector< Path > &allNodePaths, Path &currentPath, NeighbourContainerType &innerNeighbours)
 Recursive pathFinder: Collects all possible segment combinations to build paths.
 

Protected Attributes

NodeCompatibilityCheckerType m_compatibilityChecker
 protected Data members:
 

Detailed Description

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
class Belle2::PathCollectorRecursive< ContainerType, NodeType, NeighbourContainerType, NodeCompatibilityCheckerType >

Path finder for generic ContainerType.

Uses recursive collection process and returns vector of paths, which are vectors of NodeType*.

Requirements for ContainerType:

  • must have begin() and end() with iterator pointing to pointers of entries ( = ContainerType< NodeType*>)

Requirements for NodeType:

  • must have function: bool NodeType::getMetaInfo().isSeed()
  • must have function: NeighbourContainerType& NodeType::getInnerNodes()
  • must have function: bool NodeType::getOuterNodes().empty()
  • other requirements depend on NodeCompatibilityCheckerType used.

Requirements for NeighbourContainerType:

  • must have function: bool NeighbourContainerType::empty()
  • must have function: unsigned int (or comparable) NeighbourContainerType::size()
  • must have access operator: NeighbourContainerType: operator [] returning a NodeType*

Requirements for NodeCompatibilityCheckerType:

  • must have function bool areCompatible(NodeType* outerNode, NodeType* innerNode);

Definition at line 44 of file PathCollectorRecursive.h.

Member Typedef Documentation

◆ Path

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
using Path = std::vector<NodeType*>

Using Path for vector of pointers to NodeTypes.

Definition at line 47 of file PathCollectorRecursive.h.

Member Function Documentation

◆ clone()

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
Path clone ( const Path & aPath) const
inlineprotected

Copies path to create an identical one.

Definition at line 116 of file PathCollectorRecursive.h.

117 {
118 Path newPath = Path();
119 for (auto* entry : aPath) {
120 newPath.push_back(entry);
121 }
122 return newPath;
123 }

◆ findPaths()

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
bool findPaths ( ContainerType & aNetwork,
std::vector< Path > & paths,
unsigned int pathLimit,
bool storeSubsets = false )
inline

Main functionality of this class Evaluates provided network and creates all allowed paths.

All found paths are filled into the provided vector 'paths'. If storeSubsets is turned on, also the sub-paths are saved to vector 'paths'. If a defined limit on the number of possible paths is exceeded, the search is aborted, and false is returned.

Definition at line 56 of file PathCollectorRecursive.h.

57 {
58 m_storeSubsets = storeSubsets;
59
60 std::vector<Path> allNodePaths;
61 for (NodeType* aNode : aNetwork) {
62 if (aNode->getMetaInfo().isSeed() == false) {
63 continue;
64 }
65
66 NeighbourContainerType& innerNeighbours = aNode->getInnerNodes();
67 if (innerNeighbours.empty()) {
68 continue;
69 }
70 if (aNode->getOuterNodes().empty()) {
71 nTrees++;
72 }
73
74 // creating unique_ptr of a new path:
75 Path newPath = Path{aNode};
76
77 findPathsRecursive(allNodePaths, newPath, innerNeighbours);
78 storeAcceptedPath(newPath, allNodePaths);
79
80 if (allNodePaths.size() > pathLimit) {
81 B2WARNING("Number of collected paths is too large: skipping the event and not processing it."
82 << LogVar("Number of node paths", allNodePaths.size()) << LogVar("Current limit of paths", pathLimit));
83 return false;
84 }
85 }
86 paths = allNodePaths;
87 return true;
88 }

◆ findPathsRecursive()

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
void findPathsRecursive ( std::vector< Path > & allNodePaths,
Path & currentPath,
NeighbourContainerType & innerNeighbours )
inlineprotected

Recursive pathFinder: Collects all possible segment combinations to build paths.

Definition at line 136 of file PathCollectorRecursive.h.

137 {
138 nRecursiveCalls++;
139
140 if (currentPath.size() > 30) {
141 B2WARNING("findPathsRecursive reached a path length of over 30. Stopping Path here!");
142 return;
143 }
144
145 // Test if there are viable neighbours to current node
146 NeighbourContainerType viableNeighbours;
147 for (size_t iNeighbour = 0; iNeighbour < innerNeighbours.size(); ++iNeighbour) {
148 if (m_compatibilityChecker.areCompatible(currentPath.back(), innerNeighbours[iNeighbour])) {
149 viableNeighbours.push_back(innerNeighbours[iNeighbour]);
150 }
151 }
152
153 // If current path will continue, optionally store the subpath up to current node
154 if (m_storeSubsets && viableNeighbours.size() > 0) {
155 Path newPath = clone(currentPath);
156 storeAcceptedPath(newPath, allNodePaths);
157 }
158
159 for (size_t iNeighbour = 0; iNeighbour < viableNeighbours.size(); ++iNeighbour) {
160 // the last alternative is assigned to the existing path.
161 if (iNeighbour == viableNeighbours.size() - 1) {
162 currentPath.push_back(viableNeighbours[iNeighbour]);
163 NeighbourContainerType& newNeighbours = viableNeighbours[iNeighbour]->getInnerNodes();
164
165 findPathsRecursive(allNodePaths, currentPath, newNeighbours);
166 } else {
167 Path newPath = clone(currentPath);
168
169 newPath.push_back(viableNeighbours[iNeighbour]);
170 NeighbourContainerType& newNeighbours = viableNeighbours[iNeighbour]->getInnerNodes();
171
172 findPathsRecursive(allNodePaths, newPath, newNeighbours);
173 storeAcceptedPath(newPath, allNodePaths);
174 }
175 }
176 }

◆ printPaths()

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
static std::string printPaths ( const std::vector< Path > & allPaths)
inlinestatic

Prints information about all paths provided in a vector of paths.

Definition at line 92 of file PathCollectorRecursive.h.

93 {
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;
101 }
102 out << "\n" << "path " << index << ": length " << aPath.size() << ", entries:\n";
103 for (auto* entry : aPath) {
104 out << entry->getEntry() << "| ";
105 }
106 index++;
107 }
108 out << "\n" << "longest path was " << longesPathIndex << " with length of " << longestPath << "\n";
109
110 return out.str();
111 }

◆ storeAcceptedPath()

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
void storeAcceptedPath ( Path newPath,
std::vector< Path > & allNodePaths ) const
inlineprotected

Tests length requirement on a path before adding it to path vector.

Definition at line 127 of file PathCollectorRecursive.h.

128 {
129 if (newPath.size() >= minPathLength) {
130 allNodePaths.push_back(newPath);
131 }
132 }

Member Data Documentation

◆ m_compatibilityChecker

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
NodeCompatibilityCheckerType m_compatibilityChecker
protected

protected Data members:

Stores mini-Class for checking compatibility of two nodes passed.

Definition at line 196 of file PathCollectorRecursive.h.

◆ m_storeSubsets

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
bool m_storeSubsets = false

flag if subsets should be stored or not

Definition at line 191 of file PathCollectorRecursive.h.

◆ minPathLength

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
unsigned int minPathLength = 2

public Data members:

parameter for setting minimal path length: path length == number of nodes collected in a row from given network, this is not necessarily number of hits!

Definition at line 182 of file PathCollectorRecursive.h.

◆ nRecursiveCalls

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
unsigned int nRecursiveCalls = 0

Counter for number of recursive calls.

Definition at line 188 of file PathCollectorRecursive.h.

◆ nTrees

template<class ContainerType, class NodeType, class NeighbourContainerType, class NodeCompatibilityCheckerType>
unsigned int nTrees = 0

Counter for number of trees found.

Definition at line 185 of file PathCollectorRecursive.h.


The documentation for this class was generated from the following file: