I am running a macro (macro.C) on some ROOT files. I launch ROOT (root -l) and type:
root [0] .include <PATH_TO_DELPHES>
root [1] .include <PATH_TO_DELPHES_EXTERNAL>
root [2] .x macro.C
Now I want to use a bash script to run my macro on several ROOT files. I am familiar with running root -b -l -q macro.C directly on command line. But how do I include the PATH also via the command line?
This is a good solution. Alternatively, you can redefine your code in order to run the present macro on a list/vector/array of file names programmatically…
Thank you all for your input. Very helpful. @amadio My macros are named as such: SR_xxx , SR_yyy , etc … so my bash script look like this:
#!/bin/bash for SR2 in xxx yyy do SR=SR_$SR2 for point in *.root do root -b -l -q $SR.C\(\"$point\"\) mv *.$SR2*.root Done/ #move to some directory done done mv *.txt Done/ #move to some directory
If I include your code in the do loop inside it throws an error. Should EOF wrap the entire for loop?
Here is a slightly modified version that should work. Please try out and let us know.
#!/bin/bash
for i in xxx yyy; do
for file in *.root; do
macro=SR_${i}.C
root -b -l -q ${macro}\("${file}"\)
mv *${i}*.root Done/ #move to some directory
done
done
mv *.txt Done/ #move to some directory
#!/bin/bash
for i in xxx yyy; do
for file in *.root; do
macro=SR_${i}.C
root -b -l -q <<-EOF
.include
.include
.x ${macro}\("${file}"\)
EOF
mv *${i}*.root Done/ #move to some directory
done
done
mv *.txt Done/ #move to some directory