Re: [ROOT] Warning file not closed or root crash when deleting file

From: cstrato (
Date: Sun Jun 20 2004 - 21:13:06 MEST

Dear Rene

Thank you for your fast reply.
Calling fTree->AddFriend(atree) did solve my problem.

What I do not quite understand is that calling
    fTree->AddFriend(atree->GetName(), fFile);
and later calling
seems to be working, too.

Is this an alterantive correct way or does it only work by chance?

Best regards

Rene Brun wrote:

> Hi Christian,
> Before calling AddFriend, you must close atree and fFile.
> Do:
>    TString tname = atree->GetName()
>    TString fname = fFile->GetName()
>    atree->Write();
>    delete fFile;
>    fTree->AddFriend(tname,fname);
> or  call the other TTree::AddFriend constructor
>    atree->Write();
>    fTree->AddFriend(atree);
> Rene Brun
> On Sun, 20 Jun 
> 2004, cstrato wrote:
>>Dear Rooters
>>I have the following situation:
>>First I open an existing file "fDataFile" which contains some data 
>>trees. In a first step I add these trees as friends to a tree "fTree".
>>Then I create a new file "fFile" where the result tree "atree" should be 
>>stored. Later, I create the result tree "atree" in a class method.
>>After filling "atree" I want to add "atree" as friend to fTree, too.
>>The relevant code fragment of the method looks like this:
>>    TTree *atree = new TTree(treename, "");
>>    // fill atree
>>    fFile->cd();
>>    atree->Write();
>>    fTree->AddFriend(atree->GetName(), fFile->GetName());
>>In this case AddTree() results in the following message:
>>Warning in <TFile::Init>: file /Users/cs/ROOT/rootcode/tmp.root probably 
>>not closed, trying to recover
>>Info in <TFile::Recover>: /Users/cs/ROOT/rootcode/tmp.root, recovered 
>>key TTree:Test at address 350
>>Warning in <TFile::Init>: successfully recovered 1 keys
>>Nevertheless, everything works fine including the call to the
>>destructors, where I delete "fDataFile" with "SafeDelete(fDataFile)".
>>In contrast, when I add "atree" as friend using:
>>    fTree->AddFriend(atree->GetName(), fFile);
>>everything works fine until I call the destructors.
>>When I try to delete "fDataFile" with "SafeDelete(fDataFile)" then
>>root crashes beyond recovery with "*** Break *** bus error"
>>However, if I remove "atree" after usage by calling in a different method
>>    fTree->RemoveFriend(atree);
>>then everything works fine again and I can call "SafeDelete(fDataFile)"
>>in the destructor.
>>Does anybody have an idea what might be the reason for this behavior?
>>(I am afraid ths code is too complex to extract a simple macro.)
>>Thank you in advance
>>Best regards
>>C.h.r.i.s.t.i.a.n. .S.t.r.a.t.o.w.a
>>V.i.e.n.n.a.         .A.u.s.t.r.i.a

This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET