-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.py
101 lines (92 loc) · 2.93 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
from os import path, makedirs
import importlib
import logging
import logging.handlers
from code_generation.code_generation import CodeGenerator
def run(args):
analysis_name = "s"
available_samples = [
"singletop",
# "single_s",
# "single_t",
# "single_tw",
"ttbar",
"diboson",
"dyjets",
"wjets",
"qcd",
"data",
]
available_eras = ["2016preVFP", "2016postVFP", "2017", "2018"]
available_scopes = ["lep"]
#print(available_scopes)
## 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]))
## Setup Logging
root = logging.getLogger()
root.setLevel("INFO")
if args.debug == "true":
root.setLevel("DEBUG")
## setup logging
if not path.exists("generation_logs"):
makedirs("generation_logs")
terminal_handler = logging.StreamHandler()
terminal_handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
root.addHandler(terminal_handler)
handler = logging.handlers.WatchedFileHandler(
f"generation_logs/generation_{era}_{sample_group}.log",
"w",
)
handler.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
root.addHandler(handler)
## 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"
root.info(f"Generating code for {sample_group}...")
root.info(f"Configuration used: {config}")
root.info(f"Era: {era}")
root.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")