Skip to content

Commit cde1073

Browse files
committed
[df] Improve syntax for column definition in df001
The tutorial uses a C++ lambda with increment of a shared local variable between two different nodes of the computation graph, without explaining it. This is a somewhat advanced usage of the API for an introductory tutorial and is also in a seemingly irrelevant part of the tutorial (used just for creating the toy data). RDataFrame already provides the `rdfentry_` magic column which does effectively the same, providing a sequentially increasing number. Also, it was already used in the Python tutorial so this commit is just aligning the two language versions.
1 parent fe5c02d commit cde1073

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

tutorials/dataframe/df001_introduction.C

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@
2020
void fill_tree(const char *treeName, const char *fileName)
2121
{
2222
ROOT::RDataFrame d(10);
23-
int i(0);
24-
d.Define("b1", [&i]() { return (double)i; })
25-
.Define("b2",
26-
[&i]() {
27-
auto j = i * i;
28-
++i;
29-
return j;
30-
})
23+
d.Define("b1", [](ULong64_t entry) -> double { return entry; }, {"rdfentry_"})
24+
.Define("b2", [](ULong64_t entry) -> int { return entry * entry; }, {"rdfentry_"})
3125
.Snapshot(treeName, fileName);
3226
}
3327

tutorials/dataframe/df001_introduction.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
import ROOT
1717

18-
# A simple helper function to fill a test tree: this makes the example stand-alone.
1918
def fill_tree(treeName, fileName):
19+
"""A simple helper function to fill a test tree: this makes the example stand-alone."""
2020
df = ROOT.RDataFrame(10)
21-
df.Define("b1", "(double) rdfentry_")\
22-
.Define("b2", "(int) rdfentry_ * rdfentry_").Snapshot(treeName, fileName)
21+
df.Define("b1", "static_cast<double>(rdfentry_)")\
22+
.Define("b2", "static_cast<int>(rdfentry_ * rdfentry_)").Snapshot(treeName, fileName)
2323

2424
# We prepare an input tree to run on
2525
fileName = "df001_introduction_py.root"

0 commit comments

Comments
 (0)