Re: [ROOT] Open a ROOT file twice

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Jul 06 2000 - 11:07:55 MEST


Hi Reiner,
Sorry for the long delay to answer your mail.
Root I/O does not support concurrent write in the same file by two different
processes or the way you show it in your macro.
You can only have one writer and multiple readers.
It is possible to use Root in concurrent mode by implementing a small server
(a la rootd) where all transactions to the file go via the server. In this case,
we are back to the simpler situation of one writer and multiple readers.
The communication via the server can be done via the socket classes.
See tutorials hserv/hclient.

Rene Brun

ROHLFS Reiner wrote:
> 
> 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:29 MET