I want to load a macro (I know the path and name of if, that means I can access the macro) and then try to find out, what signature this macro has. For example:
- User gives path (whatever) and name (“say myMacro.C”)
- Now I want to check, whether the macro “myMacro” has the return type Bool_t and takes a Double*-Pointer as a parameter, i.e. the signature looks like:
“Bool_t myMacro(Double_t* someParameter)”
At the moment I use TEveMacro to open the macro file, then get the lines in it and check whether one line contains this signature. But I do not really like this method for some reasons.
I think it might be possible to do it in a different way. Maybe one can use CINT to do it because when I load a macro in CINT via .L myMacro.C, CINT knows the signature (you can press “tab” and you will see it).
Thanks in advance for your help.
gROOT->GetGlobalFunction("myMacro"); will return a TFunction object describing the function.
thank you very much, it is working.
However, there is some small problem left:
Let us consider signatures of the type:
void myMacro(TObject*, Double_t*&, Int_t&)
If I use
ROOT->GetGlobalFunctionWithPrototype("myMacro", "TObject*, Double_t*&, Int_t&, kTRUE)
for identification, I will also find functions defined as follows:
void myMacro(TObject*, Double_t*&, Double_t)
void myMacro(TObject*, Double_t*&, Int_t)
(and similar functions). The same problem for the second parameter. But I want to check, whether the third parameter is really a reference of type integer and not a double or a non-reference integer, …
My idea is to load a macro, use GetGlobalFunctionWithPrototype and check, whether the return value is 0x0. If so, the macro has not the correct signature.
Is there a way to fix the problem mentioned above?
I just discovered a method to do exactly what I want:
In addition to the check with GetGlobalFunctionWithPrototype (cf. above) I used the following check:
if (strstr(myTFunction->GetMangledName(), "ParameterSomeCharacters") != 0x0)
It does not look beautiful, but it does its job. To find the correct comparison sequence “ParameterSomeCharacters”, one can first import a macro with the correct signature and check its mangled name.