Basic SaveGraph usage.
This tutorial shows how to use the SaveGraph action. SaveGraph inspects the sequence of RDataFrame actions.
Author: Ivan Kabadzhov (CERN)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, April 17, 2024 at 11:07 AM.
ROOT::RDataFrame rd1(1);
auto rd2 = rd1.Define("Root_def1", "1").Filter("Root_def1 < 2", "Main_Filter").Define("Root_def2", "1");
auto branch1 = rd2.Define("Branch_1_def", "1");
auto branch2 = rd2.Define("Branch_2_def", "1");
ROOT::RDF::RResultPtr<double> branch1_1 = branch1.Filter("Branch_1_def < 2", "Filter_1")
.Define("Branch_1_1_def", "1")
.Filter("1 == Branch_1_1_def % 2", "Filter_1_1")
.Mean("Branch_1_1_def");
ROOT::RDF::RResultPtr<unsigned long long> branch1_2 =
branch1.Define("Branch_1_2_def", "1").Filter("Branch_1_2_def < 2", "Filter_1_2").Count();
ROOT::RDF::RResultPtr<double> branch2_1 = branch2.Filter("Branch_2_def < 2", "Filter_2")
.Define("Branch_2_1_def", "1")
.Define("Branch_2_2_def", "1")
.Filter("1 == Branch_2_1_def % 2", "Filter_2_1")
.Max("Branch_2_1_def");
ROOT::RDF::RResultPtr<unsigned long long> branch2_2 = branch2.Count();
std::cout << ROOT::RDF::SaveGraph(branch1_1);
ROOT::RDF::SaveGraph(rd1, /*output_file=*/"rdf_savegraph_tutorial.dot");
digraph { 8 [label="Mean", style="filled", fillcolor="#e47c7e", shape="box"]; 6 [label="Filter_1_1", style="filled", fillcolor="#0f9d58", shape="hexagon"]; 7 [label="Define\nBranch_1_1_def", style="filled", fillcolor="#4285f4", shape="ellipse"]; 3 [label="Filter_1", style="filled", fillcolor="#0f9d58", shape="hexagon"]; 4 [label="Define\nBranch_1_def", style="filled", fillcolor="#4285f4", shape="ellipse"]; 5 [label="Define\nRoot_def2", style="filled", fillcolor="#4285f4", shape="ellipse"]; 1 [label="Main_Filter", style="filled", fillcolor="#0f9d58", shape="hexagon"]; 2 [label="Define\nRoot_def1", style="filled", fillcolor="#4285f4", shape="ellipse"]; 0 [label="Empty source\nEntries: 1", style="filled", fillcolor="#f4b400", shape="ellipse"]; 6 -> 8; 7 -> 6; 3 -> 7; 4 -> 3; 5 -> 4; 1 -> 5; 2 -> 1; 0 -> 2; }
SaveGraph produces content in the standard DOT file format
(https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29): it can be converted to e.g. an image file
using standard tools such as the dot
CLI program.
gSystem->Exec("dot -Tpng rdf_savegraph_tutorial.dot -o rdf_savegraph_tutorial.png");