Belle II Software development
DirectedNodeNetwork< EntryType, MetaInfoType > Class Template Reference

Network of directed nodes of the type EntryType. More...

#include <DirectedNodeNetwork.h>

Public Member Functions

 DirectedNodeNetwork ()
 ************************* CONSTRUCTOR/DESTRUCTOR *************************
 
 ~DirectedNodeNetwork ()
 destructor taking care of cleaning up the pointer-mess WARNING only needed when using classic pointers for the nodes!
 
bool addNode (NodeID nodeID, EntryType &newEntry)
 ************************* PUBLIC MEMBER FUNCTIONS *************************
 
bool addInnerToLastOuterNode (NodeID innerNodeID)
 to the last outerNode added, another innerNode will be attached
 
bool addOuterToLastInnerNode (NodeID outerNodeID)
 to the last innerNode added, another outerNode will be attached
 
bool linkNodes (NodeID outerNodeID, NodeID innerNodeID)
 takes two entry IDs and weaves them into the network
 
bool isNodeInNetwork (const NodeID nodeID) const
 Check if a given entry is already in the network.
 
void clear ()
 Clear directed node network Called to clear the directed node network if its size grows to large.
 
std::vector< Node * > getOuterEnds ()
 getters:
 
std::vector< Node * > getInnerEnds ()
 returns all nodes which have no inner nodes (but outer ones) and therefore are inner ends of the network
 
NodegetNode (NodeID toBeFound)
 Returns pointer to the node carrying the entry which is equal to given parameter.
 
std::vector< Node * > & getNodes ()
 Returns all nodes of the network.
 
std::vector< Node * >::iterator begin ()
 Returns iterator for container: begin.
 
std::vector< Node * >::iterator end ()
 Returns iterator for container: end.
 
unsigned int size () const
 Returns number of nodes to be found in the network.
 

Protected Types

using Node = DirectedNode<EntryType, MetaInfoType>
 Defining abbreviation for the used directed node type pack.
 
using NodeID = std::int64_t
 NodeID should be some unique integer.
 

Protected Member Functions

void finalize ()
 Finalizing the NodeNetwork.
 

Static Protected Member Functions

static bool createLink (Node &outerNode, Node &innerNode)
 ************************* INTERNAL MEMBER FUNCTIONS *************************
 

Protected Attributes

std::unordered_map< NodeID, Node * > m_nodeMap
 ************************* DATA MEMBERS *************************
 
std::vector< Node * > m_nodes
 After the network is finalized this vector will also carry all nodes to be able to keep the old interface.
 
std::vector< Node * > m_outerEnds
 keeps track of current outerEnds (nodes which have no outerNodes) entries are the NodeIDs of the nodes which currently form an outermost node
 
std::vector< Node * > m_innerEnds
 keeps track of current innerEnds (nodes which have no innerNodes) entries are the NodeIds of the nodes which currently form an innermost node
 
NodeID m_lastOuterNodeID
 temporal storage for last outer node added, used for speed-up
 
NodeID m_lastInnerNodeID
 temporal storage for last inner node added, used for speed-up
 
bool m_isFinalized
 keeps track of the state of the network to fill the vectors m_nodes, m_outerEnds, m_innerEnds only if required
 

Detailed Description

template<typename EntryType, typename MetaInfoType>
class Belle2::DirectedNodeNetwork< EntryType, MetaInfoType >

Network of directed nodes of the type EntryType.

Template Parameters
EntryType: type of the directe nodes
MetaInfoType: meta info type of the nodes

Definition at line 29 of file DirectedNodeNetwork.h.

Member Typedef Documentation

◆ Node

template<typename EntryType, typename MetaInfoType>
using Node = DirectedNode<EntryType, MetaInfoType>
protected

Defining abbreviation for the used directed node type pack.

Definition at line 32 of file DirectedNodeNetwork.h.

◆ NodeID

template<typename EntryType, typename MetaInfoType>
using NodeID = std::int64_t
protected

