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
thanks
sorry
ā¦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.
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.
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.