Skip to content

Commit 8a6dc4e

Browse files
Benedikt Volkelchiarazampolli
authored andcommitted
Specify output path from python
Avoid writing all files to current directory, so the Python wrapper can be started from anywhere writing to a different place
1 parent 76bf6aa commit 8a6dc4e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

RelVal/o2dpg_release_validation.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323

2424
import sys
2525
import argparse
26-
from os import environ, system
27-
from os.path import join
26+
from os import environ, makedirs
27+
from os.path import join, abspath, exists
28+
from subprocess import Popen
29+
from shlex import split
2830

2931
# make sure O2DPG + O2 is loaded
3032
O2DPG_ROOT=environ.get('O2DPG_ROOT')
@@ -36,11 +38,14 @@
3638
ROOT_MACRO=join(O2DPG_ROOT, "RelVal", "ReleaseValidation.C")
3739

3840
def run(args):
41+
if not exists(args.output):
42+
makedirs(args.output)
3943
select_critical = "kTRUE" if args.select_critical else "kFALSE"
40-
cmd = f"\\(\\\"{args.input_files[0]}\\\",\\\"{args.input_files[1]}\\\",{args.test},{args.chi2_value},{args.rel_bc_diff},{args.rel_entries_diff},{select_critical}\\)"
44+
cmd = f"\\(\\\"{abspath(args.input_files[0])}\\\",\\\"{abspath(args.input_files[1])}\\\",{args.test},{args.chi2_value},{args.rel_bc_diff},{args.rel_entries_diff},{select_critical}\\)"
4145
cmd = f"root -l -b -q {ROOT_MACRO}{cmd}"
4246
print(f"Running {cmd}")
43-
system(cmd)
47+
p = Popen(split(cmd), cwd=args.output)
48+
p.wait()
4449
return 0
4550

4651
def main():
@@ -52,6 +57,7 @@ def main():
5257
parser.add_argument("--rel-bc-diff", dest="rel_bc_diff", type=float, help="Threshold of relative difference in normalised bin content", default=0.01)
5358
parser.add_argument("--rel-entries-diff", dest="rel_entries_diff", type=float, help="Threshold of relative difference in number of entries", default=0.01)
5459
parser.add_argument("--select-critical", dest="select_critical", action="store_true", help="Select the critical histograms and dump to file")
60+
parser.add_argument("--output", "-o", help="output directory", default="./")
5561
parser.set_defaults(func=run)
5662

5763
args = parser.parse_args()

0 commit comments

Comments
 (0)