Reading more than one root files

Hi,

I am trying to open recursively root files; I try this code:

  TFile *file[5];
  TTree *T1[5];

  f[1]->Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root");

  T1[0]=(TTree*) f[1]->Get("T");

but I obtain an error.
The point, to be clear, is that I need to initialize a TFile array to get the TTree contained in the files in a TTree array.

Thanks, NewR

Can tell us which error you get ?

Thx,

I obtain:

f[1]->Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root");
input_line_29:2:3: error: use of undeclared identifier ‘f’
(f[1]->Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root"))
^
Error in : Error evaluating expression (f[1]->Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root")).
Execution of your code was aborted.

but using f[1].Open I get the same error!

Hi,

You should do something like:

f[1] = TFile::Open("/home/daqmgr/neutroni/DataAnalysis/dst/run328.root");

Regards,
Sergey

1 Like

It doesn’t work. I fixed by opening and closing the same temporary root file recursively as:

TFile *f;
Char_t filenm[80];

for (Int_t i=0; i<5; i++) {
nrun = 330 + i;
sprintf(filenm,"…/dst/run%3i.root",nrun);
f = new TFile(filenm);
T1[i]=(TTree*) f->Get(“T”);
f->Close();

delete f;
}

Many thanks, NewR

Is your error due to the act that you called your array TFile *file[5] and not f[] as in your following code?

1 Like

Yes, you are right!!! Very stupid error!!

Thank you very much!