Dear Rene Thank you for this short and clear explanation. Maybe these nine lines could be added to the method description of TTree::AddFriend. (I checked the documentation once again and have the feeling that the current description does not cover this issue.) Best regards Christian Rene Brun wrote: > There are 3 TTree::AddFriend functions. Up to you to select > the right one for your conditions: > > 1-AddFriend(const char *treename, const char *filename=""); > -Open the file, if filename is specified. > -Import the Tree from the file > -Add the tree to the list of friends > > 2-AddFriend(const char *treename, TFile *file); > -Import the Tree from the file > -Add the tree to the list of friends > > 3-AddFriend(TTree *tree, const char* alias="", Bool_t warn = kFALSE); > -Add the tree to the list of friends > > You must be careful when using style 1 and you already have either > the tree or/and the file connected in memory. > > Rene Brun > > cstrato wrote: > >>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 >> fTree->RemoveFriend(atree); >>seems to be working, too. >> >>Is this an alterantive correct way or does it only work by chance? >> >>Best regards >>Christian >> >>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 >>>>Christian >>>>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- >>>>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