Hi Reiner,
Read carefully the following example.
void reiner() {
TFile *file = new TFile("reiner.root","recreate");
TNamed *name = new TNamed("myName","my title");
TDirectory *dir = file->mkdir("sub");
dir->cd();
name->Write();
file->cd();
file->Write(); //<===important statement
delete file;
file = new TFile("reiner.root");
file->ls();
file->cd("sub");
TNamed *name2 = (TNamed*)gDirectory->Get("myName");
name2->Dump();
file->ls();
}
Rene Brun
On Sun, 5 Mar 2000, ROHLFS Reiner wrote:
> Hi ROOT - team
>
> I have problems to find my object in a ROOT file that I have written into a
> subdirectory. It disappears after I close and reopen the ROOT file:
>
> Warning in <TGClient::GetColorByName>: couldn't retrieve color LightYellow
> *******************************************
> * *
> * W E L C O M E to R O O T *
> * *
> * Version 2.23/12 21 February 2000 *
> * *
> * You are welcome to visit our Web site *
> * http://root.cern.ch *
> * *
> *******************************************
>
> FreeType Engine v1.1 used to render TrueType fonts.
>
> CINT/ROOT C/C++ Interpreter version 5.14.25, Nov 25 1999
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] TFile * file = new TFile("subdir.root", "NEW")
> root [1] file->IsOpen()
> (Bool_t)1
> root [2] TNamed *name = new TNamed("my Name", "my title")
> root [3] TDirectory * dir = file->mkdir("sub")
> root [4] dir->cd()
> (Bool_t)1
> root [5] name->Write("my Name")
> root [6] file->ls()
> TFile** subdir.root
> TFile* subdir.root
> TDirectory* sub sub
> KEY: TNamed my Name;1 my title
> KEY: TDirectory sub;1 sub
> // up to here everything looks
> // OK for me
>
> root [7] delete file
> root [8] TFile * file = new TFile("subdir.root", "READ")
> root [9] file->IsOpen()
> (Bool_t)1
> root [10] file->ls()
> TFile** subdir.root
> TFile* subdir.root
> KEY: TDirectory sub;1 sub
> // here "TNamed my Name" is
> // missing ??
>
> root [11] gDirectory->cd("sub")
> (Bool_t)1
> root [12] gDirectory->ls()
> TDirectory* sub sub
> root [13] gDirectory->pwd()
> subdir.root:/sub
> root [14] name->Read("my Name")
> Error in <TNamed::Read>: Key not found
> // I cannot read the object
>
> root [15] file->Map()
> 20000305/103617 At:64 N=88 TFile
> 20000305/103650 At:152 N=75 TDirectory
> 20000305/103725 At:227 N=79 TNamed
> 20000305/103738 At:306 N=94 TFile
> 20000305/103738 At:400 N=55 TFile
>
> // But somehow TNamed is
> // available in the file
>
>
>
> What is wrong with these statements?
> I run these on a SUN SPARC station.
>
> Thanks Reiner.
>
>
This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:21 MET