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 <vector>
16#include <unordered_map>
17#include <memory>
18#include <ROOT/RDataFrame.hxx>
21
22namespace ROOT {
23namespace Detail {
24namespace RDF {
25class RDefineBase;
26class RFilterBase;
27class RRangeBase;
28} // namespace RDF
29} // namespace Detail
30
31namespace Internal {
32namespace RDF {
33class RColumnRegister;
34namespace GraphDrawing {
35
36std::shared_ptr<GraphNode> CreateDefineNode(const std::string &columnName,
37 const ROOT::Detail::RDF::RDefineBase *columnPtr,
38 std::unordered_map<void *, std::shared_ptr<GraphNode>> &visitedMap);
39
40std::shared_ptr<GraphNode> CreateFilterNode(const ROOT::Detail::RDF::RFilterBase *filterPtr,
41 std::unordered_map<void *, std::shared_ptr<GraphNode>> &visitedMap);
42
43std::shared_ptr<GraphNode> CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr,
44 std::unordered_map<void *, std::shared_ptr<GraphNode>> &visitedMap);
45
46// clang-format off
47/**
48\class ROOT::Internal::RDF::GraphCreatorHelper
49\ingroup dataframe
50\brief Helper class that provides the operation graph nodes.
51
52 This class is the single point from which graph nodes can be retrieved. Every time an object is created,
53 it clears the static members and starts again.
54 By asking this class to create a node, it will return an existing node if already created, otherwise a new one.
55*/
56// clang-format on
58private:
59 ////////////////////////////////////////////////////////////////////////////
60 /// \brief Map to keep track of visited nodes when constructing the computation graph (SaveGraph)
61 std::unordered_map<void *, std::shared_ptr<GraphNode>> fVisitedMap;
62
63 ////////////////////////////////////////////////////////////////////////////
64 /// \brief Starting from any leaf (Action, Filter, Range) it draws the dot representation of the branch.
65 std::string FromGraphLeafToDot(const GraphNode &leaf) const;
66
67 ////////////////////////////////////////////////////////////////////////////
68 /// \brief Starting by an array of leaves, it draws the entire graph.
69 std::string FromGraphActionsToDot(std::vector<std::shared_ptr<GraphNode>> leaves) const;
70
71public:
72 ////////////////////////////////////////////////////////////////////////////
73 /// \brief Starting from the root node, prints the entire graph.
74 std::string RepresentGraph(ROOT::RDataFrame &rDataFrame);
75
76 ////////////////////////////////////////////////////////////////////////////
77 /// \brief Starting from the root node, prints the entire graph.
78 std::string RepresentGraph(RLoopManager *rLoopManager);
79
80 ////////////////////////////////////////////////////////////////////////////
81 /// \brief Starting from a Filter or Range, prints the branch it belongs to
82 template <typename Proxied, typename DataSource>
84 {
85 auto loopManager = rInterface.GetLoopManager();
86 loopManager->Jit();
87
88 return FromGraphLeafToDot(*rInterface.GetProxiedPtr()->GetGraph(fVisitedMap));
89 }
90
91 ////////////////////////////////////////////////////////////////////////////
92 /// \brief Starting from an action, prints the branch it belongs to
93 template <typename T>
94 std::string RepresentGraph(const RResultPtr<T> &resultPtr)
95 {
96 auto loopManager = resultPtr.fLoopManager;
97
98 loopManager->Jit();
99
100 auto actionPtr = resultPtr.fActionPtr;
101 return FromGraphLeafToDot(*actionPtr->GetGraph(fVisitedMap));
102 }
103};
104
105} // namespace GraphDrawing
106} // namespace RDF
107} // namespace Internal
108} // namespace ROOT
109
110#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::string RepresentGraph(const RResultPtr< T > &resultPtr)
Starting from an action, prints the branch it belongs to.
std::string RepresentGraph(RInterface< Proxied, DataSource > &rInterface)
Starting from a Filter or Range, prints the branch it belongs to.
std::string FromGraphLeafToDot(const GraphNode &leaf) const
Starting from any leaf (Action, Filter, Range) it draws the dot representation of the branch.
std::string RepresentGraph(ROOT::RDataFrame &rDataFrame)
Starting from the root node, prints the entire graph.
std::string FromGraphActionsToDot(std::vector< std::shared_ptr< GraphNode > > leaves) const
Starting by an array of leaves, it draws the entire graph.
std::unordered_map< void *, std::shared_ptr< GraphNode > > fVisitedMap
Map to keep track of visited nodes when constructing the computation graph (SaveGraph)
Class used to create the operation graph to be printed in the dot representation.
Definition GraphNode.hxx:47
RDFDetail::RLoopManager * GetLoopManager() const
The public interface to the RDataFrame federation of classes.
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 modern, high-level interface for analysis of data stored in TTree ,...
std::shared_ptr< GraphNode > CreateFilterNode(const ROOT::Detail::RDF::RFilterBase *filterPtr, std::unordered_map< void *, std::shared_ptr< GraphNode > > &visitedMap)
std::shared_ptr< GraphNode > CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr, std::unordered_map< void *, std::shared_ptr< GraphNode > > &visitedMap)
std::shared_ptr< GraphNode > CreateDefineNode(const std::string &columnName, const ROOT::Detail::RDF::RDefineBase *columnPtr, std::unordered_map< void *, std::shared_ptr< GraphNode > > &visitedMap)
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.