Logo ROOT  
Reference Guide
loopdir.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_io
3/// \notebook -nodraw
4/// Example of script to loop on all the objects of a ROOT file directory
5/// and print on Postscript all TH1 derived objects.
6/// This script uses the file generated by tutorial hsimple.C
7///
8/// \macro_image
9/// \macro_code
10///
11/// \author Rene Brun
12
13void loopdir() {
14 TFile *f1 = TFile::Open("hsimple.root");
15 TIter keyList(f1->GetListOfKeys());
16 TKey *key;
17 TCanvas c1;
18 c1.Print("hsimple.ps[");
19 while ((key = (TKey*)keyList())) {
20 TClass *cl = gROOT->GetClass(key->GetClassName());
21 if (!cl->InheritsFrom("TH1")) continue;
22 TH1 *h = (TH1*)key->ReadObj();
23 h->Draw();
24 c1.Print("hsimple.ps");
25 }
26 c1.Print("hsimple.ps]");
27}
28
#define h(i)
Definition: RSha256.hxx:106
#define gROOT
Definition: TROOT.h:406
The Canvas class.
Definition: TCanvas.h:27
TClass instances represent classes, structs and namespaces in the ROOT type system.
Definition: TClass.h:80
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4837
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format.
Definition: TFile.h:53
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:3942
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:28
virtual const char * GetClassName() const
Definition: TKey.h:76
virtual TObject * ReadObj()
To read a TObject* from the file.
Definition: TKey.cxx:738
return c1
Definition: legend1.C:41
TF1 * f1
Definition: legend1.C:11