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:

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!!!
does not find them anymore …

what is happening here?



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…")
gDirectory->ls(); //will show all objects in f; //same as previous statement


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