TChain

From: Sean Kelly (kelly@physics.ucla.edu)
Date: Thu Sep 03 1998 - 01:02:30 MEST


Hi Rooters,

I have written a short program to excercise the TChain class.  Can anyone
see where I am in error.  I have included below two short programs, and
their output. One reads a tree, the other, a chain containing the same
file and no other.  The latter generates a segmentation violation.

thanks

Sean Kelly


This code generates the expected output

{
  gROOT->Reset();
  
  TFile f("run2889a.root");
  TTree *e896 = (TTree*)f.Get("e896");
  
  Event *event = new Event();
  Int_t nevent;  
  Int_t nb = 0;

  e896->SetBranchAddress("event", &event);
  nevent = e896->GetEntries();
  
  for(Int_t i=0;i<10;i++) {
    nb += e896->GetEvent(i);
    printf("Run  = %i\t Event  = %i\tTracks = %i\tTops = %i\tHyps = %i\n",
	   event->evtHdr->run, event->evtHdr->event, event->nTrk,
           event->nTop, event->nPhy);
    event->Clear();         
  }
  Float_t mbytes = 0.000001*nb;
  printf("%d events and %d bytes read.\n",nevent,nb);
  f.Close();
}

root [3] .x nochain.C
Run  = 2889      Event  = 8     Tracks = 5      Tops = 1        Hyps = 0
Run  = 2889      Event  = 944   Tracks = 9      Tops = 1        Hyps = 0
Run  = 2889      Event  = 2442  Tracks = 6      Tops = 1        Hyps = 0
Run  = 2889      Event  = 2794  Tracks = 10     Tops = 1        Hyps = 0
Run  = 2889      Event  = 4480  Tracks = 11     Tops = 1        Hyps = 0
Run  = 2889      Event  = 5302  Tracks = 13     Tops = 1        Hyps = 0
Run  = 2889      Event  = 8194  Tracks = 6      Tops = 1        Hyps = 0
Run  = 2889      Event  = 10382 Tracks = 5      Tops = 1        Hyps = 0
Run  = 2889      Event  = 11678 Tracks = 9      Tops = 1        Hyps = 0
Run  = 2889      Event  = 12348 Tracks = 4      Tops = 1        Hyps = 0
287 events and 6960 bytes read.

The equivalent code with a chain containing a the same file and no others
causes a segmentation violation.

{
  gROOT->Reset();
    
  TChain chain("e896");
  chain.Add("run2889a.root");

  Event *event = new Event();
  Int_t nevent;  
  Int_t nb = 0;

  chain->SetBranchAddress("event", &event);
  nevent = chain->GetEntries();
  
  for (Int_t i=0;i<10;i++) {
    nb += chain->GetEvent(i,1);                
    printf("Run  = %i\t Event  = %i\tTracks = %i\tTops = %i\tHyps = %i\n",
	   event->evtHdr->run, event->evtHdr->event, event->nTrk,
           event->nTop, event->nPhy);
           event->Clear();         
  }	
  Float_t mbytes = 0.000001*nb;
  printf("%d events and %d bytes read.\n",nevent,nb);
}

root [0] .x load.C
root [1] .x chain.C
Run  = 2889      Event  = 8     Tracks = 5      Tops = 1        Hyps = 0

 *** Break *** segmentation violation



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:34:37 MET