Logo ROOT  
Reference Guide
df025_RNode.C File Reference

Detailed Description

Manipulate RDF objects in functions, loops and conditional branches.

View in nbviewer Open in SWAN Each RDataFrame object has its own type. It helps with performance, but sometimes it gets in the way of writing simple code that manages RDF objects. Luckily, every RDF object can be converted to the generic RNode type. This tutorial shows how to take advantage of RNode to easily manipulate RDataFrames.

/// A generic function that takes an RDF object and applies a string filter
ROOT::RDF::RNode AddFilter(ROOT::RDF::RNode node, string_view filterStr)
{
return node.Filter(filterStr);
}
void df025_RNode()
{
// Using the generic AddFilter helper function defined above: RNode in, RNode out
auto f1 = AddFilter(df, "rdfentry_ > 0");
auto f2 = f1.Filter([](ULong64_t e) { return e > 1; }, {"rdfentry_"});
// Conditionally applying a filter is simple with ROOT::RDF::RNode
bool someCondition = true;
auto maybe_filtered = ROOT::RDF::RNode(f2);
if (someCondition)
maybe_filtered = maybe_filtered.Filter("rdfentry_ > 3");
// Adding new columns with Define in a loop is simple thanks to ROOT::RDF::RNode
auto with_columns = ROOT::RDF::RNode(maybe_filtered);
for (auto i = 0; i < 3; ++i)
with_columns = with_columns.Define("x" + std::to_string(i), "42");
// RNodes can be used exactly like any other RDF object
std::cout << "Entries passing the selection: " << with_columns.Count().GetValue() << std::endl;
}
Entries passing the selection: 4
Date
June 2020
Author
Danilo Piparo

Definition in file df025_RNode.C.

e
#define e(i)
Definition: RSha256.hxx:121
basic_string_view
Definition: libcpp_string_view.h:199
ROOT::RDF::RInterface::Filter
RInterface< RDFDetail::RFilter< F, Proxied >, DS_t > Filter(F f, const ColumnNames_t &columns={}, std::string_view name="")
Append a filter to the call graph.
Definition: RInterface.hxx:187
ROOT::RDataFrame
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:42
ROOT::RDF::RNode
RInterface<::ROOT::Detail::RDF::RNodeBase, void > RNode
Definition: InterfaceUtils.hxx:54
ROOT::RDF::RInterface
The public interface to the RDataFrame federation of classes.
Definition: InterfaceUtils.hxx:53
ULong64_t
unsigned long long ULong64_t
Definition: RtypesCore.h:74
f1
TF1 * f1
Definition: legend1.C:11