.include via command line

Dear ROOT experts,

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?

Thanks a lot.
Amin

Hey there,

An easy way to achieve this is to pass PATH to your macro as a “command line” argument.

Then you will be able to run your macro as:

root -l macro.C($PATH)

Cheers,
Adam

1 Like

It may be possible to just create a shell script like this:

#!/bin/bash

root -b -q -l <<-EOF
.include
.include
.x macro.C
EOF

Then you can access command line parameters with $@. If you give a concrete example I can show how to adjust the above to make it work.

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?

Thanks a lot.
Amin

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

Thanks @amadio
But where did you include the following in your modified version?

root -b -q -l <<-EOF
.include
.include
.x macro.C
EOF

Ah, ok, if you want that, then use the following:

#!/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

Well, “.include” does nothing except some terminal output.
You can try: std::cout << gInterpreter->GetIncludePath() << std::endl; std::cout << gSystem->GetIncludePath() << std::endl;

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