ATLAS Offline Software
Loading...
Searching...
No Matches
TrigCompositeUtils::NavGraph Class Reference

Structure to hold a transient Directed Acyclic Graph (DAG) structure. More...

#include <NavGraph.h>

Collaboration diagram for TrigCompositeUtils::NavGraph:

Public Member Functions

 NavGraph ()=default
 Construct an empty NavGraph.
 ~NavGraph ()=default
 Destruct a NavGraph, default.
 NavGraph (const NavGraph &obj)=delete
 Prevent copy of a NavGraphNode.
 NavGraph (NavGraph &&obj)=delete
 Prevent move of a NavGraphNode.
void addNode (const Decision *node, const Decision *comingFrom=nullptr)
 Add a new NavGraphNode which shadows the xAOD Decision object "node" from the full navigation graph.
const std::vector< NavGraphNode * > & finalNodes () const
 Get all final nodes.
std::vector< NavGraphNode * > allNodes ()
 Get all nodes.
size_t nodes () const
size_t edges () const
std::vector< const Decision * > thin ()
 Perform thinning.
void printAllPaths (MsgStream &log, MSG::Level msgLevel=MSG::VERBOSE) const
 Helper function.

Private Member Functions

void rewireNodeForRemoval (NavGraphNode &toBeDeleted)
 Take all seeds (parents) of the supplied node and connect them to all the node's children.
void recursivePrintNavPath (const NavGraphNode &nav, size_t level, MsgStream &log, MSG::Level msgLevel) const
 @bried Internal helper function.

Private Attributes

std::map< const Decision *, size_t > m_nodePositionMap
 Map of Decision pointer and index of the node(that contains the Decision) in m_nodes.
std::vector< std::unique_ptr< NavGraphNode > > m_nodes
 Vector of unique pointers to nodes in the graph.
std::vector< NavGraphNode * > m_finalNodes
 Entry points into the navigation graph.
size_t m_edges {0}
 Statistics on the number of edges, connecting the nodes in the graph.

Detailed Description

Structure to hold a transient Directed Acyclic Graph (DAG) structure.

NavGraph is populated from, and forms a sub-graph over the full Run 3 trigger navigation graph in a single event. Requirements on specific chains, and the specification of allowable graph entry-points are considered in the construction of the NavGraph sub-graph. Once one of these sub-graphs is fully populated to a given specification, it is searched by the feature-retrieval code to find features.

Definition at line 111 of file NavGraph.h.

Constructor & Destructor Documentation

◆ NavGraph() [1/3]

TrigCompositeUtils::NavGraph::NavGraph ( )
default

Construct an empty NavGraph.

◆ ~NavGraph()

TrigCompositeUtils::NavGraph::~NavGraph ( )
default

Destruct a NavGraph, default.

◆ NavGraph() [2/3]

TrigCompositeUtils::NavGraph::NavGraph ( const NavGraph & obj)
delete

Prevent copy of a NavGraphNode.

◆ NavGraph() [3/3]

TrigCompositeUtils::NavGraph::NavGraph ( NavGraph && obj)
delete

Prevent move of a NavGraphNode.

Member Function Documentation

◆ addNode()

void TrigCompositeUtils::NavGraph::addNode ( const Decision * node,
const Decision * comingFrom = nullptr )

Add a new NavGraphNode which shadows the xAOD Decision object "node" from the full navigation graph.

Parameters
[in]nodeThe xAOD Decision object which the new node will shadow. Will not cause duplication if node has already been added.
[in]comingFromIf not null, used to indicate which xAOD Decision object was the seed of "node". This is used to form an edge in the graph. Alternately, if comingFrom is null then "node" is taken as a final node (one of the locations from which the graph should be explored) and hence is added to the finalNodes vector.

Definition at line 73 of file NavGraph.cxx.

73 {
74 // m_nodes is a vector to preserve iteration ordering for stable output.
75 // m_nodePositionMap assures that there is no duplicated NavGraphNode
76 // with the same Decision pointer.
77 const auto& [nodeItr, newNode] = m_nodePositionMap.emplace(node, m_nodes.size());
78 if (newNode) {
79 m_nodes.emplace_back( std::make_unique<NavGraphNode>(node) );
80 }
81 NavGraphNode* nodeObj = m_nodes[nodeItr->second].get();
82
83 if (comingFrom == nullptr) { // Not coming from anywhere - hence a final node.
84 m_finalNodes.push_back( nodeObj );
85 } else {
86 const auto& [nodeItr, newNode] = m_nodePositionMap.emplace(comingFrom, m_nodes.size());
87 if (newNode) {
88 m_nodes.emplace_back( std::make_unique<NavGraphNode>(comingFrom) );
89 }
90 NavGraphNode* comingFromNodeObj = m_nodes[nodeItr->second].get();
91 const bool newEdge = comingFromNodeObj->linksTo( nodeObj );
92 if (newEdge) {
93 ++m_edges;
94 }
95 }
96 }
std::vector< NavGraphNode * > m_finalNodes
Entry points into the navigation graph.
Definition NavGraph.h:213
std::map< const Decision *, size_t > m_nodePositionMap
Map of Decision pointer and index of the node(that contains the Decision) in m_nodes.
Definition NavGraph.h:211
std::vector< std::unique_ptr< NavGraphNode > > m_nodes
Vector of unique pointers to nodes in the graph.
Definition NavGraph.h:212
size_t m_edges
Statistics on the number of edges, connecting the nodes in the graph.
Definition NavGraph.h:214

