From 198bbaf961515cc3cd4ab8888eed1ddfff156b1d Mon Sep 17 00:00:00 2001
From: Danilo Piparo <danilo.piparo@cern.ch>
Date: Mon, 3 Dec 2018 14:07:22 +0100
Subject: [PATCH] [DF] Simplify the CreateSnaphotRDF helper function

  1. No need to make it a friend
  2. No need for the ABI compatibility workaround. Now this is in a library and not interpreted.
---
 tree/dataframe/inc/ROOT/RDF/InterfaceUtils.hxx |  4 ++--
 tree/dataframe/inc/ROOT/RDF/RInterface.hxx     | 10 +---------
 tree/dataframe/src/RDFInterfaceUtils.cxx       | 17 ++++-------------
 3 files changed, 7 insertions(+), 24 deletions(-)

diff --git a/tree/dataframe/inc/ROOT/RDF/InterfaceUtils.hxx b/tree/dataframe/inc/ROOT/RDF/InterfaceUtils.hxx
index 947dd4988f1..c9e7279af29 100644
--- a/tree/dataframe/inc/ROOT/RDF/InterfaceUtils.hxx
+++ b/tree/dataframe/inc/ROOT/RDF/InterfaceUtils.hxx
@@ -81,8 +81,8 @@ bool IsImplicitMTEnabled();
 
 using HeadNode_t = ::ROOT::RDF::RResultPtr<RInterface<RLoopManager, void>>;
 HeadNode_t CreateSnaphotRDF(const ColumnNames_t &validCols,
-                            const std::string &fullTreeName,
-                            const std::string &fileName,
+                            std::string_view treeName,
+                            std::string_view fileName,
                             bool isLazy,
                             RLoopManager &loopManager,
                             std::unique_ptr<RDFInternal::RActionBase> actionPtr);
diff --git a/tree/dataframe/inc/ROOT/RDF/RInterface.hxx b/tree/dataframe/inc/ROOT/RDF/RInterface.hxx
index e7cfddf587d..18a2c464e8b 100644
--- a/tree/dataframe/inc/ROOT/RDF/RInterface.hxx
+++ b/tree/dataframe/inc/ROOT/RDF/RInterface.hxx
@@ -91,14 +91,6 @@ class RInterface {
    friend std::string cling::printValue(::ROOT::RDataFrame *tdf); // For a nice printing at the prompt
    friend class RDFInternal::GraphDrawing::GraphCreatorHelper;
 
-   using HeadNode_t = ::ROOT::RDF::RResultPtr<RInterface<RLoopManager, void>>;
-   friend HeadNode_t RDFInternal::CreateSnaphotRDF(const ColumnNames_t &validCols,
-                                                   const std::string &fullTreeName,
-                                                   const std::string &fileName,
-                                                   bool isLazy,
-                                                   RLoopManager &loopManager,
-                                                   std::unique_ptr<RDFInternal::RActionBase> actionPtr);
-
    template <typename T, typename W>
    friend class RInterface;
 
@@ -2061,7 +2053,7 @@ private:
 
       fLoopManager->Book(actionPtr.get());
 
-      return RDFInternal::CreateSnaphotRDF(validCols, fullTreename, std::string(filename), options.fLazy, *fLoopManager, std::move(actionPtr));
+      return RDFInternal::CreateSnaphotRDF(validCols, fullTreename, filename, options.fLazy, *fLoopManager, std::move(actionPtr));
    }
 
    ////////////////////////////////////////////////////////////////////////////
diff --git a/tree/dataframe/src/RDFInterfaceUtils.cxx b/tree/dataframe/src/RDFInterfaceUtils.cxx
index 274b04cddf7..d6086520941 100644
--- a/tree/dataframe/src/RDFInterfaceUtils.cxx
+++ b/tree/dataframe/src/RDFInterfaceUtils.cxx
@@ -9,6 +9,7 @@
  *************************************************************************/
 
 #include <ROOT/RDF/InterfaceUtils.hxx>
+#include <ROOT/RDataFrame.hxx>
 #include <ROOT/RDF/RInterface.hxx>
 #include <ROOT/RStringView.hxx>
 #include <ROOT/TSeq.hxx>
@@ -74,25 +75,15 @@ bool IsImplicitMTEnabled()
 }
 
 HeadNode_t CreateSnaphotRDF(const ColumnNames_t &validCols,
-                            const std::string &fullTreeName,
-                            const std::string &fileName,
+                            std::string_view treeName,
+                            std::string_view fileName,
                             bool isLazy,
                             RLoopManager &loopManager,
                             std::unique_ptr<RDFInternal::RActionBase> actionPtr)
 {
    // create new RDF
    ::TDirectory::TContext ctxt;
-   // Now we mimic a constructor for the RDataFrame. We cannot invoke it here
-   // since this would introduce a cyclic headers dependency.
-
-   // Keep these two statements separated to work-around an ABI incompatibility
-   // between clang (and thus cling) and gcc in the way std::forward is handled.
-   // See https://sft.its.cern.ch/jira/browse/ROOT-9236 for more detail.
-   auto rlm_ptr = std::make_shared<RLoopManager>(nullptr, validCols);
-   auto snapshotRDF = std::make_shared<RInterface<RLoopManager>>(rlm_ptr);
-   auto chain = std::make_shared<TChain>(fullTreeName.c_str());
-   chain->Add(std::string(fileName).c_str());
-   snapshotRDF->fProxiedPtr->SetTree(chain);
+   auto snapshotRDF = std::make_shared<ROOT::RDataFrame>(treeName, fileName, validCols);
    auto snapshotRDFResPtr = MakeResultPtr(snapshotRDF, loopManager, std::move(actionPtr));
 
    if (!isLazy) {
-- 
GitLab