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 74 of file NavGraph.cxx.

74 {
75 // m_nodes is a vector to preserve iteration ordering for stable output.
76 // m_nodePositionMap assures that there is no duplicated NavGraphNode
77 // with the same Decision pointer.
78 const auto& [nodeItr, newNode] = m_nodePositionMap.emplace(node, m_nodes.size());
79 if (newNode) {
80 m_nodes.emplace_back( std::make_unique<NavGraphNode>(node) );
81 }
82 NavGraphNode* nodeObj = m_nodes[nodeItr->second].get();
83
84 if (comingFrom == nullptr) { // Not coming from anywhere - hence a final node.
85 m_finalNodes.push_back( nodeObj );
86 } else {
87 const auto& [nodeItr, newNode] = m_nodePositionMap.emplace(comingFrom, m_nodes.size());
88 if (newNode) {
89 m_nodes.emplace_back( std::make_unique<NavGraphNode>(comingFrom) );
90 }
91 NavGraphNode* comingFromNodeObj = m_nodes[nodeItr->second].get();
92 const bool newEdge = comingFromNodeObj->linksTo( nodeObj );
93 if (newEdge) {
94 ++m_edges;
95 }
96 }
97 }
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 104 of file NavGraph.cxx.

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

◆ edges()

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

Definition at line 120 of file NavGraph.cxx.

120 {
121 return m_edges;
122 }

◆ 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 100 of file NavGraph.cxx.

100 {
101 return m_finalNodes;
102 }

◆ nodes()

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

Definition at line 115 of file NavGraph.cxx.

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

◆ 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 166 of file NavGraph.cxx.

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

◆ 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 173 of file NavGraph.cxx.

173 {
174 const Decision* node = nav.node();
175 const ElementLink<DecisionContainer> nodeEL = decisionToElementLink( node, Gaudi::Hive::currentContext() );
176 std::stringstream ss;
177 for (size_t i = 0; i < level; ++i) {
178 ss << " ";
179 }
180
181 ss << "|-> " << nodeEL.dataID() << " #" << nodeEL.index() << " Name(" << node->name() << ") Passing(" << node->decisions().size() << ")";
182 if (nav.getKeep()) ss << " [KEEP]";
183 if (node->hasObjectLink(featureString())) {
185 uint32_t clid;
187 node->typelessGetObjectLink(featureString(), key, clid, index);
188#ifndef XAOD_STANDALONE // Athena or AthAnalysis
189 ss << " Feature(#" << index << ", " << CLIDRegistry::CLIDToTypeinfo(clid)->name() << ", " << key << ")";
190#else
191 ss << " Feature(#" << index << ", " << key << ")";
192#endif
193 }
194 if (node->hasObjectLink(viewString())) ss << " [View]";
195 if (node->hasObjectLink(roiString())) ss << " [RoI]";
196 if (node->hasObjectLink(initialRoIString())) ss << " [InitialRoI]";
197 log << msgLevel << ss.str() << endmsg;
198 for (const NavGraphNode* seed : nav.seeds()) {
199 recursivePrintNavPath(*seed, level + 1, log, msgLevel);
200 }
201 }
#define endmsg
static Double_t ss
static const std::type_info * CLIDToTypeinfo(CLID clid)
Translate between CLID and type_info.
const std::vector< TrigCompositeUtils::DecisionID > & decisions() const
Get positive HLT chain decisions associated with this TrigComposite. Navigation use.
bool hasObjectLink(const std::string &name, const CLID clid=CLID_NULL) const
Check if a link to an object with a given name and type exists. CLID_NULL to not check type.
bool typelessGetObjectLink(const std::string &name, sgkey_t &key, uint32_t &clid, index_type &index) const
Fetches a single link without type.
const std::string & name() const
Get a human-readable name for the object.
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 140 of file NavGraph.cxx.

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

◆ 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 124 of file NavGraph.cxx.

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

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: