Giovanni Organtini wrote: > > Hi, > I could not find this on the Web pages. I have a root file with several > histograms. The number and the names of histograms varies from run to run. > Is there a way to obtain the list of histograms (that I can see with ls()) > and/or directorie names inside a macro? Thank you. Here's an example macro : void loop(const char* filein="test.root") { TFile* fin = new TFile(filein) ; if (!fin->IsOpen()) { printf("<E> Cannot open input file %s\n",filein) ; exit(1) ; } TList* list = fin->GetListOfKeys() ; if (!list) { printf("<E> No keys found in file\n") ; exit(1) ; } TIter next(list) ; TKey* key ; TObject* obj ; while ( key = (TKey*)next() ) { obj = key->ReadObj() ; if ( (strcmp(obj->IsA()->GetName(),"TProfile")!=0) && (!obj->InheritsFrom("TH2")) && (!obj->InheritsFrom("TH1")) ) { printf("<W> Object %s is not 1D or 2D histogram : " "will not be converted\n",obj->GetName()) ; } printf("Histo name:%s title:%s\n",obj->GetName(),obj->GetTitle()); } } -- APHECETCHE Laurent (mailto:Laurent.Aphecetche@subatech.in2p3.fr) SUBATECH-Ecole des Mines de Nantes-4 rue Alfred Kastler-44070 NANTES cedex 03 TEL (+33/0) 2 51 85 84 17 - FAX (+33/0) 2 51 85 84 24 WWW: http://www-subatech.in2p3.fr/~photons
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:34 MET