Re: [ROOT] Cleanup of TGraphs

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sat Mar 16 2002 - 11:31:01 MET


Hi Ben,

See the lines added to your code

Rene Brun

On Mon, 11 Mar 2002, Ben Morgan wrote:

> Hi ROOTers,
>            I have a raw data class for my experiment, and have used 
> MakeClass to generate the skeleton code to read the data from the tree. 
> I'm now trying to add a method to the MakeClass skeleton (which I assume 
> is o.k. to do) to graph some of the data from each event. The problem is 
> that the number of graphs for each event is different (the data is voltage 
> traces from a wire chamber). Also, as there may be as many as thirty 
> traces to graph per event, and I want to look at many events, I need to 
> make sure any preceeding graphs are deleted every time this method is 
> called. In my code (included below), I set an array of pointers to TGraph 
> objects, name the graphs and add these to the 
> current directory (following the example in 
> http://root.cern.ch/root/roottalk/roottalk01/0759.html). Without any 
> delete statements, the code runs fine and generates the required number of 
> TGraphs (using gObjectTable->Print()), and gDirectory->Get("name of 
> Graph") returns a non null pointer (although there is of course a memory 
> leak).
> However, when I try to delete these graphs by using 
> gDirectory->Delete("name of Graph"), the graphs are deleted (looking at 
> gObjectTable), but after executing the method several times, it falls over 
> with a segmentation violation:
> 
>  *** Break *** segmentation violation
> Root > Function GraphEvent() busy flag cleared
> 
> I've also tried getting the graph pointers, casting them to a TGraph and 
> then deleting, but this produces the same seg violation. I'm using ROOT 
> v3.01/06 on a PC running RH6.2, any advice on what's causing the problem 
> would be very gratefully received! Thanks,
> 
> Ben Morgan.
> 
> void RawDataClass::GraphEvent(Int_t entry)
> {
>   b_fNwire->GetEntry(entry);
>   b_fNchan->GetEntry(entry);
>   b_fWaveform->GetEntry(entry);
>  
>   if(fNwire>8)
>     {
>      cout<<"Event has more than eight active wires, try again"<<endl;
>      return;
>     }
>   char name[20];
>   char title[100];
>   const Int_t a = fNwire;  
> 
>   for(Int_t i=0; i<8; i++)
>     {
>      sprintf(name,"Wire%d",i);
>     // gDirectory->Delete(name);  //line deleted
      TGraph *gr = (TGraph*)gDirectory->GetList()->FindObject("name);
//<====new line
      delete gr;  //<==========new line
>     }
> 
>   cout<<"Number of Active Wires = "<<fNwire<<endl;
> 
>   TGraph *G[a];
>   
>   for(Int_t i=0; i<fNwire; i++)
>     {
>       sprintf(name,"Wire%d",i);
>       G[i] = new TGraph(fNchan);
>       G[i]->SetName(name);
>       gDirectory->GetList()->Add(G[i]);
>     }   
>      
> }
> 
> 
> -- 
> -------------------------------------------------------------------------------
> Mr. Ben Morgan
> Postgraduate Student
> University of Sheffield
> Department of Physics & Astronomy
> Hicks Building
> Hounsfield Road
> Sheffield  S3 7RH
> -------------------------------------------------------------------------------
> 



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