ROOT
Version v6.34
master
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
df019_Cache.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_dataframe
3
## \notebook -draw
4
## Cache a processed RDataFrame in memory for further usage.
5
##
6
## This tutorial shows how the content of a data frame can be cached in memory
7
## in form of a dataframe. The content of the columns is stored in memory in
8
## contiguous slabs of memory and is "ready to use", i.e. no ROOT IO operation
9
## is performed.
10
##
11
## Creating a cached data frame storing all of its content deserialised and uncompressed
12
## in memory is particularly useful when dealing with datasets of a moderate size
13
## (small enough to fit the RAM) over which several explorative loops need to be
14
## performed as fast as possible. In addition, caching can be useful when no file
15
## on disk needs to be created as a side effect of checkpointing part of the analysis.
16
##
17
## All steps in the caching are lazy, i.e. the cached data frame is actually filled
18
## only when the event loop is triggered on it.
19
##
20
## \macro_code
21
## \macro_image
22
##
23
## \date June 2018
24
## \author Danilo Piparo (CERN)
25
26
import
ROOT
27
import
os
28
29
# We create a data frame on top of the hsimple example.
30
hsimplePath =
os.path.join
(str(
ROOT.gROOT.GetTutorialDir
().Data()),
"hsimple.root"
)
31
df =
ROOT.RDataFrame
(
"ntuple"
, hsimplePath)
32
33
# We apply a simple cut and define a new column.
34
df_cut =
df.Filter
(
"py > 0.f"
)\
35
.Define(
"px_plus_py"
,
"px + py"
)
36
37
# We cache the content of the dataset. Nothing has happened yet: the work to accomplish
38
# has been described.
39
df_cached =
df_cut.Cache
()
40
41
h =
df_cached.Histo1D
(
"px_plus_py"
)
42
43
# Now the event loop on the cached dataset is triggered by accessing the histogram.
44
# This event triggers the loop on the `df` data frame lazily.
45
c =
ROOT.TCanvas
()
46
h.Draw
()
47
c.SaveAs
(
"df019_Cache.png"
)
48
49
print(
"Saved figure to df019_Cache.png"
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
ROOT::RDataFrame
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Definition
RDataFrame.hxx:41
tutorials
dataframe
df019_Cache.py
ROOT tags/6-34-04 - Reference Guide Generated on Wed Mar 26 2025 04:46:23 (GVA Time) using Doxygen 1.10.0