Drawing objects in TTrees


I read in the TTree::Draw class doc that objects in leaves can be ‘drawn’ just like
simple variables, if they have an AsDouble() method. The example given is for a TTimeStamp. I tried to implement this for my classes, failed, then checked if the example works, and it doesn’t (for me)…

Can you tell me what I’m doing wrong please ?

I made the tree like this:

TTimeStamp* ts = new TTimeStamp;
TTree* tree = new TTree("EventShape","Event shape global variables");
tree->Branch("time", "TTimeStamp", &ts, 32000, 0);

When I read the tree afterwards, I can do

root [2] EventShape->Draw("time.AsDouble()")

OK, but if I try

root [3] EventShape->Draw("time") 

then it’s a catastrophe (and the same happens if I try to draw using the treeviewer):

 *** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".
Attaching to program: /proc/882/exe, process 882
(no debugging symbols found)...done.
[Thread debugging using libthread_db enabled]
[New Thread -1208236336 (LWP 882)]
(no debugging symbols found)...done.
0x00ec6402 in __kernel_vsyscall
#1  0x00f56c23 in __waitpid_nocancel () from /lib/libc.so.6
#2  0x00efd1db in do_system () from /lib/libc.so.6
#3  0x00e4d19d in system () from /lib/libpthread.so.0
#4  0x00360d5d in TUnixSystem::Exec () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#5  0x00365ac7 in TUnixSystem::StackTrace () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#6  0x0036542e in TUnixSystem::DispatchSignals () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#7  0x0036556d in SigHandler () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#8  0x0035e0e4 in sighandler () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#9  <signal handler called>
#10 0x021169b5 in TFormLeafInfo::TFormLeafInfo$base () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#11 0x02119a87 in TFormLeafInfoDirect::TFormLeafInfoDirect () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#12 0x0212ca85 in TTreeFormula::SwitchToFormLeafInfo () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#13 0x02139eb2 in TTreeFormula::ParseWithLeaf () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#14 0x0213d3dd in TTreeFormula::DefinedVariable () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#15 0x010a5408 in TFormula::Analyze () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libHist.so
#16 0x010b26ea in TFormula::Compile () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libHist.so
#17 0x0212b648 in TTreeFormula::Init () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#18 0x0213b6cc in TTreeFormula::TTreeFormula () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#19 0x02122e02 in TSelectorDraw::CompileVariables () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#20 0x021244de in TSelectorDraw::Begin () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#21 0x02142794 in TTreePlayer::Process () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#22 0x0214809c in TTreePlayer::DrawSelect () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTreePlayer.so
#23 0x0394a50d in TTree::Draw () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTree.so
#24 0x0393ef85 in TTree::Draw () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libTree.so
#25 0x004de448 in G__G__Base2_9_0_15 () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#26 0x008c381a in Cint::G__ExceptionWrapper () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#27 0x009a8550 in G__call_cppfunc () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#28 0x009829dd in G__interpret_func () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#29 0x00971c59 in G__getfunction () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#30 0x00a3d079 in G__getstructmem () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#31 0x00a34b5f in G__getvariable () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#32 0x00947441 in G__getitem () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#33 0x009476c8 in G__getitem () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#34 0x0094e351 in G__getexpr () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#35 0x009d4426 in G__exec_statement () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#36 0x00932bce in G__exec_tempfile_core () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#37 0x00932ed6 in G__exec_tempfile_fp () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#38 0x009dc2d4 in G__process_cmd () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCint.so
#39 0x003390a5 in TCint::ProcessLine () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#40 0x0029f376 in TApplication::ProcessLine () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#41 0x0011c779 in TRint::HandleTermInput () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libRint.so
#42 0x0011ad25 in TTermInputHandler::Notify () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libRint.so
#43 0x0011d094 in TTermInputHandler::ReadNotify () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libRint.so
#44 0x0036464b in TUnixSystem::CheckDescriptors () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#45 0x00364a3e in TUnixSystem::DispatchOneEvent () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#46 0x002f6fb1 in TSystem::InnerLoop () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#47 0x002f8901 in TSystem::Run () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#48 0x0029dd08 in TApplication::Run () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libCore.so
#49 0x0011cccf in TRint::Run () from /home/franklan/.root-v5.17.04_gcc-4.1.2/lib/libRint.so
#50 0x08048d73 in main ()
The program is running.  Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/882/exe, process 882

Thanks a lot

Hi John,

I can reproduce the problem. It appear in the case where the object is the top level object (aka if your TTimeStamp was embedded in another object, you would not have seen this problem :slight_smile:).
I’ll fix this asap.


The problem is now fixed in SVN.