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 m_nodes.emplace_back(attributes, m_nNodes);
16 m_nNodes += 1;
17}
18
19void HyPERGraph::addEdge(int64_t source, int64_t target,
20 const Features& attributes) {
21 m_edges.emplace_back(source, target, attributes);
22 m_nEdges += 1;
23}
24
25void HyPERGraph::addGlobal(const Features& attributes) {
26 m_global = EventReco::Global(attributes);
27}
28
30 if (m_nNodes < 2) {
31 return; // There are no edges when the number of nodes is less than 2.
32 }
33 std::vector<int64_t> edgeIndices = range(m_nNodes);
34 for (const auto& index1 : edgeIndices) {
35 for (const auto& index2 : edgeIndices) {
36 if (index1 != index2)
37 m_edgeIndices.push_back(std::make_pair(index1, index2));
38 }
39 }
40}
41
42void HyPERGraph::buildHyperEdges(int64_t order) {
43 m_hyperEdgeOrder = order;
44 if (m_nNodes < order) {
45 return; // There are no hyperedges when the number of nodes is less than
46 // the hyperedge order.
47 }
48 std::vector<int64_t> edgeIndices = range(m_nNodes);
49 m_hyperEdgeIndices = buildCombinations(edgeIndices, order);
51}
52
54 using namespace asg::msgUserCode;
55 setMsgLevel(MSG::INFO);
56 ANA_MSG_INFO("Printing graph...");
57 // Print the nodes
58 for (const auto& node : m_nodes) {
59 ANA_MSG_INFO("Node Index: " << node.getNodeIndex());
60 for (const auto& feat : node.getFeatures()) {
61 ANA_MSG_INFO("Feature: " << feat);
62 }
63 }
64 // Print the edges
65 for (const auto& edge : m_edges) {
66 ANA_MSG_INFO("Edge Index: " << edge.getIndices().first << " -> "
67 << edge.getIndices().second);
68 for (const auto& feat : edge.getFeatures()) {
69 ANA_MSG_INFO("Feature: " << feat);
70 }
71 }
72 // Print the global
73 ANA_MSG_INFO("Global Features: ");
74 for (const auto& feat : m_global.getFeatures()) {
75 ANA_MSG_INFO("Feature: " << feat);
76 }
77 // Print the hyperedges
78 for (const auto& hyperEdge : m_hyperEdgeIndices) {
79 std::string indices{""};
80 for (const auto& index : hyperEdge) {
81 indices += std::to_string(index) + " ";
82 }
83 ANA_MSG_INFO("HyperEdge indices: " << indices);
84 }
85 ANA_MSG_INFO("Finished graph printing...");
86}
87
89 using namespace asg::msgUserCode;
90 setMsgLevel(MSG::INFO);
91 ANA_MSG_INFO("Printing graph inputs in validation mode...");
92
93 // Print the nodes
94 ANA_MSG_INFO("NODES:");
95 for (const auto& node : m_nodes) {
96 std::string row = "[";
97 for (const auto& feat : node.getFeatures()) {
98 row += std::to_string(feat) + ", ";
99 }
100 row += "],";
101 ANA_MSG_INFO(row);
102 }
103 // Print the edges
104 ANA_MSG_INFO("EDGES:");
105 for (const auto& edge : m_edges) {
106 std::string row = "[";
107 for (const auto& feat : edge.getFeatures()) {
108 row += std::to_string(feat) + ", ";
109 }
110 row += "],";
111 ANA_MSG_INFO(row);
112 }
113 // Print the edge indices
114 ANA_MSG_INFO("EDGE INDICES:");
115 std::string row1 = "[";
116 std::string row2 = "[";
117 for (const auto& edge : m_edges) {
118 row1 += std::to_string(edge.getIndices().first) + ", ";
119 row2 += std::to_string(edge.getIndices().second) + ", ";
120 }
121 row1 += "],";
122 row2 += "],";
123 ANA_MSG_INFO(row1);
124 ANA_MSG_INFO(row2);
125 // Print the globals
126 ANA_MSG_INFO("GLOBAL:");
127 std::string row = "[[";
128 for (const auto& feat : m_global.getFeatures()) {
129 row += std::to_string(feat) + ", ";
130 }
131 row += "]],";
132 ANA_MSG_INFO(row);
133 // Print batch
134 ANA_MSG_INFO("BATCH:");
135 row = "[[";
136 for (auto i{0}; i < this->nNodes(); i++) {
137 row += "0, ";
138 }
139 row += "]],";
140 ANA_MSG_INFO(row);
141 // Print the hyperedges
142 ANA_MSG_INFO("HYPEREDGE INDICES:");
143 std::vector<std::string> rows(this->hyperEdgeOrder());
144 for (auto i{0}; i < this->hyperEdgeOrder(); i++) {
145 rows[i] = "[";
146 }
147 for (const auto& hyperEdge : m_hyperEdgeIndices) {
148 for (auto i{0}; i < this->hyperEdgeOrder(); i++) {
149 rows[i] += std::to_string(hyperEdge[i]) + ", ";
150 }
151 }
152 for (auto i{0}; i < this->hyperEdgeOrder(); i++) {
153 rows[i] += "],";
154 ANA_MSG_INFO(rows[i]);
155 }
156 // Print batch hyperedges
157 ANA_MSG_INFO("BATCH HYPEREDGES:");
158 row = "[[";
159 for (auto i{0}; i < this->nHyperEdges(); i++) {
160 row += "0, ";
161 }
162 row += "]],";
163 ANA_MSG_INFO(row);
164
165 ANA_MSG_INFO("Finished printing graph inputs for validation...");
166}
167
169 m_nNodes = 0;
170 m_nEdges = 0;
171 m_nodes.clear();
172 m_edges.clear();
173 m_global = {};
174 m_edgeIndices = {};
177 m_nHyperEdges = 0;
178}
179
180} // 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:48
std::vector< float > Features
Definition GraphBase.h:16
std::vector< int64_t > range(int64_t n)
Definition index.py:1