Logo ROOT  
Reference Guide
loopdir.C File Reference

Detailed Description

View in nbviewer Open in SWAN 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

rU

void loopdir() {
TFile *f1 = TFile::Open("hsimple.root");
TIter keyList(f1->GetListOfKeys());
TKey *key;
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]");
}
Author
Rene Brun

Definition in file loopdir.C.

TFile::Open
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.
Definition: TFile.cxx:3946
TClass::InheritsFrom
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4777
TKey::GetClassName
virtual const char * GetClassName() const
Definition: TKey.h:76
h
#define h(i)
Definition: RSha256.hxx:124
TFile
Definition: TFile.h:54
TKey
Definition: TKey.h:28
TKey::ReadObj
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:750
f1
TF1 * f1
Definition: legend1.C:11
TCanvas
Definition: TCanvas.h:23
TClass
Definition: TClass.h:80
TH1
Definition: TH1.h:57
TIter
Definition: TCollection.h:233
gROOT
#define gROOT
Definition: TROOT.h:406
c1
return c1
Definition: legend1.C:41