Re: [ROOT] How to separate tree friends

From: cstrato (cstrato@aon.at)
Date: Fri Apr 16 2004 - 20:52:18 MEST


Dear Philippe, dear Rene

Thank you both for your last comments which are very helpful.
I did not realize the difference between adding a TTree* and
adding the treename as string.
(My suggestion was only a late-night thought.)

BTW, in my "real" program I am managing my own lists in addition
to the list of friends and I will try Rene´s suggestion.

Best regards
Christian

Philippe Canal wrote:

>>(I am not quite sure if this would make sense?)
> 
> 
> What you are trying to do, doesn't seem very general and implement
> this proposal seems that it would have negative consequence for
> everybody else (more problem about object ownership)
> 
> It would probably be better if you were either creating the 
> correct list of TTree friend in the first place or if you were managing
> your own lists instead of relying on list (the list of friends) 
> which only vaguely support your use case.
> 
> Cheers,
> Philippe.
> 
> Note: Also if you very to manage the TFile object and TTree object
> by yourself and add the tree friend by passing a TTree* instead of
> a string, the TFriendElement would __not__ own the TTree and would
> not delete it upon removal.
> 
> -----Original Message-----
> From: cstrato [mailto:cstrato@aon.at]
> Sent: Thursday, April 15, 2004 4:33 PM
> To: Philippe Canal
> Cc: Rene Brun; roottalk@pcroot.cern.ch
> Subject: Re: [ROOT] How to separate tree friends
> 
> 
> Dear Philippe
> 
> I understand, however it would be great if there would be
> a simpler way, e.g if there would exist a method such as:
>    TTree * TTree::RemoveFriend(const char *treename)
> which removes the tree from the list of friends and returns
> a pointer to the removed tree.
> (I am not quite sure if this would make sense?)
> 
> Best regards
> Christian
> 
> Philippe Canal wrote:
> 
>>Hi Christian,
>>
>>In your case the TFriendElements owns the TTree object (and the file)
>>and is deleted when RemoveFriend is called.
>>
>>You will need to record the name of the TTree and the name of the
>>file before Removing the friendship from the previous tree.
>>
>>Cheers,
>>Philippe.
>>
>>-----Original Message-----
>>From: cstrato [mailto:cstrato@aon.at]
>>Sent: Wednesday, April 14, 2004 4:55 PM
>>To: Philippe Canal
>>Cc: Rene Brun; roottalk@pcroot.cern.ch
>>Subject: Re: [ROOT] How to separate tree friends
>>
>>
>>Dear Philippe,
>>
>>I have tried to implement your suggestion in the attached
>>macro "macroFriends.C". Sorrowly, I get 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::MoveTree------
>>Error in <TMemberInspector::Streamer>: version id <=0 in ClassDef, dummy 
>>Streamer() called
>>Error in <TMemberInspector::Streamer>: version id <=0 in ClassDef, dummy 
>>Streamer() called
>>Error in <TMemberInspector::Streamer>: version id <=0 in ClassDef, dummy 
>>Streamer() called
>>------MyClass::GetTreeX------
>>nfriends(treeX) = 3
>>------MyClass::GetTreeY------
>>
>>  *** Break *** bus error
>>Root > Function macroFriends() busy flag cleared
>>Function GetTreeY() busy flag cleared
>>
>>Can you tell me, why I cannot add the selected trees to fTreeY?
>>
>>Thank you in advance
>>Christian
>>
>>
>>Philippe Canal wrote:
>>
>>
>>>Hi Christian,
>>>
>>>The TTree object has one list of friend and it always
>>>uses all the friends on the list.
>>>
>>>However you can manipulate the list as you see fit after
>>>getting it from TTree::GetListOfFriends.
>>>
>>>For example you could extract (Remove) from it, TreeA,
>>>TreeB, TreeC etc ... and add them to the list of friends
>>>of TTreeA.
>>>
>>>Cheers,
>>>Philippe.
>>>
>>>-----Original Message-----
>>>From: owner-roottalk@pcroot.cern.ch
>>>[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of cstrato
>>>Sent: Tuesday, April 13, 2004 1:00 PM
>>>To: Rene Brun
>>>Cc: roottalk@pcroot.cern.ch
>>>Subject: Re: [ROOT] How to separate tree friends
>>>
>>>
>>>Dear Rene
>>>
>>>Thank you, but this is not what I want:
>>>I have a method:
>>>    myclass-AddTrees("treename", "filename", "group")
>>>where the user can add trees from different root files.
>>>These trees are stored as friends to the first tree fTree.
>>>
>>>fTree is then passed to different methods, where I would
>>>like to separate these trees based on their "groups",
>>>and create e.g. two trees with friends for:
>>>"group1": fTree("Tree1") with friends Tree2, Tree3, Tree4
>>>"group2": atree("TreeA") with friends TreeB, TreeC
>>>(These separate tree groups are then again passed to
>>>different methods.)
>>>
>>>Best regards
>>>Christian
>>>
>>>
>>>Rene Brun wrote:
>>>
>>>
>>>
>>>>Hi Christian,
>>>>
>>>>As I am not sure to understand your question (or what you want to do),
>>>>I can only give a naive answer
>>>>
>>>>  fTree = (TTree*)gDirectory->Get("Tree1");
>>>>  fTree->AddFriend("Tree2", "file2.root");
>>>>  fTree->AddFriend("Tree3", "file3.root");
>>>>  fTree->AddFriend("Tree4", "file4.root");
>>>>
>>>>  aTree = (TTree*)gDirectory->Get("TreeA");
>>>>  aTree->AddFriend("TreeB", "fileB.root");
>>>>  aTree->AddFriend("TreeC", "fileC.root");
>>>>
>>>>Rene Brun
>>>>
>>>>
>>>>cstrato wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>Dear Rooters
>>>>>
>>>>>Suppose that I have a tree with following friends:
>>>>> fTree = (TTree*)gDirectory->Get("Tree1");
>>>>> fTree->AddFriend("Tree2", "file2.root");
>>>>> fTree->AddFriend("Tree3", "file3.root");
>>>>> fTree->AddFriend("TreeA", "fileA.root");
>>>>> fTree->AddFriend("Tree4", "file4.root");
>>>>> fTree->AddFriend("TreeB", "fileB.root");
>>>>> fTree->AddFriend("TreeC", "fileC.root");
>>>>>
>>>>>How can I separate fTree into the following two treefriends:
>>>>>1, fTree("Tree1") with friends Tree2, Tree3, Tree4
>>>>>2, aTree("TreeA") with friends TreeB, TreeC
>>>>>
>>>>>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