Problem Cloning TTree with Friends

Hi,
I have a file with a tree t1 that has fiends t2
There is another tree t3 in the input file
I want to copy part of it in another file and have t2 and t3 as friends of t1 in the output file
What I do:
I open input file
I open an output file (recreate)
I get pointer on tree t1,t2,t3 (TTree* t1=(TTree3)_file0->Get(“t1”) …)
I do (as I have an ouput file and the cd is on the ouput file there should not be memory problems)
tt1=t1->CloneTree(50000)
tt2=t2->CloneTree(50000)
tt3=t3->CloneTree(50000)
now I delete input file (as I have to give strings structure in Clone I don’t want
to have any problems of name collisions)
I do:

tt1->AddFriend("t2")
tt1->AddFriend("t3")
tt1->Write()
tt2->Write()
tt3->Write()

now I end this root session.
I open the output file
I can Draw things in tt3
If I do a draw of tt1 using a variable in tt3 I have a segfault.
ROOT 6.08/06

Here is the stuff (with real life names)

root
TFile * f = new TFile("data_000.root")
TFile * a = new TFile("extract_data.root","recreate")
TTree* ta=(TTree*)f->Get("t_trigger")
TTree* tb=(TTree*)f->Get("trigger_aux")
TTree* tc=(TTree*)f->Get("weight_keV")
ta1=ta->CloneTree(50000)
tb1=tb->CloneTree(50000)
tc1=tc->CloneTree(50000)
delete f
tb1->Write()
tc1->Write()
ta1->AddFriend("trigger_aux")
ta1->AddFriend("weight_keV")
ta1->Write()
delete a
produit@yoga$ root extract_data.root 
   ------------------------------------------------------------
  | Welcome to ROOT 6.08/06                http://root.cern.ch |
  |                               (c) 1995-2016, The ROOT Team |
  | Built for linuxx8664gcc                                    |
  | From tag v6-08-06, 2 March 2017                            |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------

