Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
GraphNode.hxx
Go to the documentation of this file.
1// Author: Enrico Guiraud, Danilo Piparo, CERN, Massimo Tumolo Politecnico di Torino 08/2018
2
3/*************************************************************************
4 * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOT_RDF_GRAPHNODE
12#define ROOT_RDF_GRAPHNODE
13
14#include <string>
15#include <memory>
16#include <vector>
17#include <string_view>
18
19#include <iostream>
20
21namespace ROOT {
22namespace Internal {
23namespace RDF {
24namespace GraphDrawing {
25
34
36
37// clang-format off
38/**
39\class ROOT::Internal::RDF::GraphDrawing::GraphNode
40\brief Class used to create the operation graph to be printed in the dot representation
41
42 This represent a single node of the overall graph. Each node maps the real RNode keeping just
43 the name and the columns defined up to that point.
44*/
45// clang-format on
46class GraphNode {
47 /// Nodes may share the same name (e.g. Filter). To manage this situation in dot, each node
48 /// is represented by an unique id.
49 unsigned int fID;
50
51 std::string fName, fColor, fShape;
52
53 /// Columns defined up to this node. By checking the defined columns between two consecutive
54 /// nodes, it is possible to know if there was some Define in between.
55 std::vector<std::string> fDefinedColumns;
56
57 std::shared_ptr<GraphNode> fPrevNode;
58
59 /// When the graph is reconstructed, the first time this node has been explored this flag
60 /// is set and it won't be explored anymore.
61 bool fIsExplored = false;
62
63 /// A just created node. This means that in no other exploration the node was already created
64 /// (this is needed because branches may share some common node).
65 bool fIsNew = true;
66
67 ////////////////////////////////////////////////////////////////////////////
68 /// \brief Gives a different shape based on the node type
69 void SetRoot()
70 {
71 fColor = "#f4b400";
72 fShape = "ellipse";
73 }
74
75 ////////////////////////////////////////////////////////////////////////////
76 /// \brief Gives a different shape based on the node type
77 void SetFilter()
78 {
79 fColor = "#0f9d58";
80 fShape = "hexagon";
81 }
82
83 ////////////////////////////////////////////////////////////////////////////
84 /// \brief Gives a different shape based on the node type
85 void SetDefine()
86 {
87 fColor = "#4285f4";
88 fShape = "ellipse";
89 }
90
91 ////////////////////////////////////////////////////////////////////////////
92 /// \brief Gives a different shape based on the node type
93 void SetRange()
94 {
95 fColor = "#9574b4";
96 fShape = "diamond";
97 }
98
99 ////////////////////////////////////////////////////////////////////////////
100 /// \brief Gives a different shape based on the node type
101 void SetAction(bool hasRun)
102 {
103 if (hasRun) {
104 fName += "\\n(already run)";
105 fColor = "#e6e5e6";
106 } else {
107 fColor = "#e47c7e";
108 }
109 fShape = "box";
110 }
111
112public:
113 ////////////////////////////////////////////////////////////////////////////
114 /// \brief Creates a node with a name
115 GraphNode(std::string_view name, unsigned int id, ENodeType t) : fID(id), fName(name)
116 {
117 switch (t) {
118 case ENodeType::kAction: SetAction(/*hasRun=*/false); break;
119 case ENodeType::kDefine: SetDefine(); break;
120 case ENodeType::kFilter: SetFilter(); break;
121 case ENodeType::kRange: SetRange(); break;
122 case ENodeType::kRoot: SetRoot(); break;
123 case ENodeType::kUsedAction: SetAction(/*hasRun=*/true); break;
124 };
125 }
126
127 ////////////////////////////////////////////////////////////////////////////
128 /// \brief Appends a node on the head of the current node
129 void SetPrevNode(const std::shared_ptr<GraphNode> &node) { fPrevNode = node; }
130
131 ////////////////////////////////////////////////////////////////////////////
132 /// \brief Adds the column defined up to the node
133 void AddDefinedColumns(const std::vector<std::string_view> &columns)
134 {
135 // TODO: Converting the string_views for backward compatibility.
136 // Since they are names of defined columns, they were added to the
137 // register of column names of the RLoopManager object by the
138 // RColumnRegister, so we could also change fDefinedColumns to only
139 // store string_views
140 fDefinedColumns.clear();
141 fDefinedColumns.reserve(columns.size());
142 for (const auto &col : columns) {
143 fDefinedColumns.push_back(std::string(col));
144 };
145 }
146
147 std::string GetColor() const { return fColor; }
148 unsigned int GetID() const { return fID; }
149 std::string GetName() const { return fName; }
150 std::string GetShape() const { return fShape; }
151 GraphNode *GetPrevNode() const { return fPrevNode.get(); }
152
153 ////////////////////////////////////////////////////////////////////////////
154 /// \brief Gets the column defined up to the node
155 const std::vector<std::string> &GetDefinedColumns() const { return fDefinedColumns; }
156
157 bool IsExplored() const { return fIsExplored; }
158 bool IsNew() const { return fIsNew; }
159
160 ////////////////////////////////////////////////////////////////////////////
161 /// \brief Allows to stop the graph traversal when an explored node is encountered
162 void SetExplored() { fIsExplored = true; }
163
164 ////////////////////////////////////////////////////////////////////////////
165 /// \brief Mark this node as "not newly created"
166 void SetNotNew() { fIsNew = false; }
167};
168
169} // namespace GraphDrawing
170} // namespace RDF
171} // namespace Internal
172} // namespace ROOT
173
174#endif
XFontStruct * id
Definition TGX11.cxx:147
char name[80]
Definition TGX11.cxx:148
Helper class that provides the operation graph nodes.
void SetDefine()
Gives a different shape based on the node type.
Definition GraphNode.hxx:85
void SetExplored()
Allows to stop the graph traversal when an explored node is encountered.
void SetPrevNode(const std::shared_ptr< GraphNode > &node)
Appends a node on the head of the current node.
const std::vector< std::string > & GetDefinedColumns() const
Gets the column defined up to the node.
void SetAction(bool hasRun)
Gives a different shape based on the node type.
void SetRoot()
Gives a different shape based on the node type.
Definition GraphNode.hxx:69
GraphNode(std::string_view name, unsigned int id, ENodeType t)
Creates a node with a name.
void SetRange()
Gives a different shape based on the node type.
Definition GraphNode.hxx:93
unsigned int fID
Nodes may share the same name (e.g.
Definition GraphNode.hxx:49
void AddDefinedColumns(const std::vector< std::string_view > &columns)
Adds the column defined up to the node.
std::vector< std::string > fDefinedColumns
Columns defined up to this node.
Definition GraphNode.hxx:55
void SetFilter()
Gives a different shape based on the node type.
Definition GraphNode.hxx:77
void SetNotNew()
Mark this node as "not newly created".
bool fIsExplored
When the graph is reconstructed, the first time this node has been explored this flag is set and it w...
Definition GraphNode.hxx:61
std::shared_ptr< GraphNode > fPrevNode
Definition GraphNode.hxx:57