Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
GraphUtils.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_GRAPHUTILS
12#define ROOT_GRAPHUTILS
13
14#include <string>
15#include <sstream>
16#include <vector>
17#include <map>
18#include <memory>
19#include <type_traits>
20#include <ROOT/RDataFrame.hxx>
23
24#include <iostream>
25
26namespace ROOT {
27namespace Detail {
28namespace RDF {
29class RDefineBase;
30class RFilterBase;
31class RRangeBase;
32} // namespace RDF
33} // namespace Detail
34
35namespace Internal {
36namespace RDF {
37class RColumnRegister;
38
39namespace GraphDrawing {
40std::shared_ptr<GraphNode>
41CreateDefineNode(const std::string &columnName, const ROOT::Detail::RDF::RDefineBase *columnPtr);
42
43std::shared_ptr<GraphNode> CreateFilterNode(const ROOT::Detail::RDF::RFilterBase *filterPtr);
44
45std::shared_ptr<GraphNode> CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr);
46
47
48/// Add the Defines that have been added between this node and the previous to the graph.
49/// Return the new "upmost" node, i.e. the last of the Defines added if any, otherwise the node itself
50std::shared_ptr<GraphNode> AddDefinesToGraph(std::shared_ptr<GraphNode> node, const RColumnRegister &colRegister,
51 const std::vector<std::string> &prevNodeDefines);
52
53// clang-format off
54/**
55\class ROOT::Internal::RDF::GraphCreatorHelper
56\ingroup dataframe
57\brief Helper class that provides the operation graph nodes.
58
59 This class is the single point from which graph nodes can be retrieved. Every time an object is created,
60 it clears the static members and starts again.
61 By asking this class to create a node, it will return an existing node if already created, otherwise a new one.
62*/
63// clang-format on
65private:
66 using DefinesNodesMap_t = std::map<const ROOT::Detail::RDF::RDefineBase *, std::weak_ptr<GraphNode>>;
67 using FiltersNodesMap_t = std::map<const ROOT::Detail::RDF::RFilterBase *, std::weak_ptr<GraphNode>>;
68 using RangesNodesMap_t = std::map<const ROOT::Detail::RDF::RRangeBase *, std::weak_ptr<GraphNode>>;
69
70 ////////////////////////////////////////////////////////////////////////////
71 /// \brief Stores the columns defined and which node in the graph defined them.
73 {
74 static DefinesNodesMap_t sMap;
75 return sMap;
76 };
77
78 ////////////////////////////////////////////////////////////////////////////
79 /// \brief Stores the filters defined and which node in the graph defined them.
81 {
82 static FiltersNodesMap_t sMap;
83 return sMap;
84 }
85
86 ////////////////////////////////////////////////////////////////////////////
87 /// \brief Stores the ranges defined and which node in the graph defined them.
89 {
90 static RangesNodesMap_t sMap;
91 return sMap;
92 }
93
94 ////////////////////////////////////////////////////////////////////////////
95 /// \brief Invoked by the RNodes to create a define graph node.
96 friend std::shared_ptr<GraphNode>
97 CreateDefineNode(const std::string &columnName, const ROOT::Detail::RDF::RDefineBase *columnPtr);
98
99 ////////////////////////////////////////////////////////////////////////////
100 /// \brief Invoked by the RNodes to create a Filter graph node.
101 friend std::shared_ptr<GraphNode> CreateFilterNode(const ROOT::Detail::RDF::RFilterBase *filterPtr);
102
103 ////////////////////////////////////////////////////////////////////////////
104 /// \brief Invoked by the RNodes to create a Range graph node.
105 friend std::shared_ptr<GraphNode> CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr);
106
107 ////////////////////////////////////////////////////////////////////////////
108 /// \brief Starting from any leaf (Action, Filter, Range) it draws the dot representation of the branch.
109 std::string FromGraphLeafToDot(std::shared_ptr<GraphNode> leaf);
110
111 ////////////////////////////////////////////////////////////////////////////
112 /// \brief Starting by an array of leaves, it draws the entire graph.
113 std::string FromGraphActionsToDot(std::vector<std::shared_ptr<GraphNode>> leaves);
114
115 ////////////////////////////////////////////////////////////////////////////
116 /// \brief Starting from the root node, prints the entire graph.
117 std::string RepresentGraph(ROOT::RDataFrame &rDataFrame);
118
119 ////////////////////////////////////////////////////////////////////////////
120 /// \brief Starting from the root node, prints the entire graph.
121 std::string RepresentGraph(RLoopManager *rLoopManager);
122
123 ////////////////////////////////////////////////////////////////////////////
124 /// \brief Starting from a Filter or Range, prints the branch it belongs to
125 template <typename Proxied, typename DataSource>
127 {
128 auto loopManager = rInterface.GetLoopManager();
129 loopManager->Jit();
130
131 return FromGraphLeafToDot(rInterface.GetProxiedPtr()->GetGraph());
132 }
133
134 ////////////////////////////////////////////////////////////////////////////
135 /// \brief Starting from an action, prints the branch it belongs to
136 template <typename T>
137 std::string RepresentGraph(const RResultPtr<T> &resultPtr)
138 {
139 auto loopManager = resultPtr.fLoopManager;
140
141 loopManager->Jit();
142
143 auto actionPtr = resultPtr.fActionPtr;
144 return FromGraphLeafToDot(actionPtr->GetGraph());
145 }
146
147public:
148 ////////////////////////////////////////////////////////////////////////////
149 /// \brief Functor. Initializes the static members and delegates the work to the right override.
150 /// \tparam NodeType the RNode from which the graph has to be drawn
151 template <typename NodeType>
152 std::string operator()(NodeType &node)
153 {
154 // First all static data structures are cleaned, to avoid undefined behaviours if more than one Represent is
155 // called
160 // The Represent can now start on a clean environment
161 return RepresentGraph(node);
162 }
163};
164
165} // namespace GraphDrawing
166} // namespace RDF
167} // namespace Internal
168} // namespace ROOT
169
170#endif
The head node of a RDF computation graph.
void Jit()
Add RDF nodes that require just-in-time compilation to the computation graph.
std::map< const ROOT::Detail::RDF::RFilterBase *, std::weak_ptr< GraphNode > > FiltersNodesMap_t
std::string operator()(NodeType &node)
Functor.
static FiltersNodesMap_t & GetStaticFiltersMap()
Stores the filters defined and which node in the graph defined them.
std::string RepresentGraph(const RResultPtr< T > &resultPtr)
Starting from an action, prints the branch it belongs to.
static DefinesNodesMap_t & GetStaticColumnsMap()
Stores the columns defined and which node in the graph defined them.
friend std::shared_ptr< GraphNode > CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr)
Invoked by the RNodes to create a Range graph node.
friend std::shared_ptr< GraphNode > CreateDefineNode(const std::string &columnName, const ROOT::Detail::RDF::RDefineBase *columnPtr)
Invoked by the RNodes to create a define graph node.
std::string FromGraphLeafToDot(std::shared_ptr< GraphNode > leaf)
Starting from any leaf (Action, Filter, Range) it draws the dot representation of the branch.
std::string FromGraphActionsToDot(std::vector< std::shared_ptr< GraphNode > > leaves)
Starting by an array of leaves, it draws the entire graph.
std::map< const ROOT::Detail::RDF::RRangeBase *, std::weak_ptr< GraphNode > > RangesNodesMap_t
std::string RepresentGraph(RInterface< Proxied, DataSource > &rInterface)
Starting from a Filter or Range, prints the branch it belongs to.
std::string RepresentGraph(ROOT::RDataFrame &rDataFrame)
Starting from the root node, prints the entire graph.
friend std::shared_ptr< GraphNode > CreateFilterNode(const ROOT::Detail::RDF::RFilterBase *filterPtr)
Invoked by the RNodes to create a Filter graph node.
std::map< const ROOT::Detail::RDF::RDefineBase *, std::weak_ptr< GraphNode > > DefinesNodesMap_t
static RangesNodesMap_t & GetStaticRangesMap()
Stores the ranges defined and which node in the graph defined them.
static void ClearCounter()
Resets the counter.
Definition GraphNode.hxx:71
The public interface to the RDataFrame federation of classes.
RLoopManager * GetLoopManager() const
const std::shared_ptr< Proxied > & GetProxiedPtr() const
Smart pointer for the return type of actions.
RDFDetail::RLoopManager * fLoopManager
Non-owning pointer to the RLoopManager at the root of this computation graph.
std::shared_ptr< RDFInternal::RActionBase > fActionPtr
Owning pointer to the action that will produce this result.
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTree,...
std::shared_ptr< GraphNode > CreateDefineNode(const std::string &columnName, const ROOT::Detail::RDF::RDefineBase *columnPtr)
std::shared_ptr< GraphNode > CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr)
std::shared_ptr< GraphNode > AddDefinesToGraph(std::shared_ptr< GraphNode > node, const RColumnRegister &colRegister, const std::vector< std::string > &prevNodeDefines)
Add the Defines that have been added between this node and the previous to the graph.
std::shared_ptr< GraphNode > CreateFilterNode(const ROOT::Detail::RDF::RFilterBase *filterPtr)
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...