{ "cells": [ { "cell_type": "markdown", "id": "f07cfa56", "metadata": {}, "source": [ "# testMergeCont\n", "Macro demonstrating the merging of containers.\n", "\n", "\n", "\n", "**Author:** The Root Team \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:16 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "57fee208", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:16:42.241216Z", "iopub.status.busy": "2026-05-19T20:16:42.241109Z", "iopub.status.idle": "2026-05-19T20:16:42.558977Z", "shell.execute_reply": "2026-05-19T20:16:42.558235Z" } }, "outputs": [], "source": [ "TFile *f;" ] }, { "cell_type": "markdown", "id": "83613fc4", "metadata": {}, "source": [ " Definition of a helper function: " ] }, { "cell_type": "code", "execution_count": 2, "id": "84900b41", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:16:42.560997Z", "iopub.status.busy": "2026-05-19T20:16:42.560859Z", "iopub.status.idle": "2026-05-19T20:16:42.571872Z", "shell.execute_reply": "2026-05-19T20:16:42.571360Z" } }, "outputs": [], "source": [ "%%cpp -d\n", "TSeqCollection *GetCollection()\n", "{\n", " TObject *obj;\n", "#ifndef ClingWorkAroundMissingDynamicScope\n", "# define ClingWorkAroundMissingDynamicScope\n", "#endif\n", " f = TFile::Open(\"hsimple.root\");\n", " if( !f ) {\n", "#ifdef ClingWorkAroundMissingDynamicScope\n", " f = (TFile*)gROOT->ProcessLine(\"hsimple(1);\");\n", "#else\n", " f = hsimple(1);\n", "#endif\n", " }\n", " gROOT->cd();\n", " TList *l0 = new TList();\n", " TList *l01 = new TList();\n", " TH1 *hpx = (TH1*)f->Get(\"hpx\");\n", " printf(\"Adding hpx: %d entries\\n\", (int)hpx->GetEntries());\n", " l01->Add(hpx);\n", " TH1 *hpxpy = (TH1*)f->Get(\"hpxpy\");\n", " l01->Add(hpxpy);\n", " TH1 *hprof = (TH1*)f->Get(\"hprof\");\n", " l0->Add(hprof);\n", " l0->Add(l01);\n", " return l0;\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "id": "a1153166", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:16:42.573294Z", "iopub.status.busy": "2026-05-19T20:16:42.573140Z", "iopub.status.idle": "2026-05-19T20:16:42.778718Z", "shell.execute_reply": "2026-05-19T20:16:42.778067Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "Adding hpx: 25000 entries\n", "============================================\n", "Total hpx: 275000 entries\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Info in : created default TCanvas with name c1\n" ] } ], "source": [ "TString tutdir = gROOT->GetTutorialDir();\n", "gROOT->LoadMacro(tutdir+\"/hsimple.C\");\n", "TList *list1 = (TList *)GetCollection();\n", "TList *inputs = new TList();\n", "for (Int_t i=0; i<10; i++) {\n", " inputs->AddAt(GetCollection(),0);\n", " list1->Merge(inputs);\n", " inputs->Delete();\n", " f->Close();\n", "}\n", "delete inputs;\n", "TH1F *hpx = (TH1F*)(((TList*)list1->At(1))->At(0));\n", "printf(\"============================================\\n\");\n", "printf(\"Total hpx: %d entries\\n\", (int)hpx->GetEntries());\n", "hpx->Draw();\n", "list1->Delete();\n", "delete list1;" ] }, { "cell_type": "markdown", "id": "663cc4da", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "d3f8298c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:16:42.780253Z", "iopub.status.busy": "2026-05-19T20:16:42.780139Z", "iopub.status.idle": "2026-05-19T20:16:42.984914Z", "shell.execute_reply": "2026-05-19T20:16:42.984329Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gROOT->GetListOfCanvases()->Draw()" ] } ], "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 }