Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:32

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