ATLAS Offline Software
Loading...
Searching...
No Matches
HyPERGraph.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#include <AsgMessaging/MessageCheck.h> // To access ANA_MSG
5
6#include <string>
7
9
12
13namespace EventReco {
14void HyPERGraph::addNode(const Features& attributes) {
15 EventReco::Node newNode(attributes, m_nNodes);
16 m_nodes.push_back(newNode);
17 m_nNodes += 1;
18}
19
20void HyPERGraph::addEdge(int64_t source, int64_t target,
21 const Features& attributes) {
22 EventReco::Edge newEdge(source, target, attributes);
23 m_edges.push_back(newEdge);
24 m_nEdges += 1;
25}
26
27void HyPERGraph::addGlobal(const Features& attributes) {
28 m_global = EventReco::Global(attributes);
29}
30
32 if (m_nNodes < 2) {
33 return; // There are no edges when the number of nodes is less than 2.
34 }
35 std::vector<int64_t> edgeIndices = range(m_nNodes);
36 for (const auto& index1 : edgeIndices) {
37 for (const auto& index2 : edgeIndices) {
38 if (index1 != index2)
39 m_edgeIndices.push_back(std::make_pair(index1, index2));
40 }
41 }
42}
43
44void HyPERGraph::buildHyperEdges(int64_t order) {
45 m_hyperEdgeOrder = order;
46 if (m_nNodes < order) {
47 return; // There are no hyperedges when the number of nodes is less than
48 // the hyperedge order.
49 }
50 std::vector<int64_t> edgeIndices = range(m_nNodes);
51 m_hyperEdgeIndices = buildCombinations(edgeIndices, order);
53}
54
56 using namespace asg::msgUserCode;
57 setMsgLevel(MSG::INFO);
58 ANA_MSG_INFO("Printing graph...");
59 // Print the nodes
60 for (const auto& node : m_nodes) {
61 ANA_MSG_INFO("Node Index: " << node.getNodeIndex());
62 for (const auto& feat : node.getFeatures()) {
63 ANA_MSG_INFO("Feature: " << feat);
64 }
65 }
66 // Print the edges
67 for (const auto& edge : m_edges) {
68 ANA_MSG_INFO("Edge Index: " << edge.getIndices().first << " -> "
69 << edge.getIndices().second);
70 for (const auto& feat : edge.getFeatures()) {
71 ANA_MSG_INFO("Feature: " << feat);
72 }
73 }
74 // Print the global
75 ANA_MSG_INFO("Global Features: ");
76 for (const auto& feat : m_global.getFeatures()) {
77 ANA_MSG_INFO("Feature: " << feat);
78 }
79 // Print the hyperedges
80 for (const auto& hyperEdge : m_hyperEdgeIndices) {
81 std::string indices{""};
82 for (const auto& index : hyperEdge) {
83 indices += std::to_string(index) + " ";
84 }
85 ANA_MSG_INFO("HyperEdge indices: " << indices);
86 }
87 ANA_MSG_INFO("Finished graph printing...");
88}
89
91 using namespace asg::msgUserCode;
92 setMsgLevel(MSG::INFO);
93 ANA_MSG_INFO("Printing graph inputs in validation mode...");
94
95 // Print the nodes
96 ANA_MSG_INFO("NODES:");
97 for (const auto& node : m_nodes) {
98 std::string row = "[";
99 for (const auto& feat : node.getFeatures()) {
100 row += std::to_string(feat) + ", ";
101 }
102 row += "],";
103 ANA_MSG_INFO(row);
104 }
105 // Print the edges
106 ANA_MSG_INFO("EDGES:");
107 for (const auto& edge : m_edges) {
108 std::string row = "[";
109 for (const auto& feat : edge.getFeatures()) {
110 row += std::to_string(feat) + ", ";
111 }
112 row += "],";
113 ANA_MSG_INFO(row);
114 }
115 // Print the edge indices
116 ANA_MSG_INFO("EDGE INDICES:");
117 std::string row1 = "[";
118 std::string row2 = "[";
119 for (const auto& edge : m_edges) {
120 row1 += std::to_string(edge.getIndices().first) + ", ";
121 row2 += std::to_string(edge.getIndices().second) + ", ";
122 }
123 row1 += "],";
124 row2 += "],";
125 ANA_MSG_INFO(row1);
126 ANA_MSG_INFO(row2);
127 // Print the globals
128 ANA_MSG_INFO("GLOBAL:");
129 std::string row = "[[";
130 for (const auto& feat : m_global.getFeatures()) {
131 row += std::to_string(feat) + ", ";
132 }
133 row += "]],";
134 ANA_MSG_INFO(row);
135 // Print batch
136 ANA_MSG_INFO("BATCH:");
137 row = "[[";
138 for (auto i{0}; i < this->nNodes(); i++) {
139 row += "0, ";
140 }
141 row += "]],";
142 ANA_MSG_INFO(row);
143 // Print the hyperedges
144 ANA_MSG_INFO("HYPEREDGE INDICES:");
145 std::vector<std::string> rows(this->hyperEdgeOrder());
146 for (auto i{0}; i < this->hyperEdgeOrder(); i++) {
147 rows[i] = "[";
148 }
149 for (const auto& hyperEdge : m_hyperEdgeIndices) {
150 for (auto i{0}; i < this->hyperEdgeOrder(); i++) {
151 rows[i] += std::to_string(hyperEdge[i]) + ", ";
152 }
153 }
154 for (auto i{0}; i < this->hyperEdgeOrder(); i++) {
155 rows[i] += "],";
156 ANA_MSG_INFO(rows[i]);
157 }
158 // Print batch hyperedges
159 ANA_MSG_INFO("BATCH HYPEREDGES:");
160 row = "[[";
161 for (auto i{0}; i < this->nHyperEdges(); i++) {
162 row += "0, ";
163 }
164 row += "]],";
165 ANA_MSG_INFO(row);
166
167 ANA_MSG_INFO("Finished printing graph inputs for validation...");
168}
169
171 m_nNodes = 0;
172 m_nEdges = 0;
173 m_nodes.clear();
174 m_edges.clear();
175 m_global = {};
176 m_edgeIndices = {};
179 m_nHyperEdges = 0;
180}
181
182} // namespace EventReco
macros for messaging and checking status codes
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
std::vector< std::vector< int64_t > > indices
std::vector< Node > m_nodes
Definition GraphBase.h:94
int64_t nNodes() const
Definition GraphBase.h:88
std::vector< Edge > m_edges
Definition GraphBase.h:95
std::vector< EdgeIndex > m_edgeIndices
Definition HyPERGraph.h:49
int64_t hyperEdgeOrder() const
Definition HyPERGraph.h:42
std::vector< HyperEdgeIndex > m_hyperEdgeIndices
Definition HyPERGraph.h:50
virtual void clearGraph()
virtual void addNode(const Features &attributes) override
virtual void addEdge(int64_t source, int64_t target, const Features &attributes) override
int64_t nHyperEdges() const
Definition HyPERGraph.h:41
void buildHyperEdges(int64_t order)
virtual void printGraphInputsForValidation() const
virtual void printGraph() const
virtual void addGlobal(const Features &attributes) override
Definition node.h:24
std::vector< std::vector< T > > buildCombinations(const std::vector< T > &elements, int64_t hyperEdgeOrder)
Definition HyPERUtils.h:47
std::vector< float > Features
Definition GraphBase.h:16
std::vector< int64_t > range(int64_t n)
Definition index.py:1