ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
TrigCompositeUtils::NavGraph Class Reference

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. More...

#include <NavGraph.h>

Collaboration diagram for TrigCompositeUtils::NavGraph:

Public Member Functions

 NavGraph ()
 Construct an empty NavGraph. More...
 
 ~NavGraph ()=default
 Destruct a NavGraph, default. More...
 
 NavGraph (const NavGraph &obj)=delete
 Prevent copy of a NavGraphNode. More...
 
 NavGraph (NavGraph &&obj)=delete
 Prevent move of a NavGraphNode. More...
 
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. More...
 
const std::vector< NavGraphNode * > & finalNodes () const
 Get all final nodes. More...
 
std::vector< NavGraphNode * > allNodes ()
 Get all nodes. More...
 
size_t nodes () const
 
size_t edges () const
 
std::vector< const Decision * > thin ()
 Perform thinning. More...
 
void printAllPaths (MsgStream &log, MSG::Level msgLevel=MSG::VERBOSE) const
 Helper function. More...
 

Private Member Functions

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

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. More...
 
std::vector< std::unique_ptr< NavGraphNode > > m_nodes
 Vector of unique pointers to nodes in the graph. More...
 
std::vector< NavGraphNode * > m_finalNodes
 Entry points into the navigation graph. More...
 
size_t m_edges
 Statistics on the number of edges, connecting the nodes in the graph. More...
 

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

Construct an empty NavGraph.

Definition at line 74 of file NavGraph.cxx.

75  }

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

78  {
79  // m_node is a vector to preserve iteration ordering for stable output.
80  // m_nodePositionMap assures that there is no duplicated NavGraphNode
81  // with the same Decision pointer.
82  auto nodePairIt = m_nodePositionMap.insert(std::make_pair(node, m_nodes.size()));
83  if (nodePairIt.second) m_nodes.push_back( std::unique_ptr<NavGraphNode>(new NavGraphNode(node)) );
84  NavGraphNode& nodeObj = *m_nodes[nodePairIt.first->second];
85 
86  if (comingFrom == nullptr) { // Not coming from anywhere - hence a final node.
87  m_finalNodes.push_back( &nodeObj );
88  } else {
89  auto comingFromPairIt = m_nodePositionMap.insert( std::make_pair(comingFrom, m_nodes.size()) );
90  if (comingFromPairIt.second) m_nodes.push_back( std::unique_ptr<NavGraphNode>(new NavGraphNode(comingFrom)) );
91  NavGraphNode& comingFromNodeObj = *m_nodes[comingFromPairIt.first->second];
92  const bool newEdge = comingFromNodeObj.linksTo( &nodeObj );
93  if (newEdge) {
94  ++m_edges;
95  }
96  }
97  }

◆ 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  }

◆ 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();
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  }

◆ 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());
134  it = m_nodes.erase(it);
135  }
136  }
137  return returnVec;
138  }

Member Data Documentation

◆ m_edges

size_t TrigCompositeUtils::NavGraph::m_edges
private

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

Definition at line 214 of file NavGraph.h.

◆ 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:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
TrigCompositeUtils::NavGraph::recursivePrintNavPath
void recursivePrintNavPath(const NavGraphNode &nav, size_t level, MsgStream &log, MSG::Level msgLevel) const
@bried Internal helper function.
Definition: NavGraph.cxx:173
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
skel.it
it
Definition: skel.GENtoEVGEN.py:396
TrigCompositeUtils::NavGraph::m_edges
size_t m_edges
Statistics on the number of edges, connecting the nodes in the graph.
Definition: NavGraph.h:214
CLIDRegistry::CLIDToTypeinfo
static const std::type_info * CLIDToTypeinfo(CLID clid)
Translate between CLID and type_info.
Definition: CLIDRegistry.cxx:136
TrigCompositeUtils::NavGraph::m_nodes
std::vector< std::unique_ptr< NavGraphNode > > m_nodes
Vector of unique pointers to nodes in the graph.
Definition: NavGraph.h:212
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigCompositeUtils::initialRoIString
const std::string & initialRoIString()
Definition: TrigCompositeUtilsRoot.cxx:868
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
TrigCompositeUtils::decisionToElementLink
ElementLink< DecisionContainer > decisionToElementLink(const Decision *d, const EventContext &ctx)
Takes a raw pointer to a Decision and returns an ElementLink to the Decision.
Definition: TrigCompositeUtilsRoot.cxx:122
test_pyathena.parent
parent
Definition: test_pyathena.py:15
node::node
node()
Definition: memory_hooks-stdcmalloc.h:76
TrigCompositeUtils::featureString
const std::string & featureString()
Definition: TrigCompositeUtilsRoot.cxx:884
node::name
void name(const std::string &n)
Definition: node.h:37
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
TrigCompositeUtils::NavGraph::rewireNodeForRemoval
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
TrigCompositeUtils::Decision
xAOD::TrigComposite Decision
Definition: Event/xAOD/xAODTrigger/xAODTrigger/TrigComposite.h:20
xAOD::TrigComposite_v1::index_type
uint32_t index_type
Definition: TrigComposite_v1.h:56
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
TrigCompositeUtils::NavGraph::m_nodePositionMap
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
DeMoScan.index
string index
Definition: DeMoScan.py:364
TrigCompositeUtils::NavGraph::m_finalNodes
std::vector< NavGraphNode * > m_finalNodes
Entry points into the navigation graph.
Definition: NavGraph.h:213
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
TrigCompositeUtils::roiString
const std::string & roiString()
Definition: TrigCompositeUtilsRoot.cxx:876
TrigCompositeUtils::viewString
const std::string & viewString()
Definition: TrigCompositeUtilsRoot.cxx:880
node
Definition: memory_hooks-stdcmalloc.h:74
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37