-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvaStage4.py
More file actions
80 lines (61 loc) · 2.42 KB
/
vaStage4.py
File metadata and controls
80 lines (61 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
import warnings
import textwrap
import errno
def create_vaStage4_condor_script(
vaStage2Output,
config,
cuts,
output_dir=".",
):
"""
Generates a condor script to run VEGAS stage 2.
Parameters
----------
vaStage2Output : string
vaStage2 file to be copied
and renamed to stg4.root
vaStage1Output : string
VEGAS Stage1 output file
Will take care to rename file with .stage2.root extension
output_dir : str, optional
where SLURM will send command-line output/error, by default "."
"""
VEGAS = os.environ.get('VEGAS')
if not VEGAS:
raise EnvironmentError("SIMTELDIR environment variable is not set.")
exe = os.path.join(VEGAS, "bin", "vaStage4")
if not os.path.exists(exe):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), f"{exe}")
if not os.path.exists(config):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), f"{config}")
if not os.path.exists(cuts):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), f"{cuts}")
if not os.path.exists(output_dir):
warnings.warn(f"Directory '{output_dir}' does not exist. It will be created.", UserWarning)
os.makedirs(output_dir, exist_ok=True)
file_basename = os.path.splitext(str(os.path.splitext(os.path.basename(vaStage2Output))[0]))[0]
out = os.path.join(output_dir, f"{file_basename}.stg4.condor.out")
error = os.path.join(output_dir, f"{file_basename}.stg4.condor.error")
log = os.path.join(output_dir, f"{file_basename}.stg4.condor.log")
vaStage4Output = os.path.join(output_dir, f"{file_basename}.stg4.root")
if not os.path.exists(vaStage4Output):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), f"{vaStage4Output}")
script_content = textwrap.dedent(f"""\
Universe = vanilla
Executable = {exe}
Arguments = -config={config} -cuts={cuts} {vaStage4Output}
Requirements =
Environment = "VEGAS={VEGAS}"
GetEnv = True
image_size = 1638400
want_graceful_removal = True
Output = {out}
Error = {error}
Log = {log}
Queue
""")
script_path = os.path.join(output_dir, f"{file_basename}.stg4.condor.sub")
with open(script_path, "w") as script_file:
script_file.write(script_content)
return script_path