Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:29:47

0001 // Author: Enrico Guiraud, Danilo Piparo, CERN, Massimo Tumolo Politecnico di Torino 08/2018
0002 
0003 /*************************************************************************
0004  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers.               *
0005  * All rights reserved.                                                  *
0006  *                                                                       *
0007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0009  *************************************************************************/
0010 
0011 #ifndef ROOT_GRAPHUTILS
0012 #define ROOT_GRAPHUTILS
0013 
0014 #include <ROOT/RDataFrame.hxx>
0015 #include <ROOT/RDF/RInterface.hxx>
0016 #include <ROOT/RDF/GraphNode.hxx>
0017 
0018 #include <string>
0019 #include <vector>
0020 #include <unordered_map>
0021 #include <memory>
0022 
0023 namespace ROOT {
0024 namespace Detail {
0025 namespace RDF {
0026 class RDefineBase;
0027 class RFilterBase;
0028 class RRangeBase;
0029 } // namespace RDF
0030 } // namespace Detail
0031 
0032 namespace Internal {
0033 namespace RDF {
0034 class RColumnRegister;
0035 namespace GraphDrawing {
0036 
0037 std::shared_ptr<GraphNode> CreateDefineNode(const std::string &columnName,
0038                                             const ROOT::Detail::RDF::RDefineBase *columnPtr,
0039                                             std::unordered_map<void *, std::shared_ptr<GraphNode>> &visitedMap);
0040 
0041 std::shared_ptr<GraphNode> CreateFilterNode(const ROOT::Detail::RDF::RFilterBase *filterPtr,
0042                                             std::unordered_map<void *, std::shared_ptr<GraphNode>> &visitedMap);
0043 
0044 std::shared_ptr<GraphNode> CreateRangeNode(const ROOT::Detail::RDF::RRangeBase *rangePtr,
0045                                            std::unordered_map<void *, std::shared_ptr<GraphNode>> &visitedMap);
0046 
0047 // clang-format off
0048 /**
0049 \class ROOT::Internal::RDF::GraphCreatorHelper
0050 \ingroup dataframe
0051 \brief Helper class that provides the operation graph nodes.
0052 
0053  This class is the single point from which graph nodes can be retrieved. Every time an object is created,
0054  it clears the static members and starts again.
0055  By asking this class to create a node, it will return an existing node if already created, otherwise a new one.
0056 */
0057 // clang-format on
0058 class GraphCreatorHelper {
0059 private:
0060    ////////////////////////////////////////////////////////////////////////////
0061    /// \brief Map to keep track of visited nodes when constructing the computation graph (SaveGraph)
0062    std::unordered_map<void *, std::shared_ptr<GraphNode>> fVisitedMap;
0063 
0064    ////////////////////////////////////////////////////////////////////////////
0065    /// \brief Starting from any leaf (Action, Filter, Range) it draws the dot representation of the branch.
0066    std::string FromGraphLeafToDot(const GraphNode &leaf) const;
0067 
0068    ////////////////////////////////////////////////////////////////////////////
0069    /// \brief Starting by an array of leaves, it draws the entire graph.
0070    std::string FromGraphActionsToDot(std::vector<std::shared_ptr<GraphNode>> leaves) const;
0071 
0072 public:
0073    ////////////////////////////////////////////////////////////////////////////
0074    /// \brief Starting from the root node, prints the entire graph.
0075    std::string RepresentGraph(ROOT::RDataFrame &rDataFrame);
0076 
0077    ////////////////////////////////////////////////////////////////////////////
0078    /// \brief Starting from the root node, prints the entire graph.
0079    std::string RepresentGraph(RLoopManager *rLoopManager);
0080 
0081    ////////////////////////////////////////////////////////////////////////////
0082    /// \brief Starting from a Filter or Range, prints the branch it belongs to
0083    template <typename Proxied, typename DataSource>
0084    std::string RepresentGraph(ROOT::RDF::RInterface<Proxied, DataSource> &rInterface)
0085    {
0086       auto loopManager = rInterface.GetLoopManager();
0087       loopManager->Jit();
0088 
0089       return FromGraphLeafToDot(*rInterface.GetProxiedPtr()->GetGraph(fVisitedMap));
0090    }
0091 
0092    ////////////////////////////////////////////////////////////////////////////
0093    /// \brief Starting from an action, prints the branch it belongs to
0094    template <typename T>
0095    std::string RepresentGraph(const ROOT::RDF::RResultPtr<T> &resultPtr)
0096    {
0097       auto loopManager = resultPtr.fLoopManager;
0098 
0099       loopManager->Jit();
0100 
0101       auto actionPtr = resultPtr.fActionPtr;
0102       return FromGraphLeafToDot(*actionPtr->GetGraph(fVisitedMap));
0103    }
0104 };
0105 
0106 } // namespace GraphDrawing
0107 } // namespace RDF
0108 } // namespace Internal
0109 } // namespace ROOT
0110 
0111 #endif