NodeID should be some unique integer.

Definition at line 34 of file DirectedNodeNetwork.h.

Constructor & Destructor Documentation

◆ DirectedNodeNetwork()

template<typename EntryType, typename MetaInfoType>
DirectedNodeNetwork ( )
inline

************************* CONSTRUCTOR/DESTRUCTOR *************************

Constructor

Definition at line 39 of file DirectedNodeNetwork.h.

39 :
40 m_lastOuterNodeID(),
41 m_lastInnerNodeID(),
42 m_isFinalized(false)
43 {
44 m_nodeMap.reserve(40000);
45 m_nodes.reserve(40000);
46 }

◆ ~DirectedNodeNetwork()

template<typename EntryType, typename MetaInfoType>
~DirectedNodeNetwork ( )
inline

destructor taking care of cleaning up the pointer-mess WARNING only needed when using classic pointers for the nodes!

Definition at line 51 of file DirectedNodeNetwork.h.

52 {
53 for (auto nodePointer : m_nodeMap) {
54 delete nodePointer.second;
55 }
56 m_nodeMap.clear();
57 }

Member Function Documentation

◆ addInnerToLastOuterNode()

template<typename EntryType, typename MetaInfoType>
bool addInnerToLastOuterNode ( NodeID innerNodeID)
inline

to the last outerNode added, another innerNode will be attached

Definition at line 76 of file DirectedNodeNetwork.h.

77 {
78 // check if entry does not exist, constructed with ID=-1
79 if (m_lastOuterNodeID < 0) {
80 B2WARNING("Last OuterNode is not yet in this network! CurrentNetworkSize is: " << size());
81 return false;
82 }
83 // check if entries are identical (catch loops):
84 if (m_lastOuterNodeID == innerNodeID) {
85 B2WARNING("LastOuterNode and innerEntry are identical! Skipping linking-process");
86 return false;
87 }
88
89 if (linkNodes(m_lastOuterNodeID, innerNodeID)) {
90 return true;
91 }
92 B2WARNING("Last OuterNode and innerEntry were already in the network and were already connected."
93 "This is a sign for unintended behavior!");
94 return false;
95 }

◆ addNode()

template<typename EntryType, typename MetaInfoType>
bool addNode ( NodeID nodeID,
EntryType & newEntry )
inline

************************* PUBLIC MEMBER FUNCTIONS *************************

Adding new node to nodeMap, if the nodeID is not already present in the nodeMap. Returns true if new node was added.

Definition at line 63 of file DirectedNodeNetwork.h.

64 {
65 if (m_nodeMap.count(nodeID) == 0) {
66 // cppcheck-suppress stlFindInsert
67 m_nodeMap.emplace(nodeID, new Node(newEntry));
68 m_isFinalized = false;
69 return true;
70 }
71 return false;
72 }

◆ addOuterToLastInnerNode()

template<typename EntryType, typename MetaInfoType>
bool addOuterToLastInnerNode ( NodeID outerNodeID)
inline

to the last innerNode added, another outerNode will be attached

Definition at line 99 of file DirectedNodeNetwork.h.

100 {
101 // check if entry does not exist, constructed with ID=-1
102 if (m_lastInnerNodeID < 0) {
103 B2WARNING("Last InnerNode is not yet in this network! CurrentNetworkSize is: " << size());
104 return false;
105 }
106 // check if entries are identical (catch loops):
107 if (outerNodeID == m_lastInnerNodeID) {
108 B2WARNING("OuterEntry and lastInnerNode are identical! Skipping linking-process");
109 return false;
110 }
111
112 if (linkNodes(outerNodeID, m_lastInnerNodeID)) {
113 return true;
114 }
115
116 B2WARNING("Last InnerNode and outerEntry were already in the network and were already connected."
117 "This is a sign for unintended behavior!");
118 return false;
119 }

◆ begin()

template<typename EntryType, typename MetaInfoType>
std::vector< Node * >::iterator begin ( )
inline

