Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
df010_trivialDataSource.py
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##
11## Note that RTrivialDS is only a demo data source implementation and superior alternatives
12## typically exist for production use (e.g. constructing an empty RDataFrame as `RDataFrame(nEntries)`).
13##
14## \macro_code
15##
16## \date September 2017
17## \author Danilo Piparo (CERN)
18
19import ROOT
20
21# Create the data frame
22MakeTrivialDataFrame = ROOT.RDF.MakeTrivialDataFrame
23
24nEvents = 128
25
26d_s = MakeTrivialDataFrame(nEvents)
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.
30h_s = d_s.Define("x", "1./(1. + col0)").Histo1D(("h_s", "h_s", 128, 0, .6), "x")
31
32c = ROOT.TCanvas()
33c.SetLogy()
34h_s.Draw()
35c.SaveAs("df010_trivialDataSource.png")
36
37print("Saved figure to df010_trivialDataSource.png")