root [0] 
Attaching file extract_data.root as _file0...
(TFile *) 0x267d6e0
root [1] weight_keV->Draw("weight_keV")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [2] t_trigger->Draw("weight_keV")

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007fd9f8e9607a in __GI___waitpid (pid=15298, stat_loc=stat_loc
entry=0x7ffd02407b40, options=options
entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:29
#1  0x00007fd9f8e0efbb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:148
#2  0x00007fd9f99ffde4 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x14354f0) at /home/produit/root/core/unix/src/TUnixSystem.cxx:2118
#3  TUnixSystem::StackTrace (this=0x14354f0) at /home/produit/root/core/unix/src/TUnixSystem.cxx:2405
#4  0x00007fd9f9a0244c in TUnixSystem::DispatchSignals (this=0x14354f0, sig=kSigSegmentationViolation) at /home/produit/root/core/unix/src/TUnixSystem.cxx:3625
#5  <signal handler called>
#6  TTree::GetFriendAlias (this=<optimized out>, tree=0x1f49610) at /home/produit/root/tree/tree/src/TTree.cxx:5575
#7  0x00007fd9e465544b in TTreeFormula::ParseWithLeaf (this=this
entry=0x2fb04b0, leaf=0x2bbb950, subExpression=0x7ffd0240af49 "", final=<optimized out>, paran_level=0, castqueue=..., useLeafCollectionObject=false, fullExpression=0x7ffd0240bec9 "weight_keV") at /home/produit/root/tree/treeplayer/src/TTreeFormula.cxx:822
#8  0x00007fd9e4660258 in TTreeFormula::DefinedVariable (this=<optimized out>, name=..., action=<optimized out>) at /home/produit/root/tree/treeplayer/src/TTreeFormula.cxx:2959
#9  0x00007fd9e39544bd in ROOT::v5::TFormula::Analyze (this=0x2fb04b0, schain=0x7ffd0240c2e9 "weight_keV", err=
0x7ffd0240c28c: 0, offset=0) at /home/produit/root/hist/hist/src/TFormula_v5.cxx:1380
#10 0x00007fd9e395d41d in ROOT::v5::TFormula::Compile (this=0x2fb04b0, expression=<optimized out>) at /home/produit/root/hist/hist/src/TFormula_v5.cxx:2367
#11 0x00007fd9e465b8bf in TTreeFormula::Init (this=0x2fb04b0, name=0x2f77700 "Var1", expression=0x2f59649 "weight_keV") at /home/produit/root/tree/treeplayer/src/TTreeFormula.cxx:209
#12 0x00007fd9e465be6d in TTreeFormula::TTreeFormula (this=0x2fb04b0, name=0x2f77700 "Var1", expression=0x2f59649 "weight_keV", tree=<optimized out>) at /home/produit/root/tree/treeplayer/src/TTreeFormula.cxx:162
#13 0x00007fd9e464c9f6 in TSelectorDraw::CompileVariables (this=0x2f594e0, varexp=<optimized out>, selection=<optimized out>) at /home/produit/root/tree/treeplayer/src/TSelectorDraw.cxx:1008
#14 0x00007fd9e4648c0d in TSelectorDraw::Begin (this=<optimized out>, tree=<optimized out>) at /home/produit/root/tree/treeplayer/src/TSelectorDraw.cxx:477
#15 0x00007fd9e4678f26 in TTreePlayer::Process (this=0x2f81d40, selector=0x2f594e0, option=0x7fd9e5355d9d "", nentries=50000, firstentry=0) at /home/produit/root/tree/treeplayer/src/TTreePlayer.cxx:2231
#16 0x00007fd9e4679f14 in TTreePlayer::DrawSelect (this=0x2f81d40, varexp0=<optimized out>, selection=0x7fd9e5355d9d "", option=0x7fd9e5355d9d "", nentries=1000000000000, firstentry=0) at /home/produit/root/tree/treeplayer/src/TTreePlayer.cxx:414
#17 0x00007fd9fa11f0a6 in ?? ()
#18 0x00007ffd0240cbf8 in ?? ()
#19 0x00007fd9f556c900 in ?? () from /home/produit/root/mybuild/lib/libCling.so
#20 0x0000000001495a30 in ?? ()
#21 0x0000000002f46c88 in ?? ()
#22 0x00007ffd0240cf00 in ?? ()
#23 0x00007ffd0240cf00 in ?? ()
#24 0x00007ffd0240cbb0 in ?? ()
#25 0x00007fd9f556e53f in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/produit/root/mybuild/lib/libCling.so
#26 0x00007fd9f556ff9d in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/produit/root/mybuild/lib/libCling.so
#27 0x00007fd9f5570250 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**) () from /home/produit/root/mybuild/lib/libCling.so
#28 0x00007fd9f55f948e in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /home/produit/root/mybuild/lib/libCling.so
#29 0x00007fd9f54e0456 in HandleInterpreterException (metaProcessor=<optimized out>, input_line=<optimized out>, compRes=
0x7ffd0240ceec: cling::Interpreter::kSuccess, result=result
entry=0x7ffd0240cf00) at /home/produit/root/core/meta/src/TCling.cxx:1883
#30 0x00007fd9f54f143a in TCling::ProcessLine (this=0x148ed60, line=<optimized out>, error=0x7ffd0240d40c) at /home/produit/root/core/meta/src/TCling.cxx:2049
#31 0x00007fd9f9954e56 in TApplication::ProcessLine (this=this
entry=0x1480af0, line=<optimized out>, sync=sync
entry=false, err=err
entry=0x7ffd0240d40c) at /home/produit/root/core/base/src/TApplication.cxx:1005
#32 0x00007fd9f9d5259e in TRint::ProcessLineNr (this=this
entry=0x1480af0, filestem=filestem
entry=0x7fd9f9d55acf "ROOT_prompt_", line=0x2ecfd60 "t_trigger->Draw(\"weight_keV\")", error=0x7ffd0240d40c, error
entry=0x0) at /home/produit/root/core/rint/src/TRint.cxx:749
#33 0x00007fd9f9d52925 in TRint::HandleTermInput (this=0x1480af0) at /home/produit/root/core/rint/src/TRint.cxx:610
#34 0x00007fd9f9a0193c in TUnixSystem::CheckDescriptors (this=this
entry=0x14354f0) at /home/produit/root/core/unix/src/TUnixSystem.cxx:1321
#35 0x00007fd9f9a02d7a in TUnixSystem::DispatchOneEvent (this=0x14354f0, pendingOnly=<optimized out>) at /home/produit/root/core/unix/src/TUnixSystem.cxx:1076
#36 0x00007fd9f99385e4 in TSystem::InnerLoop (this=0x14354f0) at /home/produit/root/core/base/src/TSystem.cxx:408
#37 0x00007fd9f993711f in TSystem::Run (this=0x14354f0) at /home/produit/root/core/base/src/TSystem.cxx:358
#38 0x00007fd9f995238f in TApplication::Run (this=this
entry=0x1480af0, retrn=retrn
entry=false) at /home/produit/root/core/base/src/TApplication.cxx:1157
#39 0x00007fd9f9d54007 in TRint::Run (this=this
entry=0x1480af0, retrn=retrn
entry=false) at /home/produit/root/core/rint/src/TRint.cxx:463
#40 0x000000000040107c in main (argc=1, argv=0x7ffd0240f878) at /home/produit/root/main/src/rmain.cxx:30
===========================================================


The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum http://root.cern.ch/forum.
Only if you are really convinced it is a bug in ROOT then please submit a
report at http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  TTree::GetFriendAlias (this=<optimized out>, tree=0x1f49610) at /home/produit/root/tree/tree/src/TTree.cxx:5575
#7  0x00007fd9e465544b in TTreeFormula::ParseWithLeaf (this=this
entry=0x2fb04b0, leaf=0x2bbb950, subExpression=0x7ffd0240af49 "", final=<optimized out>, paran_level=0, castqueue=..., useLeafCollectionObject=false, fullExpression=0x7ffd0240bec9 "weight_keV") at /home/produit/root/tree/treeplayer/src/TTreeFormula.cxx:822
#8  0x00007fd9e4660258 in TTreeFormula::DefinedVariable (this=<optimized out>, name=..., action=<optimized out>) at /home/produit/root/tree/treeplayer/src/TTreeFormula.cxx:2959
#9  0x00007fd9e39544bd in ROOT::v5::TFormula::Analyze (this=0x2fb04b0, schain=0x7ffd0240c2e9 "weight_keV", err=
0x7ffd0240c28c: 0, offset=0) at /home/produit/root/hist/hist/src/TFormula_v5.cxx:1380
#10 0x00007fd9e395d41d in ROOT::v5::TFormula::Compile (this=0x2fb04b0, expression=<optimized out>) at /home/produit/root/hist/hist/src/TFormula_v5.cxx:2367
#11 0x00007fd9e465b8bf in TTreeFormula::Init (this=0x2fb04b0, name=0x2f77700 "Var1", expression=0x2f59649 "weight_keV") at /home/produit/root/tree/treeplayer/src/TTreeFormula.cxx:209
#12 0x00007fd9e465be6d in TTreeFormula::TTreeFormula (this=0x2fb04b0, name=0x2f77700 "Var1", expression=0x2f59649 "weight_keV", tree=<optimized out>) at /home/produit/root/tree/treeplayer/src/TTreeFormula.cxx:162
#13 0x00007fd9e464c9f6 in TSelectorDraw::CompileVariables (this=0x2f594e0, varexp=<optimized out>, selection=<optimized out>) at /home/produit/root/tree/treeplayer/src/TSelectorDraw.cxx:1008
#14 0x00007fd9e4648c0d in TSelectorDraw::Begin (this=<optimized out>, tree=<optimized out>) at /home/produit/root/tree/treeplayer/src/TSelectorDraw.cxx:477
#15 0x00007fd9e4678f26 in TTreePlayer::Process (this=0x2f81d40, selector=0x2f594e0, option=0x7fd9e5355d9d "", nentries=50000, firstentry=0) at /home/produit/root/tree/treeplayer/src/TTreePlayer.cxx:2231
#16 0x00007fd9e4679f14 in TTreePlayer::DrawSelect (this=0x2f81d40, varexp0=<optimized out>, selection=0x7fd9e5355d9d "", option=0x7fd9e5355d9d "", nentries=1000000000000, firstentry=0) at /home/produit/root/tree/treeplayer/src/TTreePlayer.cxx:414
#17 0x00007fd9fa11f0a6 in ?? ()
#18 0x00007ffd0240cbf8 in ?? ()
#19 0x00007fd9f556c900 in ?? () from /home/produit/root/mybuild/lib/libCling.so
#20 0x0000000001495a30 in ?? ()
#21 0x0000000002f46c88 in ?? ()
#22 0x00007ffd0240cf00 in ?? ()
#23 0x00007ffd0240cf00 in ?? ()
#24 0x00007ffd0240cbb0 in ?? ()
#25 0x00007fd9f556e53f in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) () from /home/produit/root/mybuild/lib/libCling.so
#26 0x00007fd9f556ff9d in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) () from /home/produit/root/mybuild/lib/libCling.so
#27 0x00007fd9f5570250 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cling::Value*, cling::Transaction**) () from /home/produit/root/mybuild/lib/libCling.so
#28 0x00007fd9f55f948e in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) () from /home/produit/root/mybuild/lib/libCling.so
#29 0x00007fd9f54e0456 in HandleInterpreterException (metaProcessor=<optimized out>, input_line=<optimized out>, compRes=
0x7ffd0240ceec: cling::Interpreter::kSuccess, result=result
entry=0x7ffd0240cf00) at /home/produit/root/core/meta/src/TCling.cxx:1883
===========================================================


Root >

I guess @pcanal can help you.

Can you provide a small version of data_000.root to help with reproducing this problem?

Thanks,
Philippe.

The problem is triggered from the fact there is a missing friend tree, On you original file.

   ta1->GetListOfFriends()->ls();

prints

OBJ: TList	TList	Doubly linked list : 0
 Friend Tree: trigger_aux in file: 
 Friend Tree: bad_triggers in file: 
 Friend Tree: trigger_aux in file: 
 Friend Tree: weight_keV in file: 
 Friend Tree: trigger_aux in file: 
 Friend Tree: weight_keV in file: 

Besides the duplication you can see the friend “bad_triggers”.

The core of the problem is a missing nullptr dereference check inside the ROOT code, which is now fixed in the master and v6.10 patch branch.

To work around the problem add an ‘empty’ TTree named “bad_triggers” to your file.

As a side note, when cloning the TTree, it also clones the list of friends and thus the

   ta1->AddFriend("trigger_aux");
   ta1->AddFriend("weight_keV");

in the exact case you gave me, is redundant.

Cheers,
Philippe.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.