{ "cells": [ { "cell_type": "markdown", "id": "36174c26", "metadata": {}, "source": [ "# loopdir\n", "Example script to loop over all the objects of a ROOT file directory and print in\n", "Postscript all the TH1 derived objects.\n", "This script uses the file generated by tutorial hsimple.C\n", "\n", "\n", "\n", "\n", "**Author:** Rene Brun \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:14 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "4a1b3a06", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:14:28.517694Z", "iopub.status.busy": "2026-05-19T20:14:28.517563Z", "iopub.status.idle": "2026-05-19T20:14:29.131673Z", "shell.execute_reply": "2026-05-19T20:14:29.131139Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Info in : ps file hsimple.ps has been created\n", "Info in : Current canvas added to ps file hsimple.ps\n", "Info in : Current canvas added to ps file hsimple.ps\n", "Info in : Current canvas added to ps file hsimple.ps\n", "Info in : ps file hsimple.ps has been closed\n" ] } ], "source": [ "TFile *f1 = TFile::Open(\"hsimple.root\");\n", "TIter keyList(f1->GetListOfKeys());\n", "TKey *key;\n", "TCanvas c1;\n", "c1.Print(\"hsimple.ps[\");\n", "while ((key = (TKey*)keyList())) {\n", " TClass *cl = gROOT->GetClass(key->GetClassName());\n", " if (!cl->InheritsFrom(\"TH1\")) continue;\n", " TH1 *h = (TH1*)key->ReadObj();\n", " h->Draw();\n", " c1.Print(\"hsimple.ps\");\n", "}\n", "c1.Print(\"hsimple.ps]\");" ] } ], "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 }