◆ allNodes()

std::vector< NavGraphNode * > TrigCompositeUtils::NavGraph::allNodes ( )

Get all nodes.

Returns
Vector of all nodes. Including all final, intermediate, and initial nodes.

Definition at line 103 of file NavGraph.cxx.

103 {
104 std::vector<NavGraphNode*> returnVec;
105 returnVec.reserve(m_nodes.size());
106 for (std::unique_ptr<NavGraphNode>& entry : m_nodes) {
107 NavGraphNode& nodeObj = *entry;
108 returnVec.push_back( &nodeObj );
109 }
110 return returnVec;
111 }

◆ edges()

size_t TrigCompositeUtils::NavGraph::edges ( ) const
Returns
Total number of edges in the NavGraph.

Definition at line 119 of file NavGraph.cxx.

119 {
120 return m_edges;
121 }

◆ finalNodes()

const std::vector< NavGraphNode * > & TrigCompositeUtils::NavGraph::finalNodes ( ) const

Get all final nodes.

Returns
Vector of final nodes. These are the nodes which were added without any "comingFrom". To explore the NavGraph fully, one should explore recursively all paths originating from each of the final nodes.

Definition at line 99 of file NavGraph.cxx.

99 {
100 return m_finalNodes;
101 }

◆ nodes()

size_t TrigCompositeUtils::NavGraph::nodes ( ) const
Returns
Total number of nodes in the NavGraph.

Definition at line 114 of file NavGraph.cxx.

114 {
115 return m_nodes.size();
116 }

◆ printAllPaths()

void TrigCompositeUtils::NavGraph::printAllPaths ( MsgStream & log,
MSG::Level msgLevel = MSG::VERBOSE ) const

Helper function.

Print the internal graph structure to the terminal.

Parameters
[in]logAthena messaging service reference.
[in]msgLevelAthena messaging service verbosity level.

Definition at line 165 of file NavGraph.cxx.

165 {
166 for (const NavGraphNode* finalNode : m_finalNodes) {
167 recursivePrintNavPath(*finalNode, 0, log, msgLevel);
168 }
169 }
void recursivePrintNavPath(const NavGraphNode &nav, size_t level, MsgStream &log, MSG::Level msgLevel) const
@bried Internal helper function.
Definition NavGraph.cxx:172

◆ recursivePrintNavPath()

void TrigCompositeUtils::NavGraph::recursivePrintNavPath ( const NavGraphNode & nav,
size_t level,
MsgStream & log,
MSG::Level msgLevel ) const
private

@bried Internal helper function.

Recursively print the graph structure from a single given starting node.

Parameters
[in]navThe node to recursively explore.
[in]levelThe current depth of recursion. Used to pad output format.
[in]logAthena messaging service reference.
[in]msgLevelAthena messaging service verbosity level.

Definition at line 172 of file NavGraph.cxx.

172 {
173 const Decision* node = nav.node();
174 const ElementLink<DecisionContainer> nodeEL = decisionToElementLink( node, Gaudi::Hive::currentContext() );
175 std::stringstream ss;
176 for (size_t i = 0; i < level; ++i) {
177 ss << " ";
178 }
179
180 ss << "|-> " << nodeEL.dataID() << " #" << nodeEL.index() << " Name(" << node->name() << ") Passing(" << node->decisions().size() << ")";
181 if (nav.getKeep()) ss << " [KEEP]";
182 if (node->hasObjectLink(featureString())) {
184 uint32_t clid;
186 node->typelessGetObjectLink(featureString(), key, clid, index);
187#ifndef XAOD_STANDALONE // Athena or AthAnalysis
188 ss << " Feature(#" << index << ", " << CLIDRegistry::CLIDToTypeinfo(clid)->name() << ", " << key << ")";
189#else
190 ss << " Feature(#" << index << ", " << key << ")";
191#endif
192 }
193 if (node->hasObjectLink(viewString())) ss << " [View]";
194 if (node->hasObjectLink(roiString())) ss << " [RoI]";
195 if (node->hasObjectLink(initialRoIString())) ss << " [InitialRoI]";
196 log << msgLevel << ss.str() << endmsg;
197 for (const NavGraphNode* seed : nav.seeds()) {
198 recursivePrintNavPath(*seed, level + 1, log, msgLevel);
199 }
200 }
#define endmsg
static Double_t ss
static const std::type_info * CLIDToTypeinfo(CLID clid)
Translate between CLID and type_info.
str index
Definition DeMoScan.py:362
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
const std::string & viewString()
const std::string & roiString()
const std::string & featureString()
const std::string & initialRoIString()
ElementLink< DecisionContainer > decisionToElementLink(const Decision *d, const EventContext &ctx)
Takes a raw pointer to a Decision and returns an ElementLink to the Decision.
setEventNumber uint32_t

