Re: Reading event from a file

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Feb 21 1997 - 14:50:40 MET


Laurent Mirabito wrote:
> 
>         Hello all,
> 
> I used ROOT to store events on file. Basically the structure is the
> following :
> 
> a TEvent contains 2 TLists :
> 
>        - 1 Liste of Vertex
>        - 1 Liste of Particle.
> 
> I have no problems to build and store my event from Zebra to root files
> but when I try to read them the memory seems to be not cleared after
> each event and I crash. Here is the code of reading ( I checked that
> the " delete " of each event is working well - it deletes all members
> of the lists -)  :
> 
> #include <stdlib.h>
> #include <iostream.h>
> #include "math.h"
> #include "TROOT.h"
> #include "TFile.h"
> #include "TList.h"
> #include "TH1.h"
> 
> #include "TKey.h"
> #include "TDirectory.h"
> #include "Rtypes.h"
> 
> #include "TVtx.h"
> #include "TVecp.h"
> #include "TTrac.h"
> #include "THaid.h"
> #include "TDedx.h"
> #include "TMuid.h"
> #include "TElid.h"
> #include "TDpar.h"
> #include "TEvent.h"
> 
> extern TTrac* GetTTrac(const int);
> 
> extern Bool_t IsAGoodTrack(TDpar *);
> TFile *fni;
> TFile *fnh;
> TH1F *hnp,*het,*hip,*hmds;
> void analyse(TEvent *ev);
> 
> //______________________________________________________________________________
> main(int argc, char **argv)
> {
> // Create a new ROOT binary machine independent file.
> // Note that this file may contain any kind of ROOT objects, histograms,
> // pictures, graphics objects, detector geometries, tracks, events, etc..
> // This file is now becoming the current directory.
>   TROOT simple("simple","Histograms and trees");
>   Int_t ier;
>   float bt,bf;
>   hnp = new TH1F("hnp1","Number of particle",70,0,70);
>   het = new TH1F("het1","Total energy",200,0,400);
>   hip = new TH1F("hip","paramtre d impact",200,-3.,3.);
>   hmds = new TH1F("hmds","Expected mass of Ds ",50,1.7,2.2);
>   fnh = new TFile("histo.root","RECREATE");
>   Int_t nev=0;
>   TFile evf("/afs/in2p3.fr/group/delphi/mirabito/Event.root","OLD");
>   evf.cd();
>   TList *evlist = gDirectory->GetListOfKeys();
>   TKey *key;
>   cout << "test " << evlist->GetSize() << endl;
>   for (int i=0;i<evlist->GetSize() ;i++)
>     {
>       key = (TKey*) evlist->At(i);
>       TEvent* ev = ( TEvent *) key->Read();
>       //           cout << "toto " << ev->GetRun() << " " << ev->GetEvt() << endl;
>       nev++;
>       if (nev%100 == 0)
>         {
>           printf("%d Run %d Event %d \n",nev,ev->GetRun(),ev->GetEvt());
>           printf("%f  %f %f \n",
>                  ev->GetBeamoy()[0],ev->GetBeamoy()[1],ev->GetBeamoy()[2]);
>         }
> //           analyse(ev);
>       delete ev;
>     }
>   evf.Close();
> }
>   fnh->cd();
>   hnp->Write();
>   het->Write();
>   hip->Write();
>   hmds->Write();
> 
> 
>   fnh->Close();
> }

Laurent,
Very likely you forget to delete something in your event class.
I need access to your classes to investigate.
I would also suggest that you change your loop on keys
for an iterator. It will be simpler and much faster.
see example in http://root.cern.ch/root/HowtoRead.html

In case you use a TList, TObjArray,etc in your Event class,
you must make sure in your Event destructor that you delete
the array as well.
For example if you have a TList of particles fParticles, you
must have a statement like
   fParticles->Delete() in the Event destructor.

Rene Brun



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