Logo ROOT  
Reference Guide
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
27
28// clang-format off
29/**
30\class ROOT::Internal::RDF::GraphNode
31\ingroup dataframe
32\brief Class used to create the operation graph to be printed in the dot representation
33
34 This represent a single node of the overall graph. Each node maps the real RNode keeping just
35 the name and the columns defined up to that point.
36*/
37// clang-format on
38class GraphNode {
39 friend class GraphCreatorHelper;
40
41private:
42 unsigned int fCounter; ///< Nodes may share the same name (e.g. Filter). To manage this situation in dot, each node
43 ///< is represented by an unique id.
44 std::string fName, fColor, fShape;
45 std::vector<std::string>
46 fDefinedColumns; ///< Columns defined up to this node. By checking the defined columns between two consecutive
47 ///< nodes, it is possible to know if there was some Define in between.
48 std::shared_ptr<GraphNode> fPrevNode;
49
50 bool fIsExplored = false; ///< When the graph is reconstructed, the first time this node has been explored this flag
51 ///< is set and it won't be explored anymore
52 bool fIsNew = true; ///< A just created node. This means that in no other exploration the node was already created
53 ///< (this is needed because branches may share some common node).
54
55public:
56 ////////////////////////////////////////////////////////////////////////////
57 /// \brief Creates a node with a name
59
60 ////////////////////////////////////////////////////////////////////////////
61 /// \brief Appends a node on the head of the current node
62 void SetPrevNode(const std::shared_ptr<GraphNode> &node) { fPrevNode = node; }
63
64 ////////////////////////////////////////////////////////////////////////////
65 /// \brief Adds the column defined up to the node
66 void AddDefinedColumns(const std::vector<std::string> &columns) { fDefinedColumns = columns; }
67
68 ////////////////////////////////////////////////////////////////////////////
69 /// \brief Gets the column defined up to the node
70 std::vector<std::string> GetDefinedColumns() { return fDefinedColumns; }
71
72 ////////////////////////////////////////////////////////////////////////////
73 /// \brief Manually sets the counter to a node.
74 /// It is used by the root node to set its counter to zero.
75 void SetCounter(unsigned int counter) { fCounter = counter; }
76
77 ////////////////////////////////////////////////////////////////////////////
78 /// \brief Allows to stop the graph traversal when an explored node is encountered
79 void SetIsExplored(bool isExplored) { fIsExplored = isExplored; }
80
81 ////////////////////////////////////////////////////////////////////////////
82 /// \brief The node is considered just created
83 void SetIsNew(bool isNew) { fIsNew = isNew; }
84
85 bool GetIsNew() { return fIsNew; }
86
87 ////////////////////////////////////////////////////////////////////////////
88 /// \brief Gives a different shape based on the node type
89 void SetRoot()
90 {
91 fColor = "#e8f8fc";
92 fShape = "oval";
93 }
94
95 ////////////////////////////////////////////////////////////////////////////
96 /// \brief Gives a different shape based on the node type
97 void SetFilter()
98 {
99 fColor = "#c4cfd4";
100 fShape = "diamond";
101 }
102
103 ////////////////////////////////////////////////////////////////////////////
104 /// \brief Gives a different shape based on the node type
106 {
107 fColor = "#60aef3";
108 fShape = "oval";
109 }
110
111 ////////////////////////////////////////////////////////////////////////////
112 /// \brief Gives a different shape based on the node type
113 void SetRange()
114 {
115 fColor = "#6F4D8F";
116 fShape = "diamond";
117 }
118
119 ////////////////////////////////////////////////////////////////////////////
120 /// \brief Gives a different shape based on the node type
121 void SetAction(bool hasRun)
122 {
123 if (hasRun) {
124 fColor = "#baf1e5";
125 } else {
126 fColor = "#9cbbe5";
127 }
128 fShape = "box";
129 }
130};
131
132} // namespace GraphDrawing
133} // namespace RDF
134} // namespace Internal
135} // namespace ROOT
136
137#endif
char name[80]
Definition: TGX11.cxx:110
void SetDefine()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:105
void SetPrevNode(const std::shared_ptr< GraphNode > &node)
Appends a node on the head of the current node.
Definition: GraphNode.hxx:62
void SetIsExplored(bool isExplored)
Allows to stop the graph traversal when an explored node is encountered.
Definition: GraphNode.hxx:79
void AddDefinedColumns(const std::vector< std::string > &columns)
Adds the column defined up to the node.
Definition: GraphNode.hxx:66
void SetAction(bool hasRun)
Gives a different shape based on the node type.
Definition: GraphNode.hxx:121
void SetRoot()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:89
GraphNode(const std::string_view &name)
Creates a node with a name.
Definition: GraphNode.hxx:58
void SetIsNew(bool isNew)
The node is considered just created.
Definition: GraphNode.hxx:83
void SetRange()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:113
std::vector< std::string > fDefinedColumns
Columns defined up to this node.
Definition: GraphNode.hxx:46
void SetFilter()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:97
void SetCounter(unsigned int counter)
Manually sets the counter to a node.
Definition: GraphNode.hxx:75
unsigned int fCounter
Nodes may share the same name (e.g.
Definition: GraphNode.hxx:42
std::vector< std::string > GetDefinedColumns()
Gets the column defined up to the node.
Definition: GraphNode.hxx:70
bool fIsExplored
When the graph is reconstructed, the first time this node has been explored this flag.
Definition: GraphNode.hxx:50
std::shared_ptr< GraphNode > fPrevNode
Definition: GraphNode.hxx:48
basic_string_view< char > string_view
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.