Dear ROOT developers and ROOT users,
The macro is attached below and it shows problem with TDirectory::Get()
function. I do not undenstand what object (global variable
gDirectory or local TFile variable) should I use in my programs. What are
recommendations?
With best wishes,
Alexander.
Try to run this macro by:
.x a.c("") <-- It's all right.
.x a.c("a") <-- Problem.
void a(const char *dir)
{
TNamed o1("","");
TFile f1("f.root","RECREATE");
if( strlen(dir)>0 )
{
f1.mkdir(dir);
f1.cd(dir);
}
o1.Write("o");
f1.Write();
f1.Close();
//////////////
TFile f2("f.root"); // Local variable
f2.cd(dir);
f2.pwd(); // f.root:/
printf("Object: %p\n", f2.Get("o")); // Object is NULL!
gDirectory->pwd(); // f.root:/a
printf("Object: %p\n",gDirectory->Get("o")); // OK.
}