gROOT->ProcessLine(".X blup.C") with arguments

Dear all,

I have a simple problem and couldn’t solve it with the help of this forum or the users guide since 2 days.

I have an array of scripts which should take the output arguments from the last one, passing into the next one and so on.

But unfortunately I can’t get ROOT to pass my arguments into the next script. Here is a simple example:

The main macro:
#include
#include

void Analysis(){
// code
double result1 = something;
double result2 = something2;
gROOT->ProcessLine(".X doAnalysis.C(result1,result2)");
}//close main macro

The embedded macro:
#include
#include

void doAnalysis(double a, double b){
cout << " test execution of macro " << endl;
cout << " result1: " << a << endl;
cout << " result2: " << b << endl;
}//close embedded macro

If I pass numbers directly, for example:
gROOT->ProcessLine(“doAnalysis(1,2)”);
I get the expected output:
test execution of macro
result1: a
result2: b

If I try to pass variables from the calculations in the main script, I get the errors:

input_line_98:2:14: error: use of undeclared identifier ‘result1’
(doAnalysis(result1, result2))
input_line_98:2:23: error: use of undeclared identifier ‘result2’
(doAnalysis(result1, result2))

It seems this problem is to simple to find some answers, but maybe some of you could solve it easily?

Best regards,
Paul

gROOT->ProcessLine(Form(".x doAnalysis(%f,%f)",result1,result2));
should work if result1 and result2 are float or double. Otherwise, replace %f by the apporpriate type.

1 Like

Thanks a lot, it worked!
So easy that it hurts, knowing that I have wasted 2 days for this…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.