Hi Rene!
Ok I get it. But could it be done so that the Streamer retrieved the TF1's
compiled function IF it was avilable? Because the coocoo was just a little
example, my real problem is this:
I need to put together some model function (in runtime) to fit a
histogram.
Thus I designed this TFoonction class. For short it works like this:
TF1 *fCTFoonc // This TF1 uses any compiled C style function.
Tlist *fLst // A list to hold TFoonction objects (let's say daughters).
TF1 *fTFoonc // Is retuned by TFoonction::GetTF1() and
//it uses compiled function CFoonction which calls
//TFoonction's Eval member function via a global pointer.
Eval member func. first
Calls fCTFoonc->EvalPar(...) and then
iterates over fLst and calls all the daugthers's Eval.
Returns sum of all the results.
The daughters are added to fLst via TFoonction::Add(TFoonction *Foo)
and this one calls Foo->Clone(). I need clones beacuse the same TFoonction
object can be added to different TFoonction objects many times. And
they can be given different names, and parameter values ...
I could avoid cloning and copy relevant datamembers to a new daughter
"by hand" but the fTFoonc's pointer to compiled C function is essential.
Is there a way to get it from TF1 object?
And I wouldn't mind saving all together to a file for some later use.
Miha Puc
On Tue, 10 Apr 2001, Rene Brun wrote:
> 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