Loopdir


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 (Beta) from the macro found in the ROOT repository on Thursday, January 19, 2017 at 04:31 PM.


In [1]:
TFile *f1 = TFile::Open("hsimple.root");
TIter keyList(f1->GetListOfKeys());
TKey *key;
TCanvas c1;
c1.Print("hsimple.ps[");
while ((key = (TKey*)keyList())) {
   TClass *cl = gROOT->GetClass(key->GetClassName());
   if (!cl->InheritsFrom("TH1")) continue;
   TH1 *h = (TH1*)key->ReadObj();
   h->Draw();
   c1.Print("hsimple.ps");
}
c1.Print("hsimple.ps]");



Error in <TFile::TFile>: file hsimple.root does not exist
    __boot()
    import os
Error in <HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
input_line_24:3:15: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
TIter keyList(f1->GetListOfKeys());
              ^~