Seg Fault with GetEntry()

Hello everyone,

I’m trying to read in a couple branches from a tree, but I get a set fault when I call a branch that’s a vector<vector> at tree->GetEntry(). Otherwise, if I comment out the two lines containing jet_FracEnergyPerSampling things run fine.

#include <stdlib.h>
#include <typeinfo>
#include <vector>
#include <algorithm>
#include <iterator>

TFile *f = TFile::Open("Nominal.root");
TTree *q = (TTree*)f->Get("outTree");

  int njet = 0;
  vector< vector<float> > *jet_EnergyPerSampling = 0;
  vector<float> *jet_pt =0;
  vector<int> *jet_FracSamplingMaxIndex =0;
  q->SetBranchAddress("njet", &njet);
  q->SetBranchAddress("jet_pt", &jet_pt);
  q->SetBranchAddress("jet_FracSamplingMaxIndex", &jet_FracSamplingMaxIndex);
  q->SetBranchAddress("jet_EnergyPerSampling", &jet_EnergyPerSampling);
  cout << "SAMP " << jet_EnergyPerSampling[0][0] << endl;

  cout << "ENTRIES" << q->GetEntries() << endl;
  int entries = q->GetEntries();
  for (int ent = 0; ent < entries; ent++) {

I’ve attached the error output below. Am I missing something?

Thanks in advance!
errors.pdf (27.7 KB)

I think we need at least the output of “outTree->Print();” (or maybe better the “Nominal.root” file).

Sorry about that! The file is too large, so here’s the output of outTree->Print().
outtree.pdf (27.8 KB)

I think it should be:
vector *jet_FracSamplingMaxIndex = 0; // Br 23

You should also “protect” access to “jet_EnergyPerSampling”. Something like:
if (jet_EnergyPerSampling && jet_EnergyPerSampling->size() && (jet_EnergyPerSampling->at(0)).size())
std::cout << "SAMP " << (*jet_EnergyPerSampling)[0][0] << std::endl;
Instead of “(*jet_EnergyPerSampling)[0][0]”, you could also try a more secure:

If you use compiled code, it may happen that you need to build a dictionary for “vector<vector >”.
For “std::vector<std::vector >” see [url=
For “std::vector<std::vectorstd::string >” see [url=