◆ rewireNodeForRemoval()

void TrigCompositeUtils::NavGraph::rewireNodeForRemoval ( NavGraphNode & toBeDeleted)
private

Take all seeds (parents) of the supplied node and connect them to all the node's children.

Unlink the parents and children from the node. For the case of Parent nodes, P, node to be deleted, N, and Child nodes, C, this function converts from P P P P P P | \ / | \ / N , N , N , N | | / \ / \ C C C C C C to P P P P P P | \ / | |\ /| | , | , | , | | | | | / \ |/ | C C C C C C where N is orphaned from the graph, with no parents or children.

Parameters
[in]toBeDeletedNode to rewire out of the navigation graph prior to its removal.

Definition at line 139 of file NavGraph.cxx.

139 {
140 const std::vector<NavGraphNode*> myParents = toBeDeleted.seeds();
141 const std::vector<NavGraphNode*> myChildren = toBeDeleted.children();
142
143 // Perform the (potentially) many-to-many re-linking required to remove toBeDeleted from the graph
144 for (NavGraphNode* child : myChildren) {
145 for (NavGraphNode* parent : myParents) {
146 bool newEdge = child->linksTo(parent);
147 if (newEdge) {
148 ++m_edges;
149 }
150 }
151 }
152
153 // Remove the edges connecting to toBeDeleted from all of its children and all of parents
154 for (NavGraphNode* child : myChildren) {
155 child->dropLinks(&toBeDeleted);
156 --m_edges;
157 }
158 for (NavGraphNode* parent : myParents) {
159 parent->dropLinks(&toBeDeleted);
160 --m_edges;
161 }
162 }

◆ thin()

std::vector< const Decision * > TrigCompositeUtils::NavGraph::thin ( )

Perform thinning.

Removing all nodes which are not explicitly flagged as keep(), after having re-wired them out of the graph.

Returns
A vector of the Decision* behind the NavGraphNodes which were thinned from the NavGraph.

Definition at line 123 of file NavGraph.cxx.

123 {
124 std::vector<const Decision*> returnVec;
125 std::vector<std::unique_ptr<NavGraphNode>>::iterator it;
126 for (it = m_nodes.begin(); it != m_nodes.end(); /*noop*/) {
127 if ((*it)->getKeep()) {
128 (*it)->resetKeep();
129 ++it;
130 } else {
131 returnVec.push_back((*it)->node());
132 rewireNodeForRemoval(*(*it));
133 it = m_nodes.erase(it);
134 }
135 }
136 return returnVec;
137 }
void rewireNodeForRemoval(NavGraphNode &toBeDeleted)
Take all seeds (parents) of the supplied node and connect them to all the node's children.
Definition NavGraph.cxx:139

Member Data Documentation

◆ m_edges

size_t TrigCompositeUtils::NavGraph::m_edges {0}
private

Statistics on the number of edges, connecting the nodes in the graph.

Definition at line 214 of file NavGraph.h.

214{0};

◆ m_finalNodes

std::vector<NavGraphNode*> TrigCompositeUtils::NavGraph::m_finalNodes
private

Entry points into the navigation graph.

When iterating over the graph, start from all of these places.

Definition at line 213 of file NavGraph.h.

◆ m_nodePositionMap

std::map<const Decision*, size_t> TrigCompositeUtils::NavGraph::m_nodePositionMap
private

Map of Decision pointer and index of the node(that contains the Decision) in m_nodes.

Definition at line 211 of file NavGraph.h.

◆ m_nodes

std::vector<std::unique_ptr<NavGraphNode> > TrigCompositeUtils::NavGraph::m_nodes
private

Vector of unique pointers to nodes in the graph.

Definition at line 212 of file NavGraph.h.


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