Belle II Software development
NodeFamilyDefiner.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#pragma once
9
10#include <framework/logging/Logger.h>
11
12namespace Belle2 {
17
33 template<class ContainerType, class NodeType, class NeighbourContainerType>
35 public:
36
41 static short defineFamilies(ContainerType& aNetwork)
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 }
65
66 private:
68 static NeighbourContainerType markNodes(short family, const NeighbourContainerType& neighbours)
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 }
90 };
91
92}
This class assigns a common family identifier to all CACells in the network that are connected.
static short defineFamilies(ContainerType &aNetwork)
Assign a common family identifier to all Nodes in the network that are connected.
static 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.
Abstract base class for different kinds of events.