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>

Static Public Member Functions

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

Static Private Member Functions

static 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()

template<class ContainerType, class NodeType, class NeighbourContainerType>
static short defineFamilies ( ContainerType & aNetwork)
inlinestatic

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 41 of file NodeFamilyDefiner.h.

42 {
43 short currentFamily = 0;
44 for (NodeType* aNode : aNetwork) {
45 if (aNode->getFamily() != -1) {
46 continue;
47 }
48
49 aNode->setFamily(currentFamily);
50
51 NeighbourContainerType& innerNeighbours = aNode->getInnerNodes();
52 NeighbourContainerType& outerNeighbours = aNode->getOuterNodes();
53 NeighbourContainerType neighbours;
54 neighbours.reserve(innerNeighbours.size() + outerNeighbours.size());
55 neighbours.insert(neighbours.end(), innerNeighbours.begin(), innerNeighbours.end());
56 neighbours.insert(neighbours.end(), outerNeighbours.begin(), outerNeighbours.end());
57
58 while (neighbours.size() != 0) {
59 neighbours = markNodes(currentFamily, neighbours);
60 }
61 currentFamily++;
62 }
63 return currentFamily;
64 }

◆ markNodes()

template<class ContainerType, class NodeType, class NeighbourContainerType>
static NeighbourContainerType markNodes ( short family,
const NeighbourContainerType & neighbours )
inlinestaticprivate

Assign family to all connected nodes and return their neighbours.

Definition at line 68 of file NodeFamilyDefiner.h.

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

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