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 "ROOT/RStringView.hxx"
18
19#include <iostream>
20
21namespace ROOT {
22namespace Internal {
23namespace RDF {
24namespace GraphDrawing {
25
26enum class ENodeType {
27 kAction,
28 kDefine,
29 kFilter,
30 kRange,
31 kRoot,
33};
34
36
37// clang-format off
38/**
39\class ROOT::Internal::RDF::GraphDrawing::GraphNode
40\ingroup dataframe
41\brief Class used to create the operation graph to be printed in the dot representation
42
43 This represent a single node of the overall graph. Each node maps the real RNode keeping just
44 the name and the columns defined up to that point.
45*/
46// clang-format on
47class GraphNode {
48 /// Nodes may share the same name (e.g. Filter). To manage this situation in dot, each node
49 /// is represented by an unique id.
50 unsigned int fID;
51
52 std::string fName, fColor, fShape;
53
54 /// Columns defined up to this node. By checking the defined columns between two consecutive
55 /// nodes, it is possible to know if there was some Define in between.
56 std::vector<std::string> fDefinedColumns;
57
58 std::shared_ptr<GraphNode> fPrevNode;
59
60 /// When the graph is reconstructed, the first time this node has been explored this flag
61 /// is set and it won't be explored anymore.
62 bool fIsExplored = false;
63
64 /// A just created node. This means that in no other exploration the node was already created
65 /// (this is needed because branches may share some common node).
66 bool fIsNew = true;
67
68 ////////////////////////////////////////////////////////////////////////////
69 /// \brief Gives a different shape based on the node type
70 void SetRoot()
71 {
72 fColor = "#f4b400";
73 fShape = "ellipse";
74 }
75
76 ////////////////////////////////////////////////////////////////////////////
77 /// \brief Gives a different shape based on the node type
78 void SetFilter()
79 {
80 fColor = "#0f9d58";
81 fShape = "hexagon";
82 }
83
84 ////////////////////////////////////////////////////////////////////////////
85 /// \brief Gives a different shape based on the node type
86 void SetDefine()
87 {
88 fColor = "#4285f4";
89 fShape = "ellipse";
90 }
91
92 ////////////////////////////////////////////////////////////////////////////
93 /// \brief Gives a different shape based on the node type
94 void SetRange()
95 {
96 fColor = "#9574b4";
97 fShape = "diamond";
98 }
99
100 ////////////////////////////////////////////////////////////////////////////
101 /// \brief Gives a different shape based on the node type
102 void SetAction(bool hasRun)
103 {
104 if (hasRun) {
105 fName += "\\n(already run)";
106 fColor = "#e6e5e6";
107 } else {
108 fColor = "#e47c7e";
109 }
110 fShape = "box";
111 }
112
113public:
114 ////////////////////////////////////////////////////////////////////////////
115 /// \brief Creates a node with a name
116 GraphNode(std::string_view name, unsigned int id, ENodeType t) : fID(id), fName(name)
117 {
118 switch (t) {
119 case ENodeType::kAction: SetAction(/*hasRun=*/false); break;
120 case ENodeType::kDefine: SetDefine(); break;
121 case ENodeType::kFilter: SetFilter(); break;
122 case ENodeType::kRange: SetRange(); break;
123 case ENodeType::kRoot: SetRoot(); break;
124 case ENodeType::kUsedAction: SetAction(/*hasRun=*/true); break;
125 };
126 }
127
128 ////////////////////////////////////////////////////////////////////////////
129 /// \brief Appends a node on the head of the current node
130 void SetPrevNode(const std::shared_ptr<GraphNode> &node) { fPrevNode = node; }
131
132 ////////////////////////////////////////////////////////////////////////////
133 /// \brief Adds the column defined up to the node
134 void AddDefinedColumns(const std::vector<std::string> &columns) { fDefinedColumns = columns; }
135
136 std::string GetColor() const { return fColor; }
137 unsigned int GetID() const { return fID; }
138 std::string GetName() const { return fName; }
139 std::string GetShape() const { return fShape; }
140 GraphNode *GetPrevNode() const { return fPrevNode.get(); }
141
142 ////////////////////////////////////////////////////////////////////////////
143 /// \brief Gets the column defined up to the node
144 const std::vector<std::string> &GetDefinedColumns() const { return fDefinedColumns; }
145
146 bool IsExplored() const { return fIsExplored; }
147 bool IsNew() const { return fIsNew; }
148
149 ////////////////////////////////////////////////////////////////////////////
150 /// \brief Allows to stop the graph traversal when an explored node is encountered
151 void SetExplored() { fIsExplored = true; }
152
153 ////////////////////////////////////////////////////////////////////////////
154 /// \brief Mark this node as "not newly created"
155 void SetNotNew() { fIsNew = false; }
156};
157
158} // namespace GraphDrawing
159} // namespace RDF
160} // namespace Internal
161} // namespace ROOT
162
163#endif
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
char name[80]
Definition TGX11.cxx:110
Helper class that provides the operation graph nodes.
Class used to create the operation graph to be printed in the dot representation.
Definition GraphNode.hxx:47
void SetDefine()
Gives a different shape based on the node type.
Definition GraphNode.hxx:86
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.
void AddDefinedColumns(const std::vector< std::string > &columns)
Adds the column defined up to the 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:70
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:94
unsigned int fID
Nodes may share the same name (e.g.
Definition GraphNode.hxx:50
std::vector< std::string > fDefinedColumns
Columns defined up to this node.
Definition GraphNode.hxx:56
void SetFilter()
Gives a different shape based on the node type.
Definition GraphNode.hxx:78
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:62
std::shared_ptr< GraphNode > fPrevNode
Definition GraphNode.hxx:58
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.