12 from AthenaCommon
import Logging
13 athMsgLog = Logging.logging.getLogger(
'Herwig7JOChecker')
17 herwig7_bin_path = os.path.join(os.environ[
'HERWIG7_PATH'],
'bin')
18 herwig7_binary = os.path.join(herwig7_bin_path,
'Herwig')
19 versions = subprocess.check_output([herwig7_binary,
'--version']).splitlines()
20 return(
' '.
join([x.decode(
'UTF8')
for x
in versions[0].
split()[1:]]))
24 for command
in range(len(list)):
25 list[command] = list[command].
replace(string,replace)
27 list[command] = list[command].strip()
34 athMsgLog.info(command)
38 for command
in range(len(list)):
41 whitespace_idx = list[command].
index(
" ")
43 list[command] = [list[command][0:whitespace_idx],list[command][whitespace_idx+1:]]
49 found_duplicate =
False
50 existing_commands = {}
55 if temp_com
in existing_commands
and existing_commands[temp_com] != temp_val:
56 found_duplicate =
True
57 str1 =
"\nFound option that is used twice"
58 str2 =
"The option %s is first set to %s" % (temp_com,existing_commands[temp_com])
59 str3 =
"And then the option %s ist set to %s" % (command[0],command[1])
60 athMsgLog.info(str1+
"\n"+str2+
"\n"+str3)
61 file.write(str1+
"\n"+str2+
"\n"+str3)
63 existing_commands[temp_com] = temp_val
65 return found_duplicate
70 file.write(command[0]+
" "+command[1]+
"\n")
73 def sort_commands(line,cd_in_line,cd_command,set_commands,read_commands,create_commands,insert_commands):
77 cd_command = line.replace(
"cd ",
"")
78 cd_command = cd_command.strip()
82 if cd_in_line
and not line.startswith(
"/Herwig/"):
83 set_commands.append(cd_command+
"/"+line)
85 set_commands.append(line)
87 elif "create" in line:
88 if cd_in_line
and not line.startswith(
"/Herwig/"):
89 create_commands.append(cd_command+
"/"+line)
91 create_commands.append(line)
93 elif "insert" in line:
94 if cd_in_line
and not line.startswith(
"/Herwig/"):
95 insert_commands.append(cd_command+
"/"+line)
97 insert_commands.append(line)
100 read_commands.append(line)
103 return cd_in_line,cd_command,set_commands,read_commands,create_commands,insert_commands
108 athMsgLog.info(
"Hello from the config-checker!")
111 version = h_version[0]
112 subversion = h_version[2]
113 subsubversion = h_version[4]
114 athMsgLog.info(
"The current Herwig version is "+version+
"."+subversion+
"."+subsubversion)
117 files = [f
for f
in os.listdir(
'.')
if os.path.isfile(f)]
121 HerwigINFile.append(file)
124 run_name = HerwigINFile[0]
125 athMsgLog.info(
"The Herwig7 *.in file is "+run_name)
133 f =
open(run_name,
"r")
137 if not line.startswith(
"#"):
138 cd,cd_cmd,set_commands,read_commands,create_commands,insert_commands =
sort_commands(line,
139 cd_in_line,cd_command,set_commands,
140 read_commands,create_commands,insert_commands)
141 cd_in_line,cd_command = cd,cd_cmd
147 create_commands =
clean_string(create_commands,
"create ",
"")
149 read_commands =
clean_string(read_commands,
"snippets/",
"")
152 include_path = os.environ[
'HERWIG7_PATH']+
"/share/Herwig/"
153 snippet_path = os.environ[
'HERWIG7_PATH']+
"/share/Herwig/snippets/"
155 include_files = [f
for f
in os.listdir(include_path)]
156 snippet_files = [f
for f
in os.listdir(snippet_path)]
160 for file
in include_files:
161 for command
in read_commands:
163 read_files.append(include_path+file)
164 for file
in snippet_files:
165 for command
in read_commands:
167 read_files.append(snippet_path+file)
170 for file
in read_files:
171 if ".in" not in file:
172 athMsgLog.info(
"Skipping file " + file +
" since it does not contain any in-file")
173 athMsgLog.info(
"It is just a directory, can be ignored.")
180 if not line.startswith(
"#"):
181 cd,cd_cmd,set_commands,read_commands,create_commands,insert_commands =
sort_commands(line,cd_in_line,cd_command,set_commands,read_commands,create_commands,insert_commands)
182 cd_in_line,cd_command = cd,cd_cmd
189 create_commands =
clean_string(create_commands,
"create ",
"")
191 read_commands =
clean_string(read_commands,
"snippets/",
"")
199 athMsgLog.info(
"\n These are the commands found by the Herwig7JOChecker:\n")
213 with open(
"HerwigCommandDuplicates.txt",
"w")
as file:
221 with open(
"HerwigCommands.txt",
"w")
as file:
227 if found_duplicate1
or found_duplicate2
or found_duplicate3:
228 athMsgLog.warn(
"There were some settings which are overwritten, please check the log-file HerwigCommandDuplicates.txt")
231 athMsgLog.info(
"Godybe from the config-checker!")