TTree::GetEntry() segmentation fault?

Here’s a snippet of the code I was using, and when doing .x test.root+ , segmentation violation problem.
I don’t understand. The problem occurs when I have the line GetEntry() in the loop.
The full code ( a few pages) works fine and I can produce my graphs and histograms, but when I rewrite the whole code, this time compiling after writing one or two new lines just for fun, I stumbled on this problem. Seems like the full successful code was hiding some problems.

#include
#include “TGraph.h”
#include “TCanvas.h”
#include “TBranch.h”
#include “TTree.h”
#include “TFile.h”
#include “TMultiGraph.h”
#include “TH2F.h”
#include “TH1F.h”

void test()
{

TFile *file = new TFile(“madHZmu.AOD.root”);
TTree tree = (TTree)file->Get(“CollectionTree”);

vector *trialmass;

int nentries = (int)tree->GetEntries();

cout << nentries << endl;

TBranch M = (TBranch)tree->GetBranch(“M”);

M->SetAddress(&eminus_E);

M->SetAutoDelete(kTRUE);

TH1F* hist = new TH1F(“hist”, “Mum’s mass”, 100, 0, 1000000);

TH2F* kink = new TH2F(“kink”, “Kink”, 100, 301000, 2001000, 100, 3001000, 9001000);

TMultiGraph* multigraph = new TMultiGraph(“multigraph”, “multi”);
vector< TGraph* > graph;
vector Function;
vector E;

    for(int i = 0; i < nentries ; i++){
    tree->GetEntry(i);    <<<-------------- here's the problem...

    }

*** Break *** segmentation violation
(no debugging symbols found)
Using host libthread_db library “/lib/tls/libthread_db.so.1”.
Attaching to program: /proc/22906/exe, process 22906
(no debugging symbols found)…done.
[Thread debugging using libthread_db enabled]
[New Thread -1208691008 (LWP 22906)]
(no debugging symbols found)…done.
0x002407a2 in _dl_sysinfo_int80 () from /lib/ld-linux.so.2
#1 0x00e9ff13 in __waitpid_nocancel () from /lib/tls/libc.so.6
#2 0x00e497b9 in do_system () from /lib/tls/libc.so.6
#3 0x00e0e98d in system () from /lib/tls/libpthread.so.0
#4 0x0041badf in TUnixSystem::Exec () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#5 0x004214ed in TUnixSystem::StackTrace () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#6 0x0041e1aa in TUnixSystem::DispatchSignals () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#7 0x0041e238 in SigHandler () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#8 0x0041d485 in sighandler () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#9
#10 0x03fca718 in TBufferFile::ReadFastArray () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#11 0x03fd8890 in TEmulatedCollectionProxy::ReadItems ()
from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#12 0x03fd8a2d in TEmulatedCollectionProxy::Streamer ()
from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#13 0x03fcf8b9 in TCollectionStreamer::Streamer () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#14 0x03fd0315 in TCollectionClassStreamer::operator() ()
from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#15 0x003facbb in TClass::Streamer () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#16 0x03fcaaa5 in TBufferFile::ReadFastArray () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#17 0x04041ba5 in TStreamerInfo::ReadBuffer<char**> ()
from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRIO.so
#18 0x01bc5cc9 in TBranchElement::ReadLeaves () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libTree.so
#19 0x01bbe817 in TBranch::GetEntry () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libTree.so
#20 0x01bc3a5b in TBranchElement::GetEntry () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libTree.so
#21 0x01c0139d in TTree::GetEntry () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libTree.so
#22 0x02c345f6 in test () from /home/cloh/testarea/14.2.25/PhysicsAnalysis/AnalysisCommon/AnalysisExamples/run/./test_root.so
#23 0x02c348a2 in G__filef0kQRi__0_1236 ()
from /home/cloh/testarea/14.2.25/PhysicsAnalysis/AnalysisCommon/AnalysisExamples/run/./test_root.so
#24 0x008cf95b in Cint::G__ExceptionWrapper () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCint.so
#25 0x009850bd in G__call_cppfunc () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCint.so
#26 0x0096b3a5 in G__interpret_func () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCint.so
#27 0x0095a4ea in G__getfunction () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCint.so
#28 0x0093fe7c in G__getitem () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCint.so
#29 0x0094299f in G__getexpr () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCint.so
#30 0x0094ae38 in G__calc_internal () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCint.so
#31 0x009bd766 in G__process_cmd () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCint.so
#32 0x003eeff3 in TCint::ProcessLine () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#33 0x003ef12a in TCint::ProcessLineSynch () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#34 0x0035e5df in TApplication::ExecuteFile () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#35 0x0035e902 in TApplication::ProcessFile () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#36 0x0035c92a in TApplication::ProcessLine () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#37 0x0011e1a8 in TRint::HandleTermInput () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRint.so
#38 0x0011c840 in TTermInputHandler::Notify () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRint.so
#39 0x0011ea56 in TTermInputHandler::ReadNotify () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRint.so
#40 0x0041a46a in TUnixSystem::CheckDescriptors () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#41 0x0041e688 in TUnixSystem::DispatchOneEvent () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#42 0x003b217c in TSystem::InnerLoop () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#43 0x003b1f42 in TSystem::Run () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#44 0x0035cae6 in TApplication::Run () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libCore.so
#45 0x0011cfb2 in TRint::Run () from /home/cloh/14.2.25/sw/lcg/external/root/5.18.00d/slc4_ia32_gcc34/root/lib/libRint.so
#46 0x08048d36 in main ()

You must initialize the pointer that you pass as branch address, ie

vector<double> *trialmass = 0;
Rene

3 Likes