Passing function arguments to interpeted macro

Hi, I have a steering macro steer.C that has a call to a dictionary-enabled class MyClass ctor, like this
steer() {

MyClass* cl=new MyClass("/path/to_config_file.C", “func1()”, “func2()”)

}

where config_file.C is another marco containing func1 and func2. Internally, MyClass ctor uses gROOT->LoadMacro and gROOT->ProcessLine to load and execute the functions. What I want is to be able to pass arguments in the line above, like
MyClass* cl=new MyClass("/path/to_config_file.C", “func1(arg1, arg2)”, “func2(arg3)”). This seems to work only for integers, however the optimal for me would be either enums or strings (char*). I have tried using
MyClass* cl=new MyClass("/path/to_config_file.C", “func1(”\arg1", “\arg2”)", “func2(“arg3)””)
but it prints out an err msg about incomplete file steer.C.
Is this supported in principle by some differentiation of the logic above (including maybe using a different function than gROOT->ProcessLine eg gInterpreter->Sth() or is it impossible because of some C++ scope/CINT limitation? Thanks and sorry if this a FAQ,
filimon

Hi filimon,

Maybe putting the backslashes at the right location could help:

Cheers, Bertrand.

Hi, actually I got it wrong in the example I provided. In fact this problem would be caught by (I assume) CINT as
Error: String literal syntax error steer.C:20:
(I just did the check just to be sure that it was not what you mention). Instead, putting the correct slashes as in your example brings these errors (changed to reflect the given example) and using the “1” literal as arg1. In fact it does not contain any reference to incomplete file as I mentioned in the original post (this was an older problem I solved already). steer.C does _not_contain #include at line 20, I have no idea where this comes from, I do use exceptions in MyClass and have #include there. Any hint now that the correct output is provided?

Error: Function func_1(“1”) is not defined in current scope (tmpfile):1:
*** Interpreter error recovered ***
Error: Symbol #include is not defined in current scope steer.C:20:
Error: Symbol exception is not defined in current scope steer.C:20:
Syntax Error: #include steer.C:20:
Error: Symbol G__exception is not defined in current scope steer.C:20:
Error: type G__exception not defined FILE:/home/filimon/…/steer.C LINE:20
*** Interpreter error recovered ***

Hard to guess without the code… Could you post your steer.C macro (the full version, not a subset)?

Well I have to send the full code for MyClass for this. I will try to reproduce it in a simpler form. cheers,
filimon

Hi filimon,

FYI, using gROOT->ProcessLine() requires the same syntax, but with some more backslashes… :wink:

Cheers, Bertrand.

OK, the idea to do a simple example actually demonstrates that ROOT works as expected, so what I want to do is actually doable :slight_smile:
If you put this on a MyClass.C file and do .L MyClass.C++

#include <TROOT.h>

class MyClass {

public:

MyClass(char* pathname, char* func);
~MyClass() {};

ClassDef(MyClass, 1);

};

MyClass::MyClass(char* pathname, char* func) {

gROOT->LoadMacro(pathname);
gROOT->ProcessLine(func);

}

and this

enum number { zero, one, two };

int macro() {

return(0);

}

int func(number arg1, char* arg2) {

std::cerr << arg1 << ’ ’ << arg2 << std::endl;
return(0);

}

in a macro.C file and then do

root> MyClass(“macro.C”, “func(two, “test”)”)

works as expected, I get

root [6] MyClass(“macro.C”, “func(two, “test”)”)
reloading /home/filimon/./macro.C 0
2 test
(int)0
(class MyClass)164656880

So since this is what I want to do and seems to work, I have to figure out where my code differs from this simplification. In my true case I get the -equivalent of-
Error: Symbol two is not defined in current scope (tmpfile):1:
and I am now trying to understand which scope is meant… Maybe some quick hint on this? Thanks,
filimon

The enum definition has to be known at the global scope level, since the “func” function called by gROOT->ProcessLine(func); has to know what “two” stands for, which is fine in your test case, sinceenum number { zero, one, two }; is declared in the global scope (so known by the interpreter). Now, if you define your enum elsewhere (in another scope), you may “hide it” from gROOT/func(), hence this “Symbol two is not defined in current scope” kind of message.

Cheers, Bertrand.