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 
21 namespace ROOT {
22 namespace Internal {
23 namespace RDF {
24 namespace GraphDrawing {
25 
26 class GraphCreatorHelper;
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
38 class GraphNode {
39  friend class GraphCreatorHelper;
40 
41 private:
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 
63 public:
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
110  void SetFilter()
111  {
112  fColor = "#c4cfd4";
113  fShape = "diamond";
114  }
115 
116  ////////////////////////////////////////////////////////////////////////////
117  /// \brief Gives a different shape based on the node type
118  void SetDefine()
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
ROOT::Internal::RDF::GraphDrawing::GraphNode::fIsNew
bool fIsNew
A just created node.
Definition: GraphNode.hxx:52
ROOT::Internal::RDF::GraphDrawing::GraphNode::fColor
std::string fColor
Definition: GraphNode.hxx:44
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetDefine
void SetDefine()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:118
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetRoot
void SetRoot()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:102
ROOT::Internal::RDF::GraphDrawing::GraphNode::ClearCounter
static void ClearCounter()
Resets the counter.
Definition: GraphNode.hxx:71
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetIsNew
void SetIsNew(bool isNew)
The node is considered just created.
Definition: GraphNode.hxx:96
string_view
basic_string_view< char > string_view
Definition: libcpp_string_view.h:785
ROOT::Internal::RDF::GraphDrawing::GraphNode::AddDefinedColumns
void AddDefinedColumns(const std::vector< std::string > &columns)
Adds the column defined up to the node.
Definition: GraphNode.hxx:79
TString.h
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetRange
void SetRange()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:126
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetCounter
void SetCounter(unsigned int counter)
Manually sets the counter to a node.
Definition: GraphNode.hxx:88
ROOT::Internal::RDF::GraphDrawing::GraphNode::fPrevNode
std::shared_ptr< GraphNode > fPrevNode
Definition: GraphNode.hxx:48
ROOT::Internal::RDF::GraphDrawing::GraphCreatorHelper
Definition: GraphUtils.hxx:56
ROOT::Internal::RDF::GraphDrawing::GraphNode::GetIsNew
bool GetIsNew()
Definition: GraphNode.hxx:98
ROOT::Internal::RDF::GraphDrawing::GraphNode::GraphNode
GraphNode(const std::string_view &name)
Creates a node with a name and a counter.
Definition: GraphNode.hxx:66
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetIsExplored
void SetIsExplored(bool isExplored)
Allows to stop the graph traversal when an explored node is encountered.
Definition: GraphNode.hxx:92
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetPrevNode
void SetPrevNode(const std::shared_ptr< GraphNode > &node)
Appends a node on the head of the current node.
Definition: GraphNode.hxx:75
ROOT::Internal::RDF::GraphDrawing::GraphNode::fName
std::string fName
Definition: GraphNode.hxx:44
ROOT::Internal::RDF::GraphDrawing::GraphNode
Definition: GraphNode.hxx:38
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetFilter
void SetFilter()
Gives a different shape based on the node type.
Definition: GraphNode.hxx:110
ROOT::Internal::RDF::GraphDrawing::GraphNode::GetStaticGlobalCounter
static unsigned int & GetStaticGlobalCounter()
Returns a static variable to allow each node to retrieve its counter.
Definition: GraphNode.hxx:57
ROOT::Internal::RDF::GraphDrawing::GraphNode::fDefinedColumns
std::vector< std::string > fDefinedColumns
Columns defined up to this node.
Definition: GraphNode.hxx:46
ROOT::Internal::RDF::GraphDrawing::GraphNode::fCounter
unsigned int fCounter
Nodes may share the same name (e.g.
Definition: GraphNode.hxx:42
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Internal::RDF::GraphDrawing::GraphNode::SetAction
void SetAction(bool hasRun)
Gives a different shape based on the node type.
Definition: GraphNode.hxx:134
ROOT::Internal::RDF::GraphDrawing::GraphNode::fShape
std::string fShape
Definition: GraphNode.hxx:44
ROOT::Internal::RDF::GraphDrawing::GraphNode::fIsExplored
bool fIsExplored
When the graph is reconstructed, the first time this node has been explored this flag.
Definition: GraphNode.hxx:50
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Internal::RDF::GraphDrawing::GraphNode::GetDefinedColumns
std::vector< std::string > GetDefinedColumns()
Gets the column defined up to the node.
Definition: GraphNode.hxx:83