TFile::Open()

Hi, rooters,
I tried to use TFile::Open(char *name) in a for-loop to open my files:

char filenames[NUMBER_OF_FILES]; …
TFile *f1=new TFile();

for(int i=0; i<NUMBER_OF_FILES; i++)
{
f1->Open(filenames[i]);
f1->ls(); //shows an empty file
localHisto= (TH1F*)f1->Get(“histo”); //here it crashes, because this object “histo” is not found

f1->Close();
}

If I don’t open this TFile, but create a new TFile-Object in each loop, it works. So I seek for explanation, why TFILE::Open returns an empty file… Do I something wrong with options?

TFile::Open is a static member function returning a TFile object.
In your loop you should do
f1 = TFile::Open(…);

and also make sure to delete your files

Rene