36 parser = argparse.ArgumentParser()
38 parser.add_argument(
"-i",
"--input", type=str,
39 help=
"directory holding all input ROOT files for skimming")
40 parser.add_argument(
"-o",
"--output", type=str,
41 help=
"directory holding all input ROOT files for skimming")
42 parser.add_argument(
"-r",
"--rootfile", type=str,
43 help=
"Name of the ROOT file in each subdirectory of the input directory")
44 parser.add_argument(
"-c",
"--cuts", type=str,
45 help=
"ROOT selection string-style cuts")
46 parser.add_argument(
"-f",
"--force", default=
False, action=
'store_true',
47 help=
"force-overwrite existing output")
49 args = parser.parse_args()
55 if not os.path.exists(args.output):
57 os.makedirs(args.output)
59 print(
"%s already exists... continuing..." % (args.output))
62 SLURM_ARRAY_TASK_ID=
"0"
65 SLURM_ARRAY_TASK_ID=os.environ[
"SLURM_ARRAY_TASK_ID"]
67 print(
"Please set the SLURM_ARRAY_TASK_ID environment variable to a number (e.g. 0) before running this script.")
71 print(
"Task ID requested: %d" % (int(SLURM_ARRAY_TASK_ID)))
75 value_index = int(SLURM_ARRAY_TASK_ID)
80 taskdir=
"%s/%d" % (args.output, value_index)
81 inputfile=
"%s/%d/%s" % (args.input, value_index, args.rootfile)
82 outputfile=
"%s/%d/%s" % (args.output, value_index, args.rootfile)
84 if os.path.exists(taskdir)
and not args.force:
85 print(
"Skipping this task directory --- it already exists. Cleanup before overwriting!")
88 if not os.path.exists(taskdir):
92 subprocess.call(
"root -q -l -b ./DelphesSkim.C'+(\"{0[input]}\",\"{0[output]}\",\"{0[cuts]}\")'".format({
'input': inputfile,
'output': outputfile,
'cuts': args.cuts}), shell=
True)