Segmentation violation using TTree->GetEntry()

I have two objects that I have defined (MyEvent and PhysicsObject). I have a piece of analysis code that runs in the ORCA framework, Qqhinv_object_simple, this finds jets and places them into my objects, then writes these to a TTree. Finally I have a piece of code to analyse the resulting file in Root, TreeRead. The source can be seen at the following links:

MyEvent
PhysicsObject
Qqhinv_object_simple
TreeRead

The ORCA code compiles and runs successfully, at least it appears to - prints out sensible and repeatable messages.

Newing obj
Newed obj
Et : 306.287
Mass : 55.5028
Eta : -1.58699
Theta : 2.73808
Phi : 2.11154
X : -157.269
Y : 261.922
Z : -715.581
T : 780.047
Adding to array
Added to array
Deleted obj
Newing obj
Newed obj
Et : 65.9681
Mass : 522.238
Eta : -4.35953
Theta : 3.11603
Phi : -1.06283
X : 31.423
Y : -56.4459
Z : -2526.22
T : 2580.44
Adding to array
Added to array
Deleted obj
No more jets
2 jets stored
One Tree Constructor
Copying jet 0 of 1
Added jet
Copying jet 1 of 1
Added jet
Jets Tree Cloned
Met Tree Ignored
Lepton Tree Ignored
evt # 0 run # 1
Event pointer created
Tree branched
------>Filling the tree
Event pointer deleted
------>Writing file
------>Closing file
------>Deleting file
------>All done
------>In the Analysis block!
------>Creating file
------>Setting up Jet Algo
------>Creating the PhysicsObject
------>Creating the tree
Newing obj
Newed obj
Et : 76.4589
Mass : 40.2861
Eta : 2.39818
Theta : 0.181268
Phi : -2.55442
X : -63.3651
Y : -42.1672
Z : 415.285
T : 424.12
Adding to array
Added to array
Deleted obj
Newing obj
Newed obj
Et : 71.7043
Mass : 9.64727
Eta : 0.876289
Theta : 0.789
Phi : 1.22633
X : 24.1033
Y : 67.1838
Z : 70.8643
T : 101.042
Adding to array
Added to array
Deleted obj
No more jets
2 jets stored
One Tree Constructor
Copying jet 0 of 1
Added jet
Copying jet 1 of 1
Added jet
Jets Tree Cloned
Met Tree Ignored
Lepton Tree Ignored
evt # 0 run # 1
Event pointer created
Tree branched
------>Filling the tree
Event pointer deleted
------>Writing file
------>Closing file
------>Deleting file
------>All done

...

Error Report

Location               Warning    Severe     Fatal

CARF Total Errors            0         0         0

When I try to run TreeRead I get the following seg fault when I call evtT->GetEntry(e).

root [4] .x TreeRead.C
 File loaded
 Event tree loaded 
 Looking at event tree
 Number of entries : 1
 Number of entries : 1
 Getting entry 0

 *** Break *** segmentation violation
 Generating stack trace...
 0x00be7749 in TBranchElement::ReadLeaves(TBuffer&) + 0x63b from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libTree.so
 0x00be06f8 in TBranch::GetEntry(int, int) + 0x1a8 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libTree.so
 0x00be6911 in TBranchElement::GetEntry(int, int) + 0x1c3 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libTree.so
 0x00be68c2 in TBranchElement::GetEntry(int, int) + 0x174 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libTree.so
 0x00c034ac in TTree::GetEntry(int, int) + 0x94 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libTree.so
 0x00c1b7a7 in <unknown> from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libTree.so
 0x0069a902 in G__call_cppfunc + 0x263 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0068a6ad in G__interpret_func + 0x6d7 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x00672ca3 in G__getfunction + 0x1295 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x006f4155 in G__getstructmem + 0x82d from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x006ee261 in G__getvariable + 0x4bc from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0066a51c in G__getitem + 0x5c1 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x006691ac in G__getexpr + 0x6fcf from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x006aebeb in G__exec_function + 0x1d0 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x006b56b1 in G__exec_statement + 0x23af from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x00653253 in G__exec_tempfile_core + 0x2ce from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x00653430 in G__exec_tempfile_fp + 0x22 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x006bd25a in G__process_cmd + 0x43f9 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x002574c7 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0x9b from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x001dda61 in TApplication::ProcessLine(char const*, bool, int*) + 0x577 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x00fc6e06 in TRint::HandleTermInput() + 0x1b2 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libRint.so
 0x00fc5d38 in TTermInputHandler::Notify() + 0x24 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libRint.so
 0x00fc75c0 in TTermInputHandler::ReadNotify() + 0x12 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libRint.so
 0x002b70c3 in TUnixSystem::CheckDescriptors() + 0xed from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x002b6894 in TUnixSystem::DispatchOneEvent(bool) + 0x10a from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x0022a665 in TSystem::InnerLoop() + 0x1b from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x0022a5fe in TSystem::Run() + 0x78 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x001de4ab in TApplication::Run(bool) + 0x2d from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x00fc6932 in TRint::Run(bool) + 0x2e4 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libRint.so
 0x080488d1 in main + 0x71 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/bin/root.exe
 0x00ff479d in __libc_start_main + 0xed from /lib/tls/libc.so.6
 0x080487d5 in _Unwind_Resume + 0x31 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/bin/root.exe