Returns iterator for container: begin.

Definition at line 200 of file DirectedNodeNetwork.h.

201 {
202 if (!m_isFinalized) finalize();
203 return m_nodes.begin();
204 }

◆ clear()

template<typename EntryType, typename MetaInfoType>
void clear ( )
inline

Clear directed node network Called to clear the directed node network if its size grows to large.

This is necessary to prevent to following modules from processing events with only partly filled networks.

Definition at line 154 of file DirectedNodeNetwork.h.

155 {
156 m_nodes.clear();
157 // Clearing the unordered_map is important as the following modules will process the event
158 // if it still contains entries.
159 for (auto nodePointer : m_nodeMap) {
160 delete nodePointer.second;
161 }
162 m_nodeMap.clear();
163 }

◆ createLink()

template<typename EntryType, typename MetaInfoType>
static bool createLink ( Node & outerNode,
Node & innerNode )
inlinestaticprotected

************************* INTERNAL MEMBER FUNCTIONS *************************

links nodes with each other. returns true if everything went well, returns false, if not

Definition at line 222 of file DirectedNodeNetwork.h.

223 {
224 // not successful if one of them was already added to the other one:
225 if (std::find(outerNode.getInnerNodes().begin(), outerNode.getInnerNodes().end(), &innerNode) != outerNode.getInnerNodes().end()) {
226 return false;
227 }
228 if (std::find(innerNode.getOuterNodes().begin(), innerNode.getOuterNodes().end(), &outerNode) != innerNode.getOuterNodes().end()) {
229 return false;
230 }
231
232 outerNode.addInnerNode(innerNode);
233 innerNode.addOuterNode(outerNode);
234 return true;
235 }

◆ end()

template<typename EntryType, typename MetaInfoType>
std::vector< Node * >::iterator end ( )
inline

Returns iterator for container: end.

Definition at line 208 of file DirectedNodeNetwork.h.

209 {
210 if (!m_isFinalized) finalize();
211 return m_nodes.end();
212 }

◆ finalize()

template<typename EntryType, typename MetaInfoType>
void finalize ( )
inlineprotected

Finalizing the NodeNetwork.

Definition at line 238 of file DirectedNodeNetwork.h.

239 {
240 if (m_isFinalized) return;
241 m_nodes.clear();
242 m_nodes.reserve(m_nodeMap.size());
243 m_innerEnds.clear();
244 m_outerEnds.clear();
245 for (const auto& item : m_nodeMap) {
246 m_nodes.push_back(item.second);
247 if (item.second->getInnerNodes().empty()) m_innerEnds.push_back(item.second);
248 if (item.second->getOuterNodes().empty()) m_outerEnds.push_back(item.second);
249 }
250 m_isFinalized = true;
251 }

◆ getInnerEnds()

template<typename EntryType, typename MetaInfoType>
std::vector< Node * > getInnerEnds ( )
inline

returns all nodes which have no inner nodes (but outer ones) and therefore are inner ends of the network

Definition at line 176 of file DirectedNodeNetwork.h.

177 {
178 if (!m_isFinalized) finalize();
179 return m_innerEnds;
180 }

◆ getNode()

template<typename EntryType, typename MetaInfoType>
Node * getNode ( NodeID toBeFound)
inline

Returns pointer to the node carrying the entry which is equal to given parameter.

If no fitting entry was found, nullptr is returned.

Definition at line 185 of file DirectedNodeNetwork.h.

186 {
187 if (m_nodeMap.count(toBeFound)) return m_nodeMap.at(toBeFound);
188 else return nullptr;
189 }

◆ getNodes()

template<typename EntryType, typename MetaInfoType>
std::vector< Node * > & getNodes ( )
inline

Returns all nodes of the network.

Definition at line 192 of file DirectedNodeNetwork.h.

193 {
194 if (!m_isFinalized) finalize();
195 return m_nodes;
196 }

◆ getOuterEnds()

template<typename EntryType, typename MetaInfoType>
std::vector< Node * > getOuterEnds ( )
inline

getters:

returns all nodes which have no outer nodes (but inner ones) and therefore are outer ends of the network

Definition at line 168 of file DirectedNodeNetwork.h.

169 {
170 if (!m_isFinalized) finalize();
171 return m_outerEnds;
172 }

◆ isNodeInNetwork()

template<typename EntryType, typename MetaInfoType>
bool isNodeInNetwork ( const NodeID nodeID) const
inline

Check if a given entry is already in the network.

Definition at line 144 of file DirectedNodeNetwork.h.

145 {
146 return m_nodeMap.count(nodeID);
147 }

◆ linkNodes()

template<typename EntryType, typename MetaInfoType>
bool linkNodes ( NodeID outerNodeID,
NodeID innerNodeID )
inline

takes two entry IDs and weaves them into the network

Definition at line 123 of file DirectedNodeNetwork.h.

124 {
125 m_isFinalized = false;
126 // check if entries are identical (catch loops):
127 if (outerNodeID == innerNodeID) {
128 B2WARNING("OuterNodeID and innerNodeID are identical! Skipping linking-process");
129 return false;
130 }
131 if (m_nodeMap.count(innerNodeID) == 0 or m_nodeMap.count(outerNodeID) == 0) {
132 B2WARNING("Trying to link Nodes that are not present yet");
133 return false;
134 }
135
136 m_lastOuterNodeID = outerNodeID;
137 m_lastInnerNodeID = innerNodeID;
138
139 return createLink(*(m_nodeMap[outerNodeID]), *(m_nodeMap[innerNodeID]));
140 }

◆ size()

template<typename EntryType, typename MetaInfoType>
unsigned int size ( ) const
inline

Returns number of nodes to be found in the network.

Definition at line 216 of file DirectedNodeNetwork.h.

216{ return m_nodeMap.size(); }

Member Data Documentation

◆ m_innerEnds

template<typename EntryType, typename MetaInfoType>
std::vector<Node*> m_innerEnds
protected

keeps track of current innerEnds (nodes which have no innerNodes) entries are the NodeIds of the nodes which currently form an innermost node

Definition at line 268 of file DirectedNodeNetwork.h.

◆ m_isFinalized

template<typename EntryType, typename MetaInfoType>
bool m_isFinalized
protected

keeps track of the state of the network to fill the vectors m_nodes, m_outerEnds, m_innerEnds only if required

Definition at line 277 of file DirectedNodeNetwork.h.

◆ m_lastInnerNodeID

template<typename EntryType, typename MetaInfoType>
NodeID m_lastInnerNodeID
protected

temporal storage for last inner node added, used for speed-up

Definition at line 274 of file DirectedNodeNetwork.h.

◆ m_lastOuterNodeID

template<typename EntryType, typename MetaInfoType>
NodeID m_lastOuterNodeID
protected

temporal storage for last outer node added, used for speed-up

Definition at line 271 of file DirectedNodeNetwork.h.

◆ m_nodeMap

template<typename EntryType, typename MetaInfoType>
std::unordered_map<NodeID, Node*> m_nodeMap
protected

************************* DATA MEMBERS *************************

carries all nodes

Definition at line 255 of file DirectedNodeNetwork.h.

◆ m_nodes

template<typename EntryType, typename MetaInfoType>
std::vector<Node*> m_nodes
protected

After the network is finalized this vector will also carry all nodes to be able to keep the old interface.

This shouldn't affect the performance drastically in comparison to directly accessing the nodeMap.

Definition at line 260 of file DirectedNodeNetwork.h.

◆ m_outerEnds

template<typename EntryType, typename MetaInfoType>
std::vector<Node*> m_outerEnds
protected

keeps track of current outerEnds (nodes which have no outerNodes) entries are the NodeIDs of the nodes which currently form an outermost node

Definition at line 264 of file DirectedNodeNetwork.h.


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