[ROOT] Open a ROOT file twice

From: ROHLFS Reiner (Reiner.Rohlfs@obs.unige.ch)
Date: Mon Jun 12 2000 - 13:32:19 MEST


Hi ROOT - team,

is it possible to open the same ROOT file twice in UPDATE - mode?
I want to write two objects ( in the example macro below they are name1 and
name2) in the same file independent of each other.

The following macro results in a somehow corrupted ROOT file or do I something
wrong?

Thanks Reiner.


{
   gROOT->Reset();

   // create a new file
   TFile * file1 = new TFile("update_two.root", "NEW");
   TDirectory * dir1 = file1->mkdir("sub1");
   TNamed * name1 = new TNamed("name1", "title1");
   file1->cd();
   file1->Write();


   // open the same file in update mode
   TFile * file2 = new TFile("update_two.root", "UPDATE");
   TDirectory * dir2 = file2->mkdir("sub2");
   TNamed * name2 = new TNamed("name2", "title2");
   file2->cd();
   file2->Write();


   TDirectory * tmpDir;

   // write the first object and close the file
   tmpDir = gDirectory;
   dir1->cd();
   name1->Write(name1->GetName(), TObject::kOverwrite);
   file1->cd();
   file1->Write();
   
   gDirectory = tmpDir;
   delete file1;


   // write the second object and close the file
   tmpDir = gDirectory;
   dir2->cd();
   name2->Write(name2->GetName(), TObject::kOverwrite);
   file2->cd();
   file2->Write();
   
   gDirectory = tmpDir;
   delete file2;


   // test the result
   TFile * tf = new TFile("update_two.root");
   tf->ls();

   tf->Map();
	// this shows something unexpected

   tf->cd("sub1");
// this crashesthe root session
   tf->ls();

   tf->cd("sub2");
   tf->ls();

   delete tf;

}



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:27 MET