Passing parameters

Dear experts,
I have a code that runs perfectly with no problem. I run it using “root -l filename.C++” command. I would like to modify the code so it would do different things based on the parameter I pass to the code when running it. For example do addition of two variables (defined in the code) when I pass the parameter “add” to the code and do multiplication of those variables when I pass “mult” to the code. I know how to do this when running the code when I do “.L filename()” and then “filename(“parameter”)” but I don’t know how to pass these parameters when I run the code using this command “root -l filename.C++”. could you point me in the right direction please. Many thanks!


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hello @Natilus,

What you want can be accomplished with the following command line:

$ root -l -q -e '.x filename(arg1, arg2, ..., argN)'

Cheers,
J.

Hi @jalopezg ,
Thank you very much for your help. That worked perfectly, the only tiny problem is that after the code runs and generates the plots and histograms, it exits the root program and consequently all the plots and histograms close. is there anyway I can keep root running and close it manually (.q)?
Thanks again

Hello @Natilus,

For that, you just have to remove the -q command line option.

Cheers,
J.

Hi @jalopezg ,
Thank you very much for your help! I really appreciate it.