I thought it might be something to do with how I’m using the the tree so tried dumping all the branches to a TObjArray (those bits are in the file as comments), in this case it gets a bit further but prints the wrong values then seg faults with:

root [4] .x TreeRead.C
File loaded
Event tree loaded
Looking at event tree
Number of entries : 1
Number of entries : 1
 Getting entry 0
 Entry 0 got
 Run Number 154426004   (<---- this should be 1 )
 Event Number 7190368   (<---- this should be 0 )
Jet tree loaded
Number of jets : 26999784   (<---- this should be 1 )

 *** Break *** segmentation violation
 Generating stack trace...
 0x0026c902 in G__call_cppfunc + 0x263 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0025c6ad in G__interpret_func + 0x6d7 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x00244ca3 in G__getfunction + 0x1295 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x002c6155 in G__getstructmem + 0x82d from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x002c0261 in G__getvariable + 0x4bc from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023c51c in G__getitem + 0x5c1 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023b1ac in G__getexpr + 0x6fcf from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x002445f2 in G__getfunction + 0xbe4 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023c54c in G__getitem + 0x5f1 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023b1ac in G__getexpr + 0x6fcf from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023abbd in G__getexpr + 0x69e0 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0028792c in G__exec_statement + 0x262a from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0028498c in G__exec_loop + 0x23e from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x00285048 in G__exec_for + 0x18f from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0028740f in G__exec_statement + 0x210d from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0028498c in G__exec_loop + 0x23e from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x00285048 in G__exec_for + 0x18f from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0028740f in G__exec_statement + 0x210d from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0025dd85 in G__interpret_func + 0x1daf from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0024530b in G__getfunction + 0x18fd from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023c54c in G__getitem + 0x5f1 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023b1ac in G__getexpr + 0x6fcf from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x00280beb in G__exec_function + 0x1d0 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x002876b1 in G__exec_statement + 0x23af from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0025dd85 in G__interpret_func + 0x1daf from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0024530b in G__getfunction + 0x18fd from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023c54c in G__getitem + 0x5f1 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0023b1ac in G__getexpr + 0x6fcf from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x00233e8b in G__calc_internal + 0x2a4 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0028ceae in G__process_cmd + 0x204d from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCint.so
 0x0085c4c7 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0x9b from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x0085c5b6 in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) + 0x46 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x007e328d in TApplication::ProcessFile(char const*, int*) + 0x821 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x007e29f3 in TApplication::ProcessLine(char const*, bool, int*) + 0x509 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x001eae06 in TRint::HandleTermInput() + 0x1b2 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libRint.so
 0x001e9d38 in TTermInputHandler::Notify() + 0x24 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libRint.so
 0x001eb5c0 in TTermInputHandler::ReadNotify() + 0x12 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libRint.so
 0x008bc0c3 in TUnixSystem::CheckDescriptors() + 0xed from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x008bb894 in TUnixSystem::DispatchOneEvent(bool) + 0x10a from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x0082f665 in TSystem::InnerLoop() + 0x1b from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x0082f5fe in TSystem::Run() + 0x78 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x007e34ab in TApplication::Run(bool) + 0x2d from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libCore.so
 0x001ea932 in TRint::Run(bool) + 0x2e4 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/lib/libRint.so
 0x080488d1 in main + 0x71 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/bin/root.exe
 0x00f6a79d in __libc_start_main + 0xed from /lib/tls/libc.so.6
 0x080487d5 in _Unwind_Resume + 0x31 from /afs/cern.ch/cms/external/lcg/external/root/3.10.02/slc3_ia32_gcc323/root/bin/root.exe
Root > Function read() busy flag cleared
Function TreeRead() busy flag cleared

My thinking is that something (probably a pointer) is getting confused when the file is written, but I can’t see where/why that would be happening. Am I doing something daft?
Cheers
Simon

Hi,

ROOT 3.10/02 is relatively old. Could you try to reproduce the problem with a newer version of ROOT (preferably ROOT 4.04/02).

Thanks,
Philippe.

Hi Philippe,
Unfortunately not - the code that generates the root tree and the lib containing my objects run in the CMS ORCA framework, and the current version is built on ROOT 3.10/02. I think an upgrade is planned for the future, but I have no control over the version of root I use.
I think the problem is in the reading of the TTree (TreeRead.C) and it seems to be when I try to access the MyEvent object itself, or the TObjArrays that the object contains.
Using myEvtTree->MakeClass() I can correctly access the event and run numbers (which are just int’s in the MyEvent class), but currently can’t successfully access the TObjArrays holding my jet info.
Cheers
Simon

Try replacing

MyEvent *evt; with

MyEvent *evt=0; Cheers,
Philippe

Hi Philippe,
I’ve tried that :slight_smile: It seems that storing pointers is the issue. If I store a TObjArray instead of a TObjArray* and a MyEvent instead of a MyEvent* it seems to work - I can read back from the TTree the arrays. However the TObjArray stores pointers and when I read these back in it seems that the pointers are pointing to a memory address but the memory contains the wrong data. Is there anything that needs to be done to store pointers to TTrees?
Cheers
Simon

Hi,

You also need to write a proper default constructor:

//Needed for root MyEvent::MyEvent(){};should initialize ALL data members to a good value (for pointers the correct value depends on whether you use //-> or not). Anyway, in your case you are probably better off using embedded object.

Cheers,
Philippe.