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

This class assigns a common family identifier to all CACells in the network that are connected. More...

#include <NodeFamilyDefiner.h>

Public Member Functions

short defineFamilies (ContainerType &aNetwork)
 Assign a common family identifier to all Nodes in the network that are connected.
 

Private Member Functions

NeighbourContainerType markNodes (short family, const NeighbourContainerType &neighbours)
 Assign family to all connected nodes and return their neighbours.
 

Detailed Description

template<class ContainerType, class NodeType, class NeighbourContainerType>
class Belle2::NodeFamilyDefiner< ContainerType, NodeType, NeighbourContainerType >

This class assigns a common family identifier to all CACells in the network that are connected.

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::setFamily()
  • must have function: bool NodeType::getFamily()
  • must have function: NeighbourContainerType& NodeType::getInnerNodes()
  • must have function: NeighbourContainerType& NodeType::getOuterNodes()

Requirements for NeighbourContainerType:

  • must have function: unsigned int (or comparable) NeighbourContainerType::size()
  • must support range based for loop

Definition at line 34 of file NodeFamilyDefiner.h.

Member Function Documentation

◆ defineFamilies()

short defineFamilies ( ContainerType &  aNetwork)
inline

Assign a common family identifier to all Nodes in the network that are connected.

Performs a width first flood fill algorithm. Returns total number of defined families.

Definition at line 42 of file NodeFamilyDefiner.h.

43 {
44 short currentFamily = 0;
45 for (NodeType* aNode : aNetwork) {
46 if (aNode->getFamily() != -1) {
47 continue;
48 }
49
50 aNode->setFamily(currentFamily);
51
52 NeighbourContainerType& innerNeighbours = aNode->getInnerNodes();
53 NeighbourContainerType& outerNeighbours = aNode->getOuterNodes();
54 NeighbourContainerType neighbours;
55 neighbours.reserve(innerNeighbours.size() + outerNeighbours.size());
56 neighbours.insert(neighbours.end(), innerNeighbours.begin(), innerNeighbours.end());
57 neighbours.insert(neighbours.end(), outerNeighbours.begin(), outerNeighbours.end());
58
59 while (neighbours.size() != 0) {
60 neighbours = markNodes(currentFamily, neighbours);
61 }
62 currentFamily++;
63 }
64 return currentFamily;
65 }
NeighbourContainerType markNodes(short family, const NeighbourContainerType &neighbours)
Assign family to all connected nodes and return their neighbours.
NodeType
Enum of possible Nodes in parsing tree.

◆ markNodes()

NeighbourContainerType markNodes ( short  family,
const NeighbourContainerType &  neighbours 
)
inlineprivate

Assign family to all connected nodes and return their neighbours.

Definition at line 69 of file NodeFamilyDefiner.h.

70 {
71 NeighbourContainerType newNeighbours;
72 for (auto& neighbour : neighbours) {
73 // If node was already touched continue;
74 if (neighbour->getFamily() != -1) {
75 short tmpFamily = neighbour->getFamily();
76 if (tmpFamily != family) {
77 B2FATAL("Node already assigned to different family: " << family << ", " << tmpFamily);
78 } else {
79 continue;
80 }
81 }
82 neighbour->setFamily(family);
83 NeighbourContainerType& innerNeighbours = neighbour->getInnerNodes();
84 NeighbourContainerType& outerNeighbours = neighbour->getOuterNodes();
85 newNeighbours.reserve(innerNeighbours.size() + outerNeighbours.size());
86 newNeighbours.insert(newNeighbours.end(), innerNeighbours.begin(), innerNeighbours.end());
87 newNeighbours.insert(newNeighbours.end(), outerNeighbours.begin(), outerNeighbours.end());
88 }
89 return newNeighbours;
90 }

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