Re: [ROOT] Obtaining the pointer on function from macros

From: Rene Brun (Rene.Brun@cern.ch)
Date: Sun Feb 24 2002 - 19:33:54 MET


Hi Ruben,

You can do this via the class TMethodCall.
For an example of use, see one of the constructors for TF1:
   TF1(const char *name, void *fcn, Double_t xmin, Double_t xmax, Int_t
npar);

In the source, look at the bottom of the function for the following lines:
  if (!fcn) return;
   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);
   }

then look at TF1::EvalPar to see how to call the function from
the compiled code:

Rene Brun

On Sun, 24 Feb 2002, Ruben Shahoian wrote:

> Hello,
> is there any possibility to get the pointer on the function, loaded as
> a macro by CINT? 
> I need to execute from main program (not a macros!) the user defined
> function supplied as a macros (at program compliation time the macros name
> is not defined yet. I imagine comething like this:
> 
> MyClass {
> ...
>   void Init();
>   void UseMacro();
> 
> protected:
>   void    (*fUserMacro)(Int_t);        // pointer on function from user,
>                                        // takes 1 integer argument
>   TString  fUserMacroName;             // name of the user macro
> ...
> } 
> 
> MyClass::Init()
> {
> ...
>    fUserMacro = 0;
>    fUserMacroName ++ = "++";    // to call in compiled mode
>    gROOT->LoadMacro(fUserMacroName.Data());
>    fUserMacro = ?????? GET_POINTER_ON_LOADED_AND_COMPILED_FUNCTION ???     
> ...
> }
> 
> MyClass::UseMacro()
> {
> ...
>  fUserMacro(val1)
> ...
>  fUserMacro(val2)
> 
> ... etc
> 
> }
> 
> If this is not possible, are there any workarounds?
> 
> Regards,
> 	Ruben Shahoyan
> 



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