How to correctly add a branch to a saved TTree?

From: Pierre-Luc Drouin <pldrouin_at_physics.carleton.ca>
Date: Sat, 20 Jun 2009 16:46:39 -0400


Hi,

I am trying to add and fill a branch to an existing TTree and I get a segmentation violation error when the number of entries exceeds some value

Here is some code to reproduce the problem: {
  Int_t nentries=500000;

  TFile *file=new TFile("file.root","recreate");
  TTree *tree=new TTree("tree","tree");
  Float_t val=0;

  tree->Branch("br1",&val,"br1/F");

  for(Int_t i=0; i<nentries; ++i) {
    val=i;
    tree->Fill();
}

  file->Write();
  file->Close();
  delete file;

  file=new TFile("file.root","update");
  tree=(TTree*)file->Get("tree");
  TBranch *br=tree->Branch("br2",&val,"br2/F");

  for(Int_t i=0; i<nentries; ++i) {
    val=i;
    br->Fill();
}

  tree->SetEntries(br->GetEntries());

  file->Write();
  file->Close();
  delete file;

  file=new TFile("file.root","read");
  tree=(TTree*)file->Get("tree");
  tree->Draw("br1");
}

The code above works correctly when nentries is 25000 but fails with 500000.

How can I fix this problem?

Thank you!
Pierre-Luc Drouin Received on Sat Jun 20 2009 - 22:47:01 CEST

This archive was generated by hypermail 2.2.0 : Sun Jun 21 2009 - 05:50:05 CEST