RE: your mail (TMyClass)

From: Anton Fokin (fokin@tsl.uu.se)
Date: Sun Feb 27 2000 - 20:42:53 MET


Thanks Rene,

by the end of day I started to understand things... The magic
G__p2f2funcname call was a bit confusing but finally I realised I do not
need it at all if I already have a name of my function. The bytecode works
hundreds of times faster than my ProcessLine implementation.

/Anton

Anton,
As shown by Pasha, you can always call gROOT->ProcessLine
from the compiled code to execute via the interpreter.
However, this may be a very slow procedure in the case
you intend to use this service.
As you were guessing, my answer is "yes, look in the second TF1
constructor". This is a real example and you have to understand
each of the following lines
 - in the constructor
   char *funcname = G__p2f2funcname(fcn);
   SetTitle(funcname);
   if (funcname) {
      fMethodCall = new TMethodCall();
      fMethodCall->InitWithPrototype(funcname,"Double_t*,Double_t*");
      fNumber = -1;
   } else {
      Printf("Function:%s cannot be compiled",name);
   }

 - in TF1::EvalPar
   Double_t result = 0;
   if (fMethodCall) fMethodCall->Execute(result);

It is up to you to do the bookeeping of fMethodCall as well as
the function name.
The method above is efficient. Each call to fMethodCall->Execute
executes pre-compiled bytecode as opposed to string interpretation
in the case of gROOT->ProcessLine.

Rene Brun

On Sun, 27 Feb 2000, Anton Fokin wrote:

> Hello!
>
> I am in troubles with calling interpreter function from compiled code.
>
> Let's say I have compiled class
>
> class TMyClass {
> private:
>   Float_t (*fFunc) ();
> public:
>      void SetFunction(const char* Macro);
>   Float_t Function()                      { return (*fFunc)() }
> };
>
>
> and a macro in Macro.C file
>
> Float_t
> MyFunc()
> {
>   printf("the answer is ...\n");
>   return 42;
> }
>
> now I would like to write in my compiled program:
>
>
> TMyClass *MyClass = new TMyClass();
> MyClass->SetFunction("Macro.C");
> Float_t Answer = MyClass->Function();
>
>
> How TMyClass::SetFunction(const char* Macro) should look like? I am sure
you
> suggest me to look into TF1 implementation, but could you write a few
lines
> of example code instead? I hope it helps others too ...
>
> Best regards,
> Anton
>



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