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 "TString.h"
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
55 ////////////////////////////////////////////////////////////////////////////
56 /// \brief Returns a static variable to allow each node to retrieve its counter
57 static unsigned int &GetStaticGlobalCounter()
58 {
59 static unsigned int sGlobalCounter = 1;
60 return sGlobalCounter;
61 }
62
63public:
64 ////////////////////////////////////////////////////////////////////////////
65 /// \brief Creates a node with a name and a counter
67
68 ////////////////////////////////////////////////////////////////////////////
69 /// \brief Resets the counter.
70 /// This is not strictly needed but guarantees that two consecutive request to the graph return the same result.
72
73 ////////////////////////////////////////////////////////////////////////////
74 /// \brief Appends a node on the head of the current node
75 void SetPrevNode(const std::shared_ptr<GraphNode> &node) { fPrevNode = node; }
76
77 ////////////////////////////////////////////////////////////////////////////
78 /// \brief Adds the column defined up to the node
79 void AddDefinedColumns(const std::vector<std::string> &columns) { fDefinedColumns = columns; }
80
81 ////////////////////////////////////////////////////////////////////////////
82 /// \brief Gets the column defined up to the node
83 std::vector<std::string> GetDefinedColumns() { return fDefinedColumns; }
84
85 ////////////////////////////////////////////////////////////////////////////
86 /// \brief Manually sets the counter to a node.
87 /// It is used by the root node to set its counter to zero.
88 void SetCounter(unsigned int counter) { fCounter = counter; }
89
90 ////////////////////////////////////////////////////////////////////////////
91 /// \brief Allows to stop the graph traversal when an explored node is encountered
92 void SetIsExplored(bool isExplored) { fIsExplored = isExplored; }
93
94 ////////////////////////////////////////////////////////////////////////////
95 /// \brief The node is considered just created
96 void SetIsNew(bool isNew) { fIsNew = isNew; }
97
98 bool GetIsNew() { return fIsNew; }
99
100 ////////////////////////////////////////////////////////////////////////////
101 /// \brief Gives a different shape based on the node type
102 void SetRoot()
103 {
104 fColor = "#e8f8fc";
105 fShape = "oval";
106 }
107
108 ////////////////////////////////////////////////////////////////////////////
109 /// \brief Gives a different shape based on the node type
111 {
112 fColor = "#c4cfd4";
113 fShape = "diamond";
114 }
115
116 ////////////////////////////////////////////////////////////////////////////
117 /// \brief Gives a different shape based on the node type
119 {
120 fColor = "#60aef3";
121 fShape = "oval";
122 }
123
124 ////////////////////////////////////////////////////////////////////////////
125 /// \brief Gives a different shape based on the node type
126 void SetRange()
127 {
128 fColor = "#6F4D8F";
129 fShape = "diamond";
130 }
131
132 ////////////////////////////////////////////////////////////////////////////
133 /// \brief Gives a different shape based on the node type
134 void SetAction(bool hasRun)
135 {
136 if (hasRun) {
137 fColor = "#baf1e5";
138 } else {
139 fColor = "#9cbbe5";
140 }
141 fShape = "box";
142 }
143};
144
145} // namespace GraphDrawing
146} // namespace RDF
147} // namespace Internal
148} // namespace ROOT
149
150#endif
char name[80]
Definition: TGX11.cxx:109
void SetDefine()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:118
void SetPrevNode(const std::shared_ptr< GraphNode > &node)
Appends a node on the head of the current node.
Definition: GraphNode.hxx:75
void SetIsExplored(bool isExplored)
Allows to stop the graph traversal when an explored node is encountered.
Definition: GraphNode.hxx:92
void AddDefinedColumns(const std::vector< std::string > &columns)
Adds the column defined up to the node.
Definition: GraphNode.hxx:79
void SetAction(bool hasRun)
Gives a different shape based on the node type.
Definition: GraphNode.hxx:134
void SetRoot()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:102
GraphNode(const std::string_view &name)
Creates a node with a name and a counter.
Definition: GraphNode.hxx:66
void SetIsNew(bool isNew)
The node is considered just created.
Definition: GraphNode.hxx:96
void SetRange()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:126
static unsigned int & GetStaticGlobalCounter()
Returns a static variable to allow each node to retrieve its counter.
Definition: GraphNode.hxx:57
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:110
void SetCounter(unsigned int counter)
Manually sets the counter to a node.
Definition: GraphNode.hxx:88
unsigned int fCounter
Nodes may share the same name (e.g.
Definition: GraphNode.hxx:42
static void ClearCounter()
Resets the counter.
Definition: GraphNode.hxx:71
std::vector< std::string > GetDefinedColumns()
Gets the column defined up to the node.
Definition: GraphNode.hxx:83
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
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21