-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.py
108 lines (100 loc) · 2.76 KB
/
generate.py
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from os import path, makedirs
import importlib
import logging
import logging.handlers
from code_generation.code_generation import CodeGenerator
def run(args):
analysis_name = "whtautau"
available_samples = [
"ggh_htautau",
"ggh_hbb",
"ggh_hww",
"vbf_htautau",
"vbf_hbb",
"vbf_hww",
"rem_htautau",
"rem_hbb",
"embedding",
"embedding_mc",
"singletop",
"ttbar",
"diboson",
"dyjets",
"wjets",
"data",
"electroweak_boson",
"wminush_htautau",
"triboson",
"rem_ttbar",
"ggZZ",
"rem_VH",
]
available_eras = ["2016preVFP", "2016postVFP", "2017", "2018"]
available_scopes = [
"mt",
"et",
"tt",
"em",
"mm",
"ee",
"emt",
"met",
"mmt",
"ett",
"mtt",
"mme",
"eem",
]
## setup variables
shifts = set([shift.lower() for shift in args.shifts])
sample_group = args.sample
era = args.era
scopes = list(set([scope.lower() for scope in args.scopes]))
## load config
configname = args.config
config = importlib.import_module(
f"analysis_configurations.{analysis_name}.{configname}"
)
## Setting up executable
executable = f"{configname}_{sample_group}_{era}.cxx"
args.logger.info(f"Generating code for {sample_group}...")
args.logger.info(f"Configuration used: {config}")
args.logger.info(f"Era: {era}")
args.logger.info(f"Shifts: {shifts}")
config = config.build_config(
era,
sample_group,
scopes,
shifts,
available_samples,
available_eras,
available_scopes,
)
# create a CodeGenerator object
generator = CodeGenerator(
main_template_path=args.template,
sub_template_path=args.subset_template,
configuration=config,
executable_name=f"{configname}_{sample_group}_{era}",
analysis_name=analysis_name,
config_name=configname,
output_folder=args.output,
threads=args.threads,
)
if args.debug == "true":
generator.debug = True
# generate the code
generator.generate_code()
executable = generator.get_cmake_path()
# append the executable name to the files.txt file
# if the file does not exist, create it
if not path.exists(path.join(args.output, "files.txt")):
with open(path.join(args.output, "files.txt"), "w") as f:
f.write(f"{executable}\n")
else:
with open(path.join(args.output, "files.txt"), "r+") as f:
for line in f:
if executable in line:
break
else:
f.write(f"{executable}\n")