Skip to content

Commit

Permalink
[df] Improve syntax for column definition in df001
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vepadulano committed Jun 10, 2024
1 parent fe5c02d commit cde1073
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 2 additions & 8 deletions tutorials/dataframe/df001_introduction.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,8 @@
void fill_tree(const char *treeName, const char *fileName)
{
ROOT::RDataFrame d(10);
int i(0);
d.Define("b1", [&i]() { return (double)i; })
.Define("b2",
[&i]() {
auto j = i * i;
++i;
return j;
})
d.Define("b1", [](ULong64_t entry) -> double { return entry; }, {"rdfentry_"})
.Define("b2", [](ULong64_t entry) -> int { return entry * entry; }, {"rdfentry_"})
.Snapshot(treeName, fileName);
}

Expand Down
6 changes: 3 additions & 3 deletions tutorials/dataframe/df001_introduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

import ROOT

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

# We prepare an input tree to run on
fileName = "df001_introduction_py.root"
Expand Down

0 comments on commit cde1073

Please sign in to comment.