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

2cU

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]");
}
#define h(i)
Definition: RSha256.hxx:106
#define gROOT
Definition: TROOT.h:415
The Canvas class.
Definition: TCanvas.h:31
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:75
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4708
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:48
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:3923
The TH1 histogram class.
Definition: TH1.h:56
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:24
virtual const char * GetClassName() const
Definition: TKey.h:72
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:729
return c1
Definition: legend1.C:41
TF1 * f1
Definition: legend1.C:11
Author
Rene Brun

Definition in file loopdir.C.