{ "cells": [ { "cell_type": "markdown", "id": "27cf68cb", "metadata": {}, "source": [ "# df034_SaveGraph\n", "Basic SaveGraph usage.\n", "\n", "This tutorial shows how to use the SaveGraph action.\n", "SaveGraph inspects the sequence of RDataFrame actions.\n", "\n", "\n", "\n", "\n", "**Author:** Ivan Kabadzhov (CERN) \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:10 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "86d873fc", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:14.750328Z", "iopub.status.busy": "2026-05-19T20:10:14.750209Z", "iopub.status.idle": "2026-05-19T20:10:17.227036Z", "shell.execute_reply": "2026-05-19T20:10:17.226453Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "digraph {\n", "\t8 [label=\"Mean\", style=\"filled\", fillcolor=\"#e47c7e\", shape=\"box\"];\n", "\t6 [label=\"Filter_1_1\", style=\"filled\", fillcolor=\"#0f9d58\", shape=\"hexagon\"];\n", "\t7 [label=\"Define\\nBranch_1_1_def\", style=\"filled\", fillcolor=\"#4285f4\", shape=\"ellipse\"];\n", "\t3 [label=\"Filter_1\", style=\"filled\", fillcolor=\"#0f9d58\", shape=\"hexagon\"];\n", "\t4 [label=\"Define\\nBranch_1_def\", style=\"filled\", fillcolor=\"#4285f4\", shape=\"ellipse\"];\n", "\t5 [label=\"Define\\nRoot_def2\", style=\"filled\", fillcolor=\"#4285f4\", shape=\"ellipse\"];\n", "\t1 [label=\"Main_Filter\", style=\"filled\", fillcolor=\"#0f9d58\", shape=\"hexagon\"];\n", "\t2 [label=\"Define\\nRoot_def1\", style=\"filled\", fillcolor=\"#4285f4\", shape=\"ellipse\"];\n", "\t0 [label=\"Empty source\\nEntries: 1\", style=\"filled\", fillcolor=\"#f4b400\", shape=\"ellipse\"];\n", "\t6 -> 8;\n", "\t7 -> 6;\n", "\t3 -> 7;\n", "\t4 -> 3;\n", "\t5 -> 4;\n", "\t1 -> 5;\n", "\t2 -> 1;\n", "\t0 -> 2;\n", "}" ] } ], "source": [ "ROOT::RDataFrame rd1(1);\n", "auto rd2 = rd1.Define(\"Root_def1\", \"1\").Filter(\"Root_def1 < 2\", \"Main_Filter\").Define(\"Root_def2\", \"1\");\n", "\n", "auto branch1 = rd2.Define(\"Branch_1_def\", \"1\");\n", "auto branch2 = rd2.Define(\"Branch_2_def\", \"1\");\n", "\n", "ROOT::RDF::RResultPtr branch1_1 = branch1.Filter(\"Branch_1_def < 2\", \"Filter_1\")\n", " .Define(\"Branch_1_1_def\", \"1\")\n", " .Filter(\"1 == Branch_1_1_def % 2\", \"Filter_1_1\")\n", " .Mean(\"Branch_1_1_def\");\n", "\n", "ROOT::RDF::RResultPtr branch1_2 =\n", " branch1.Define(\"Branch_1_2_def\", \"1\").Filter(\"Branch_1_2_def < 2\", \"Filter_1_2\").Count();\n", "\n", "ROOT::RDF::RResultPtr branch2_1 = branch2.Filter(\"Branch_2_def < 2\", \"Filter_2\")\n", " .Define(\"Branch_2_1_def\", \"1\")\n", " .Define(\"Branch_2_2_def\", \"1\")\n", " .Filter(\"1 == Branch_2_1_def % 2\", \"Filter_2_1\")\n", " .Max(\"Branch_2_1_def\");\n", "\n", "ROOT::RDF::RResultPtr branch2_2 = branch2.Count();\n", "\n", "std::cout << ROOT::RDF::SaveGraph(branch1_1);\n", "ROOT::RDF::SaveGraph(rd1, /*output_file=*/\"rdf_savegraph_tutorial.dot\");" ] }, { "cell_type": "markdown", "id": "7b7292a9", "metadata": {}, "source": [ "SaveGraph produces content in the standard DOT file format\n", "(https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29): it can be converted to e.g. an image file\n", "using standard tools such as the `dot` CLI program." ] }, { "cell_type": "code", "execution_count": 2, "id": "1038f40b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:10:17.234946Z", "iopub.status.busy": "2026-05-19T20:10:17.234821Z", "iopub.status.idle": "2026-05-19T20:10:17.443697Z", "shell.execute_reply": "2026-05-19T20:10:17.442634Z" } }, "outputs": [], "source": [ "gSystem->Exec(\"dot -Tpng rdf_savegraph_tutorial.dot -o rdf_savegraph_tutorial.png\");" ] } ], "metadata": { "kernelspec": { "display_name": "ROOT C++", "language": "c++", "name": "root" }, "language_info": { "codemirror_mode": "text/x-c++src", "file_extension": ".C", "mimetype": " text/x-c++src", "name": "c++" } }, "nbformat": 4, "nbformat_minor": 5 }