Re: Directories in TFile.

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue May 18 1999 - 08:55:47 MEST


Hi Alexander,
As you have found yourself:
 f2.pwd() and gDirectory->pwd() print different results.
the function pwd() simply prints the full path name corresponding to the
object or pointer.

To import an object in memory,
 - you cd to the directory and gDirectory->Get
 - or you Get(full path name of object)

Rene Brun

Alexander Zvyagin wrote:
> 
>                                            IHEP, Protvino, Russia, 17-MAY-1999
> 
>     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.
> }



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:33 MET