Re: [ROOT] Problem with CloneTree()

From: cstrato (cstrato@aon.at)
Date: Tue Apr 20 2004 - 21:34:46 MEST


Dear Philippe

Thank you for your explanation. Now I understand the problem.
Using Double_t x[n] did solve the problem.

Best regards
Christian

Philippe Canal wrote:
> Hi,
> 
> In CopyTrees2 you force all the tree to share a single double to store
> their data:
> 
>    fe = (TFriendElement*)friends->At(0);
>    treej[0] = fe->GetParentTree();
>    treej[0]->SetBranchAddress("BrX",&x);
>    for (Int_t j=0; j<nfriends; j++) {
>       fe = (TFriendElement*)friends->At(j);
>       treej[j+1] = fe->GetTree();
>       treej[j+1]->SetBranchAddress("BrX",&x);
>    }//for_j
> 
> I am not sure what you intend was .. but this wont result in 
> real copies of the trees (unless they are all indentical!)
> 
> 
>> Why can I not use the following code in line 171:
>>   fTreeZ->AddFriend(str.Data(), filename);
> 
> 
> Because of file ownership and lifetime.  'Filename' points 
> to the file you are currently updateing.  This call lead
> to an attempts to re-open it in read mode .... before you
> even wrote it's table of content once ... hence the error.
> 
> Later in the code you have:
>          //not allowed!         fTreeZ->AddFriend(tree, str.Data());
>          delete tree;
> Indeed you can not have those 2 statements together (because fTreeZ
> might not be informed that the object point to by tree is gone.
> 
> Cheers,
> Philippe.
> 
> -----Original Message-----
> From: owner-roottalk@pcroot.cern.ch
> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of cstrato
> Sent: Sunday, April 18, 2004 3:10 PM
> To: roottalk@pcroot.cern.ch
> Subject: [ROOT] Problem with CloneTree()
> 
> 
> Dear Rooters
> 
> In the attached macro "macroFriends.C" I want to copy selected
> entries from a tree and its friends to a new file. For this
> purpose I have written two functions:
> - CopyTrees1() creates new trees which are stored in the new file.
> - CopyTrees2() uses CloneTree() for this purpose.
> 
> While CopyTrees1() works fine, CopyTrees2() does not copy the
> entries of the first tree but the entries of the last tree, as
> seen in the following output:
> root [0] .x macroFriends.C
> ------MyClass::MyClass------
> ------MyClass::CreateTrees------
> ------MyClass::CreateTrees------
> ------MyClass::AddTree------
> ------MyClass::AddTree------
> ------MyClass::AddTree------
> ------MyClass::AddTree------
> ------MyClass::AddTree------
> ------MyClass::AddTree------
> ------MyClass::AddTree------
> ------MyClass::AddTree------
> ------MyClass::CopyTrees1------
> nfriends(treeX) = 7
> file = TreeZ1.root
> j= 0  x[0]= 0.107915     //<========correct!
> j= 1  x[0]= 0.0206264
> j= 2  x[0]= 0.142258
> j= 3  x[0]= 0.0588223
> j= 4  x[0]= 0.107915
> j= 5  x[0]= 0.0206264
> j= 6  x[0]= 0.142258
> j= 7  x[0]= 0.0588223
> ------MyClass::GetTreeZ------
> nentries(treeZ) = 50
> nfriends(treeZ) = 7
> ------MyClass::CopyTrees2------
> nfriends(treeX) = 7
> file = TreeZ2.root
> j= 0  x[0]= 0.0588223    //<========entry of j=7!
> j= 1  x[0]= 0.0206264
> j= 2  x[0]= 0.142258
> j= 3  x[0]= 0.0588223
> j= 4  x[0]= 0.107915
> j= 5  x[0]= 0.0206264
> j= 6  x[0]= 0.142258
> j= 7  x[0]= 0.0588223
> ------MyClass::GetTreeZ------
> nentries(treeZ) = 50
> nfriends(treeZ) = 7
> ------MyClass::~MyClass------
> root [1]
> 
> I have the following questions:
> 1, CopyTrees2: Do you know why the parent tree copies the wrong
>     entries to the cloned tree?
> 2, CopyTrees1: Why can I not use the following code in line 171:
>     fTreeZ->AddFriend(str.Data(), filename);
> 
> Thank you in advance for your help.
> 
> 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:07 MET