[ROOT] Savings TF1 and graphs.

From: Ray Fliller III (rfliller@bnl.gov)
Date: Mon Nov 06 2000 - 16:22:52 MET


  Hello rooters,

   I have the following problem using ROOT v 2.23/12 in Linux.

   I have a compiled class (see stripped down version below) which 
contains a TGraphErrors and a TF1.  I fit the TF1 to the data in the TGraphErrors, 
and save it to a root file.  So far, so good.  When I load it later on, 
and go to look at the fit, and jiggle some parameters about, etc., it 
tells me that the function does not exist and/or a segmentation violation 
ensues.  Upon investigation, I noticed the following:

  1) the pointer gROOT->GetFunction("name") points to somewhere other 
     than the function address.

  2)  The same pointer in the TGraphErrors points to somewhere strange 
      as  well.

  3) THe first operation that I make in the function (a Fit, changea  
     Parameter range, or change a PArameter) works O.K.    But after 
     that, I have problems.

   4) THe only way I have to get around the problem is to delete the 
      function and make an identical on with a different name, or change 
      the gROOT->GetFunction() pointer to that function, and redraw the 
      graph. Both of which still leave open the possibility of future segmetation 
      violations.

Code:

test.h
#ifndef __test__
#define __test__
#include "TCanvas.h"
#include "TGraphErrors.h"
#include "TH1.h"
#include "TF1.h"
#include "TObject.h"
 
class test:public TObject{
 public:
  TCanvas *canvas;
  TGraphErrors *graph;
  TF1 *func;
 
  test();
  virtual ~test();
 
  ClassDef(test,1)
 
};    
 
#endif

test.cxx
#include "test.h"
#include "TROOT.h"
#include <new>
extern TROOT *gROOT;
 
ClassImp(test);
 
 
test::test()
{
  canvas=0;
  graph=0;
  func=0;
}
 
test::~test()
{
 
  if(gROOT->GetListOfCanvases()->FindObject(canvas)) delete canvas;
  canvas=0;
  delete graph;
  graph=0;
  delete func;
  func=0;
}


 RAINMAN
      "How much does a piece of gum cost Ray?"
      "About $100."
      "How much does a new car cost Ray?"
      "`Bout $100."
      "There goes working for NASA!"

==============================================================================
Ray Fliller: rfliller@bnl.gov      Office Phone: (631)-344-6124 
C-A Accelerator Physics     
Building 911
Brookhaven National Lab
Upton, NY 11973                    Office: Room 211
==============================================================================



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:36 MET