ATLAS Offline Software
Loading...
Searching...
No Matches
GraphBase.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef HYPERANALYSISALGORITHMS_GRAPHBASE_H
6#define HYPERANALYSISALGORITHMS_GRAPHBASE_H
7
9
10#include <cstdint>
11#include <utility>
12#include <vector>
13
14namespace EventReco {
15// Define some types used across the graph.
16using Features = std::vector<float>;
17using EdgeIndex = std::pair<int64_t, int64_t>;
18// @class Node
19// @brief This class stores a node in the graph.
20class Node {
21 public:
22 Node() = default;
23 Node(const Features& attributes, int64_t nodeIndex)
24 : m_nodeFeatures(attributes), m_nodeIndex(nodeIndex) {};
25 const Features& getFeatures() const { return m_nodeFeatures; };
27 int64_t getNodeIndex() const { return m_nodeIndex; };
28
29 private:
31 int64_t m_nodeIndex = -1;
32};
33// @class Edge
34// @brief This class stores an edge in the graph.
35class Edge {
36 public:
37 Edge() = default;
38 Edge(int64_t source, int64_t target, const Features& attributes)
39 : m_edgeFeatures(attributes),
40 m_edgeIndex(std::make_pair(source, target)) {};
41 const Features& getFeatures() const { return m_edgeFeatures; };
42 EdgeIndex getIndices() const { return m_edgeIndex; };
43
44 private:
47};
48// @class Global
49// @brief This class stores the global features of the graph.
50class Global {
51 public:
52 Global() = default;
53 Global(const Features& attributes) : m_globalFeatures(attributes) {};
54 const Features& getFeatures() const { return m_globalFeatures; };
55
56 private:
58};
59
60// @class GraphBase
61// @brief This class is the base class for the graph objects.
62// It represents a graph on an event by event basis.
63// It is used to store the graph structure and features of the graph.
64// Used for evaluation.
65class GraphBase {
66 public:
67 GraphBase() = default;
68 // Methods to build the graph
69 virtual void addNode(const Features& attributes) = 0;
70 virtual void addEdge(int64_t source, int64_t target,
71 const Features& attributes) = 0;
72 virtual void addGlobal(const Features& attributes) = 0;
73 // Methods to get the graph features
74 Features getNodeFeats(std::size_t index) const {
75 return m_nodes[index].getFeatures();
76 };
77 Features& getNodeFeats(std::size_t index) {
78 return m_nodes[index].getFeatures();
79 };
80 Features getEdgeFeats(std::size_t index) const {
81 return m_edges[index].getFeatures();
82 };
83 Features getGlobalFeats() const { return m_global.getFeatures(); };
85 return m_edges[index].getIndices();
86 };
87
88 int64_t nNodes() const { return m_nNodes; };
89 int64_t nEdges() const { return m_nEdges; };
90 int64_t nGlobal() const { return m_global.getFeatures().size(); };
91
92 protected:
94 std::vector<Node> m_nodes;
95 std::vector<Edge> m_edges;
96 int64_t m_nNodes = 0;
97 int64_t m_nEdges = 0;
98};
99} // namespace EventReco
100
101#endif // HYPERANALYSISALGORITHMS_GRAPHBASE_H
Edge(int64_t source, int64_t target, const Features &attributes)
Definition GraphBase.h:38
const Features & getFeatures() const
Definition GraphBase.h:41
EdgeIndex m_edgeIndex
Definition GraphBase.h:46
EdgeIndex getIndices() const
Definition GraphBase.h:42
Edge()=default
Features m_edgeFeatures
Definition GraphBase.h:45
const Features & getFeatures() const
Definition GraphBase.h:54
Global(const Features &attributes)
Definition GraphBase.h:53
Features m_globalFeatures
Definition GraphBase.h:57
EdgeIndex getEdgeIndicesVector(std::size_t index) const
Definition GraphBase.h:84
virtual void addGlobal(const Features &attributes)=0
std::vector< Node > m_nodes
Definition GraphBase.h:94
int64_t nNodes() const
Definition GraphBase.h:88
virtual void addNode(const Features &attributes)=0
Features getEdgeFeats(std::size_t index) const
Definition GraphBase.h:80
std::vector< Edge > m_edges
Definition GraphBase.h:95
Features getNodeFeats(std::size_t index) const
Definition GraphBase.h:74
Features & getNodeFeats(std::size_t index)
Definition GraphBase.h:77
Features getGlobalFeats() const
Definition GraphBase.h:83
virtual void addEdge(int64_t source, int64_t target, const Features &attributes)=0
int64_t nGlobal() const
Definition GraphBase.h:90
int64_t nEdges() const
Definition GraphBase.h:89
int64_t getNodeIndex() const
Definition GraphBase.h:27
const Features & getFeatures() const
Definition GraphBase.h:25
Features m_nodeFeatures
Definition GraphBase.h:30
int64_t m_nodeIndex
Definition GraphBase.h:31
Features & getFeatures()
Definition GraphBase.h:26
Node()=default
Node(const Features &attributes, int64_t nodeIndex)
Definition GraphBase.h:23
std::vector< float > Features
Definition GraphBase.h:16
std::pair< int64_t, int64_t > EdgeIndex
Definition GraphBase.h:17
Definition index.py:1
STL namespace.