Re: [ROOT] Can't Clone my class

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Apr 10 2001 - 09:15:55 MEST


Hi Miha,

When TF1 objects are cloned, the TF1::Streamer is called. This function saves
the values of the TF1 function at fNpx points in case of interpreted or compiled
functions because these functions may not be available in the program reading
back the object. There is a problem in TF1::Save (the range is not correctly
saved).
I have fixed the problem in teh development version in CVS.
Meanwhile, I suggest you use TF1::DrawCopy instead of Clone.

   TF1 *f1 = new TF1("f1", coocoo, -3, 3, 1);
   f1 -> SetParameter(0, 1);
   f1 -> DrawCopy();
   f1 -> SetParameter(0, -1);
   f1 -> Draw("same");

Rene Brun

miha.puc@marvin.fmf.uni-lj.si wrote:
> 
> Hi!
> Thank you Rene. Your suggestion inplicitly led me to the problem (I didn't
> realize that TF1::Streamer() is evaluating the TF1 funtion (saving in
> fSave) and some global pointer was not set at that time yet.
> 
> But I got to another problem. It seems to me that TF1::Clone() doesn't
> work well. I compiled the code below and the function f2 was drawn as
> constant 0.
> 
> --------------------------------
> #include <TROOT.h>
> #include <TApplication.h>
> #include <TGClient.h>
> #include <TF1.h>
> 
> Double_t coocoo(Double_t *x, Double_t *par) {
>    Double_t xx = *x - par[0];
>    return xx * xx - 1;
> }
> 
> extern void InitGui();
> VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
> 
> TROOT root("GUI", "GUI test environement", initfuncs);
> 
> int main(int argc, char **argv)
> {
>    TApplication *Appp = new TApplication("App", &argc, argv);
> 
>    TF1 *f1 = new TF1("f1", coocoo, -3, 3, 1);
>    f1 -> SetParameter(0, 1);
>    f1 -> Draw();
> 
>    TF1 *f2 = (TF1*) f1->Clone();
>    f2 -> SetParameter(0, -1);
>    f2 -> Draw("same");
> 
>    Appp->Run(1);
> }
> -----------------------------------
> 
> On Mon, 9 Apr 2001, Rene Brun wrote:
> 
> > Hi Miha,
> >
> > Cloning an object (TObject *obj) is done via obj->Clone().
> > This function creates a new object of your class by calling
> > its default constructor, then calls the Streamer function of your class to
> > copy the members.
> >
> > You must make sure that your constructor initializes correctly all members, in
> > particular the pointers. In your case, one of the pointers fCTFoonc,
> > fTFoonc, fLst or fMoother is probably not set. Check also the constructor
> > of your class TFoonction for similar symptoms.
> >
> > Rene Brun
> >
> > miha.puc@marvin.fmf.uni-lj.si wrote:
> > >
> > > Hi!
> > > I'm new to roottalk.
> > > So can anybody help me?
> > > I wrote a class having the following data members:
> > >
> > > class TFoonction : public TNamed {
> > > protected:
> > >    Int_t fNprs;
> > >    Int_t fMyIdx;
> > >    Int_t fMyIdxGlobal;
> > >    Double_t fXmin, fXmax;
> > >    TF1 *fCTFoonc;
> > >    TF1 *fTFoonc;
> > >    TList *fLst;
> > >    TFoonction* fMoother;
> > >
> > > If I try to clone an object of this class I get a segfault.
> > > I rely on rootcint to generate the Streamer function.
> > > I only tried if with compiled code. I use ROOT v 3.00/06 RH Linux 6.2.
> > >
> > > Miha
> > > --
> >
> 
> --



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:41 MET