I've changed your macro (see below). The corrections were that: 1. Each section with TFile declaration was enclosed in the {}. It is bad that CINT doesn't print error message 'second declaration' for the code { TFile file("test.root","recreate"); TFile file("test.root","update"); } 2. file->ls() is correct only if 'file' is declared as pointer: TFile *file = new TFile(...) Use file.ls() in the case of TFile file(...) Unfortunately CINT doesn't print error message for the code { TFile file("test.root","recreate"); file->Close(); } 3. gDirectory->ls() was replaced by file.ls() 4. gDirectory->cd() was replaced by file.cd() 5. gDirectory->mkdir(...) was replaced by file.mkdir(...) class TFile : public TDirectory Read the pages: http://root.cern.ch/root/html/TFile.html http://root.cern.ch/root/html/TDirectory.html Your macro: { { gROOT.Reset(); TFile file("test.root","recreate"); file.mkdir("dir1"); file.cd("dir1"); named = new TNamed("amo","amo"); named->Write("amo"); file.ls(); file.Write(); file.Close(); printf("------file closed-------\n"); } { TFile file("test.root","update"); file.cd("dir1"); named = new TNamed("eva","eva"); named->Write("eva"); file.ls(); file.Write(); file.Close(); printf("------file closed-------\n"); } { TFile file("test.root","update"); file.ls(); file.cd("dir1"); file.ls(); } } With best wishes, Alexander Yuryevich Zvyagin. >Sorry for this question, but I checked tutorials and documentation >without >success. My problem: Once I closed a root file, im not able to write >again >into an already created directory. The newly written object appears >in memory but not on disk. After closing and reopening the file it is >lost. >ALso I cant delete an object after reopening the file. >So what is wrong with the following test macro?? > > >{ > gROOT.Reset(); > TFile file("test.root","recreate"); > gDirectory->mkdir("dir1"); > gDirectory->cd("dir1"); > named = new TNamed("amo","amo"); > named->Write("amo"); > gDirectory->ls(); > file->Write(); > file->Close(); > printf("------file closed-------\n"); > > TFile file("test.root","update"); > gDirectory->cd("dir1"); > named = new TNamed("eva","eva"); > named->Write("eva"); > gDirectory->ls(); > file->Write(); > file->Close(); > printf("------file closed-------\n"); > > TFile file("test.root","update"); > gDirectory->cd("dir1"); > gDirectory->ls(); >} > >and this is the output: > >root [0] .x new.C >TDirectory* dir1 dir1 > KEY: TNamed amo;1 amo >TFile Writing Name=test.root Title= >------file closed------- >TDirectory* dir1 dir1 > KEY: TNamed amo;1 amo > KEY: TNamed eva;1 eva >TFile Writing Name=test.root Title= >------file closed------- >TDirectory* dir1 dir1 > KEY: TNamed amo;1 amo >root [1] >-------------------------------------------------- > >and eva is lost! >Thanks in advance > Hajo!
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:35 MET