Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDFHelpers.cxx
Go to the documentation of this file.
1// Author: Stefan Wunsch, Enrico Guiraud CERN 09/2020
2
3/*************************************************************************
4 * Copyright (C) 1995-2020, 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#include "ROOT/RDFHelpers.hxx"
12#include "TROOT.h" // IsImplicitMTEnabled
13#include "TError.h" // Warning
14#include "RConfigure.h" // R__USE_IMT
15#ifdef R__USE_IMT
17#endif // R__USE_IMT
18
19#include <set>
20
22
23void ROOT::RDF::RunGraphs(std::vector<RResultHandle> handles)
24{
25 if (handles.empty()) {
26 Warning("RunGraphs", "Got an empty list of handles");
27 return;
28 }
29
30 // Check that there are results which have not yet been run
31 unsigned int nNotRun = 0;
32 for (const auto &h : handles) {
33 if (!h.IsReady())
34 nNotRun++;
35 }
36 if (nNotRun < handles.size()) {
37 Warning("RunGraphs", "Got %lu handles from which %lu link to results which are already ready.", handles.size(),
38 handles.size() - nNotRun);
39 return;
40 }
41 if (nNotRun == 0)
42 return;
43
44 // Find the unique event loops
45 auto sameGraph = [](const RResultHandle &a, const RResultHandle &b) { return a.fLoopManager < b.fLoopManager; };
46 std::set<RResultHandle, decltype(sameGraph)> s(handles.begin(), handles.end(), sameGraph);
47 std::vector<RResultHandle> uniqueLoops(s.begin(), s.end());
48
49 // Trigger the unique event loops
50 auto run = [](RResultHandle &h) { h.fLoopManager->Run(); };
51#ifdef R__USE_IMT
53 ROOT::TThreadExecutor{}.Foreach(run, uniqueLoops);
54 return;
55 }
56#endif // R__USE_IMT
57 for (auto &h : uniqueLoops)
58 run(h);
59}
#define b(i)
Definition RSha256.hxx:100
#define a(i)
Definition RSha256.hxx:99
#define h(i)
Definition RSha256.hxx:106
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:231
This class provides a simple interface to execute the same task multiple times in parallel threads,...
void Foreach(F func, unsigned nTimes, unsigned nChunks=0)
Execute a function without arguments several times in parallel, dividing the execution in nChunks.
void RunGraphs(std::vector< RResultHandle > handles)
Trigger the event loop of multiple RDataFrames concurrently.
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
Definition TROOT.cxx:556