I am trying to use a function in a macro that I load only upon its existence. You can see from the macros that I transcribe below (I cannot attach 3 files…) that:
“mainMacro.C” loads “conditionaMacro.C” if it exists;
“mainMacro.C” then runs “testMacro.C”
in “testMacro.C” the function defined in “conditionalMacro.C” is called only if this macro exists.
If “conditionalMacro.C” exists, everything works, but if it doesn’t, there is an error of “undeclared identifier” in “testMacro.C”, of course. Can one overcome this problem?
if (gSystem->AccessPathName("conditionalMacro.C", kFileExists)==0) {
gROOT->ProcessLine("conditionalMacro();"); // try this ...
// gInterpreter->ProcessLine("conditionalMacro();"); // ... or that
}
BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).
Thanks for the suggestion, but for me it does not work. I tried both options (I guess you meant to use these lines in testMacro.C, right?), and even if I get no error, the conditionalMacro is not executed (I have no output from it). Did it work for you?
Thanks also for the comment about the format, I will follow it next time.
I have then a question: what is the difference between the three:
conditionalMacro(); // not working
gROOT->ProcessLine("conditionalMacro();"); // try this ...
// gInterpreter->ProcessLine("conditionalMacro();"); // ... or that
Yes, the first does not work but the others do, I would be curious to know why
And I know that my first version works in ROOT5, this is what I started from - I am porting my code from ROOT5 to ROOT6.