TFile::Open overwrites entries in gDirectory->GetList()?

Hi all,

I am stuck for quite some time with some strange things in my root program.

Point is:
I create some histos which I try to find lateron with:
gDirectory->GetList()->FindObject(histoname)

that works fine.

However, if I do a
TFile myfile(“file.root”, “UPDATE”);

which also contains histos, ALL the other histos I created before are gone!!!
gDirectory->GetList()->FindObject(*itr)
does not find them anymore …

what is happening here?

Cheers
Andi

Andi,

gDirectory is a pointer to the current directory.
As soon as you open a new file or change directory within a file, gDirectory points to the current directory.
In your case, before opening a new file, you can something like
TDirectory *olddir = gDirectory;
TFile f(’'newfile…")
olddir->GetList()->ls();
gDirectory->ls(); //will show all objects in f
f.ls(); //same as previous statement

Rene

Dear Rene,

aha, yes, I forgot about the real meaning of gDirectory and that it is a pointer to the current dir. It works fine now again when I store the gDir pointer before I open the file.

Thanks for your help
Andi