Loopdir 1 1

Example of script to loop on all the objects of a ROOT file directory and print on Postscript all TH1 derived objects. This script uses the file generated by tutorial hsimple.C

Author: Rene Brun
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Thursday, June 17, 2021 at 04:25 PM.

In [1]:
TFile *f1 = TFile::Open("hsimple.root");
TCanvas c1;
c1.Print("hsimple.ps[");
for(auto k : *f1->GetListOfKeys()) {
   TKey *key = static_cast<TKey*>(k);
   TClass *cl = gROOT->GetClass(key->GetClassName());
   if (!cl->InheritsFrom("TH1")) continue;
   TH1 *h = key->ReadObject<TH1>();
   h->Draw();
   c1.Print("hsimple.ps");
}
c1.Print("hsimple.ps]");
Info in <TCanvas::Print>: ps file hsimple.ps has been created
Info in <TCanvas::Print>: Current canvas added to ps file hsimple.ps
Info in <TCanvas::Print>: Current canvas added to ps file hsimple.ps
Info in <TCanvas::Print>: Current canvas added to ps file hsimple.ps
Info in <TCanvas::Print>: ps file hsimple.ps has been closed