Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
df010_trivialDataSource.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_dataframe
3/// \notebook -draw
4/// Use the "trivial data source", an example data source implementation.
5///
6/// This tutorial illustrates how use the RDataFrame in combination with a
7/// RDataSource. In this case we use a RTrivialDS, which is nothing more
8/// than a simple generator: it does not interface to any existing dataset.
9/// The RTrivialDS has a single column, col0, which has value n for entry n.
10/// The code for RTrivialDS is available at these links (header and source):
11/// - https://github.com/root-project/root/blob/master/tree/dataframe/src/RTrivialDS.cxx
12/// - https://github.com/root-project/root/blob/master/tree/dataframe/inc/ROOT/RTrivialDS.hxx
13///
14/// Note that RTrivialDS is only a demo data source implementation and superior alternatives
15/// typically exist for production use (e.g. constructing an empty RDataFrame as `RDataFrame(nEntries)`).
16///
17/// \macro_code
18///
19/// \date September 2017
20/// \author Danilo Piparo (CERN)
21
23{
24 auto nEvents = 128U;
25 auto d_s = ROOT::RDF::MakeTrivialDataFrame(nEvents);
26
27 /// Now we have a regular RDataFrame: the ingestion of data is delegated to
28 /// the RDataSource. At this point everything works as before.
29 auto h_s = d_s.Define("x", "1./(1. + col0)").Histo1D({"h_s", "h_s", 128, 0, .6}, "x");
30
31 /// Now we redo the same with a RDF from scratch and we draw the two histograms
32 ROOT::RDataFrame d(nEvents);
33
34 /// This lambda redoes what the RTrivialDS provides
35 auto g = []() {
36 static ULong64_t i = 0;
37 return i++;
38 };
39 auto h = d.Define("col0", g).Define("x", "1./(1. + col0)").Histo1D({"h", "h", 128, 0, .6}, "x");
40
41 auto c_s = new TCanvas();
42 c_s->SetLogy();
43 h_s->DrawClone();
44
45 auto c = new TCanvas();
46 c->SetLogy();
47 h->DrawClone();
48
49 return 0;
50}
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
#define g(i)
Definition RSha256.hxx:105
#define h(i)
Definition RSha256.hxx:106
unsigned long long ULong64_t
Definition RtypesCore.h:81
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTree,...
The Canvas class.
Definition TCanvas.h:23
RInterface< RDFDetail::RLoopManager > MakeTrivialDataFrame()
Make a RDF wrapping a RTrivialDS with infinite entries, for demo purposes.