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_image
18/// \macro_code
19///
20/// \date September 2017
21/// \author Danilo Piparo (CERN)
22
23int df010_trivialDataSource()
24{
25 auto nEvents = 128U;
27
28 /// Now we have a regular RDataFrame: the ingestion of data is delegated to
29 /// the RDataSource. At this point everything works as before.
30 auto h_s = d_s.Define("x", "1./(1. + col0)").Histo1D({"h_s", "h_s", 128, 0, .6}, "x");
31
32 /// Now we redo the same with a RDF from scratch and we draw the two histograms
33 ROOT::RDataFrame d(nEvents);
34
35 /// This lambda redoes what the RTrivialDS provides
36 auto g = []() {
37 static ULong64_t i = 0;
38 return i++;
39 };
40 auto h = d.Define("col0", g).Define("x", "1./(1. + col0)").Histo1D({"h", "h", 128, 0, .6}, "x");
41
42 auto c_s = new TCanvas();
43 c_s->SetLogy();
44 h_s->DrawClone();
45
46 auto c = new TCanvas();
47 c->SetLogy();
48 h->DrawClone();
49
50 return 0;
51}
#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
Portable unsigned long integer 8 bytes.
Definition RtypesCore.h:85
ROOT's RDataFrame offers a modern, high-level interface for analysis 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.