Passing arguments to a macro

Hi! Is there a way to pass arguments to a macro started from command line ?
something like :
adrian@nthez145: ~ $root .x macro.C (arg1 , arg2)
Thank you !

see several examples at page 10 of the Users Guide

Rene

:blush: thanks :blush:
sorry :frowning:

ā€¦Iā€™ve search the userā€™s guide under parameter and argv.

Rene,
I came upon this old post while looking for a parameter passing method that would apply to the simplest macro style from with root:

[code]For example:
{
some code
}

results:

root [0] .x quickplot_4ch.C(3)
Error: can not open file ā€˜/ā€¦/rootfiles/./quickplot_4ch.C(3)ā€™

(aka synax error)
and then another try to see if argc was visible

root [1] .x quickplot_4ch.C
Error: Symbol argc is not defined in current scope quickplot_4ch.C:2:
*** Interpreter error recovered ***
[/code]

So does the macro require a ā€œmainā€ call to pass a parameter?

Thanks,
Dave

Hi,

The chapter you are looking for is ā€œCINT the C++ Interpreterā€ at ftp://root.cern.ch/root/doc/7CINT.pdf. In particular the discussion on Named Scripts.

In short do:

// File quickplot_4ch.C void quickplot_4ch.C(int val) { // some code }
and useroot 'quickplot_4ch.C(3)'

Philippe.

1 Like

In a bash shell Iā€™d like to do the following:

#ā€¦
BINW=$3
root ā€˜quickplot_4ch.C+(BINW)ā€™

but,
Error: Symbol BINW is not defined in current scope :0:

After reviewing other posts and ch2ā€¦
So it seems that if I know the value to pass, everything works fine (as in previous helps), but trying to pass it through an enclosing shell script wonā€™t get the values paste the single quotes?

Thanks,
Dave

Hi

cplager, thanks for the attemptā€¦butā€¦

[code]root [0]
Processing compRates.C+($BINW,$RATE1,$RATE2)ā€¦

RooFit v2.50 ā€“ Developed by Wouter Verkerke and David Kirkby
Copyright Ā© 2000-2008 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt

Error: Symbol BINW is not defined in current scope :0:
Error: Symbol RATE1 is not defined in current scope :0:
Error: Symbol RATE2 is not defined in current scope :0:[/code]

I suspectedā€¦when $3,$4,$5 didnā€™t work, but I gave it a try anyway.

Dave

Traffic sure was slow in the forum this week.

This isnā€™t really a Root question anymore, butā€¦

Use double quotes " " not single quotes ā€™ '.

Either will work within the script:

root -l ā€œcompRates.C+($BINW,$RATE1,$RATE2)ā€

root -l ā€˜compRates.C+(ā€™$BINW,$RATE1,$RATE2ā€™)ā€™

also, args on the scriptā€™s command line must be separated by blank spaces (not commas)

Sorry for digging this old thread, but it may be worth noting that ROOT options ā€œ-bā€ and ā€œ-qā€ may be in some cases preferable than ā€œ-lā€ and that in case BINW is a string, for instance, the following will work :

I do this frequently, and my macro takes string and non-string arguments. Here is an example with fixed arguments:

If I needed to pass shell variables as arguments, I have to carefully escape some quotes. Here is a complicated example where I use printf to format a string argument. Note the change of the outermost quotes to backticks and double-quotes to allow the shell variable expansion.

for run in {535,536,537}
do
  root -b -q -l `printf "standard_analysis.C+(\"../rootfiles/Outputs/Run%04d\",\"./out\",\"iif\",12000,125,-0.00015)" "${run}"`
done

Non-string arguments are easier:

for t in {120,125,130}
do
  root -b -q -l "standard_analysis.C+(\"../rootfiles/Outputs/Run0535\",\"./out\",\"iif\",12000,${myvar},-0.00015)"
done

Note: my way of doing it might not be the most straightforward, but seems to work.

1 Like

Hello Brun,
Please I need a help. I am trying to run root macros but I am getting this error TApplication::ExecuteFile: macro macros not found in path .:/Users/gideonbentum/root_src/obj/macros. Please how do I solve this problem?

ROOT didnā€™t find the file called ā€œmacrosā€. Check how you spelled it / from which directory you try to execute it.

Letā€™s, however, not warm up a thread thatā€™s more than 7 years old. If you need further help, you can create a new topic where we deal with your case in detail.

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