Re: looping over multiple root files

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Thu, 1 May 2008 16:11:54 +0200


Could you post the shortest possible script reproducing your problem?

Rene Brun

orge Armando Benitez wrote:
> Hi,
>
> I have 4 root files (in the future n files) that contain TGraphs with
> the same name, I would like to make some overlayed plots with the
> contents of the files, my plan is to loop over the first file TGraphs,
> then get the TGraphs for each on of the other files and then plot them
> overlayed.
>
> I'm having problem when I open more than one file. Can anybody please
> give me some suggestions about the correct procedure to do this?
>
>
> The error message looks something like this
> R__unzip: error in header
> Error: illegal pointer to class object obj 0x0 3
> FILE:macros/overlay_performance_plots.C LINE:45
>
> here is a piece of the code I'm using
>
>
> TString file0 = "file0.root";
> TString file1 = "file1.root";
> TString file2 = "file2.root";
> TString file3 = "file3.root";
>
> TFile * f0 = new TFile(file0);
> // TFile * f1 = new TFile(file1);
> // TFile * f2 = new TFile(file2);
> // TFile * f3 = new TFile(file3);
>
> TIter next(f0->GetListOfKeys());
> TKey *key;
> while ((key=(TKey*)next())) {
>
> TObject *obj = key->ReadObj();
>
> if ( obj->IsA()->InheritsFrom( "TGraph" ) ) {
> printf("key: %s \n", key->GetName());
> TMultiGraph *mg = new TMultiGraph();
> mg->SetTitle("Overlayed Plots");
>
> TObject *obj = key->ReadObj();
> TGraph *g0 = (TGraph*)obj;
> mg->Add(g0);
>
> /// everything fine up to here and when only one file is open, as soon
> as I open an extra file it complains
> TGraph *g1 = f1->GetListOfKeys()->FindObject(h1->GetName());
> mg->Draw("AC");
>
> }
> }
>
>
> Thank you for your help,
>
> Jorge A.
>
Received on Thu May 01 2008 - 16:11:56 CEST

This archive was generated by hypermail 2.2.0 : Fri May 02 2008 - 23:50:01 CEST