[ROOT] tree with a big number of branches

From: Masoud M.Shafiei (shafiei@kvi.nl)
Date: Mon Aug 12 2002 - 23:47:57 MEST


Dear ROOT users,

    I get "segmentation violation" at the level of filling up my tree.
To my understanding this is due to the shortage of memory and to solve
this problem I used  SetAutoSave(autos=1000) command and set the bufsize
to 1024, nevertheless the problem is still there !
Anybody knows what to do? The code is attached :)

Thanks in advance
Masoud



#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "TROOT.h"
#include "TClass.h"
#include "TTree.h"
#include "TFile.h"
#include "cross.h"
#include "event_structure.h"
#include "tree.h"

#define	MP	 938.27231
#define sqr(x)   ((x)*(x))

TFile         *f;
static TTree         *tree;
extern track_t       track;
extern Island_t      *Islands;
extern float         PbalCoord[2][576];
extern float         AllSolut[2][4][6];
extern int           MainCount;
static int           NoLine;
static const Int_t   bufsize=1024; //16384 = 2^14

extern "C" 
int BookTree()
{
  // initialize no. of lines
  NoLine=0;

  // Book ntuple
  printf("\n<I> Book ntuple .. \n\n");

  // Create a new ROOT file
  f = new TFile("ppg.root","RECREATE","test");  
  // Create a TTree
  tree = new TTree("t","ppg data"); 
  // Set auto save
  const Int_t autos=10;
  t->SetAutoSave(autos);
  // Create branches with all information of salad track No. 1
  tree->Branch("mul1",&mul1,"mul1/I",bufsize);
  tree->Branch("th1",&th1,"th1/F",bufsize);
  tree->Branch("ph1",&ph1,"ph1/F",bufsize);
  tree->Branch("en1",en1,"en1[mul1]/F",bufsize);  
  // Create branches with all information of salad track No. 2
  tree->Branch("mul2",&mul2,"mul2/I",bufsize);
  tree->Branch("th2",&th2,"th2/F",bufsize);
  tree->Branch("ph2",&ph2,"ph2/F",bufsize);
  tree->Branch("en2",en2,"en2[mul2]/F",bufsize);  
  // Create branches with all information of pball track
  tree->Branch("mulg",&mulg,"mulg/I",bufsize);
  tree->Branch("thg",thg,"thg[mulg]/F",bufsize);
  tree->Branch("phg",phg,"phg[mulg]/F",bufsize);
  tree->Branch("delta",delta,"delta[mulg]/F",bufsize);
  tree->Branch("energy",energy,"energy[mulg]/F",bufsize);   
  // Create branches with all information of reconstruction
  tree->Branch("mulr",&mulr,"mulr/I",bufsize);
  tree->Branch("e1r",e1r,"e1r[mulr]/F",bufsize); 
  tree->Branch("e2r",e2r,"e2r[mulr]/F",bufsize);   
  tree->Branch("egr",egr,"egr[mulr]/F",bufsize);   
  tree->Branch("phgr",phgr,"phgr[mulr]/F",bufsize);   

  return(0);
}

extern "C"
int FillTree(int i,int j,int k)
{
  int cnt,id;

  // salad part, track No.1
  mul1=0;
  th1 = track.salad[i].the;
  ph1 = track.salad[i].phi;
  for(cnt=0;cnt<MAX_SALAD;cnt++) 
    if(track.salad[i].ene_e[cnt]) 
      en1[mul1++] = track.salad[i].ene_e[cnt];
  // salad part, track No.2
  mul2=0;
  th2 = track.salad[j].the;
  ph2 = track.salad[j].phi;   
  for(cnt=0;cnt<MAX_SALAD;cnt++) 
    if(track.salad[j].ene_e[cnt]) 
      en2[mul2++] = track.salad[j].ene_e[cnt];
  
  // plastic ball part
  mulg=0;
  for(cnt=0;cnt<Islands[k].no && cnt < MAX_PBALL;cnt++) {
    id=Islands[k].memb[cnt]; 
    thg[cnt] = PbalCoord[0][id];
    phg[cnt] = PbalCoord[1][id];  
    delta[cnt] = Islands[k].delta[cnt];
    energy[cnt] = Islands[k].energy[cnt];
    mulg++; 
  }

  // reconstruction part
  mulr=MainCount;
  for(cnt=0;cnt<MainCount;cnt++) {
    e1r[cnt]  = (Float_t) AllSolut[cnt][0][0]-MP;
    e2r[cnt]  = (Float_t) AllSolut[cnt][1][0]-MP;
    egr[cnt]  = (Float_t) AllSolut[cnt][2][0];
    phgr[cnt] = (Float_t) AllSolut[cnt][2][5];
  }  


  // fill ntuple
  tree->Fill();

  // no of line
  NoLine++;

  return(0);
}

extern "C"
int CloseTree()
{
  // close ntuple
  printf("\n<I> close tree .. \n");

  tree->Print();
  f->Write();
  f->Close();

  // no of lines
  printf("\n<I> %i written in the tree \n",NoLine);

  return(0);
}



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:04 MET