9 from AthenaCommon
import Logging
10 athMsgLog = Logging.logging.getLogger(
'Herwig7JOChecker')
14 herwig7_bin_path = os.path.join(os.environ[
'HERWIG7_PATH'],
'bin')
15 herwig7_binary = os.path.join(herwig7_bin_path,
'Herwig')
16 versions = subprocess.check_output([herwig7_binary,
'--version']).splitlines()
17 return(
' '.
join([x.decode(
'UTF8')
for x
in versions[0].
split()[1:]]))
21 for command
in range(len(list)):
22 list[command] = list[command].
replace(string,replace)
24 list[command] = list[command].strip()
31 athMsgLog.debug(command)
35 for command
in range(len(list)):
38 whitespace_idx = list[command].
index(
" ")
40 list[command] = [list[command][0:whitespace_idx],list[command][whitespace_idx+1:]]
46 found_duplicate =
False
47 existing_commands = {}
52 if temp_com
in existing_commands
and existing_commands[temp_com] != temp_val:
53 found_duplicate =
True
54 str1 =
"\nFound option that is used twice"
55 str2 =
"The option %s is first set to %s" % (temp_com,existing_commands[temp_com])
56 str3 =
"And then the option %s ist set to %s" % (command[0],command[1])
57 athMsgLog.info(str1+
"\n"+str2+
"\n"+str3)
58 file.write(str1+
"\n"+str2+
"\n"+str3)
60 existing_commands[temp_com] = temp_val
62 return found_duplicate
67 file.write(command[0]+
" "+command[1]+
"\n")
70 def sort_commands(line,cd_in_line,cd_command,set_commands,read_commands,create_commands,insert_commands):
74 cd_command = line.replace(
"cd ",
"")
75 cd_command = cd_command.strip()
79 if cd_in_line
and not line.startswith(
"/Herwig/"):
80 set_commands.append(cd_command+
"/"+line)
82 set_commands.append(line)
84 elif "create" in line:
85 if cd_in_line
and not line.startswith(
"/Herwig/"):
86 create_commands.append(cd_command+
"/"+line)
88 create_commands.append(line)
90 elif "insert" in line:
91 if cd_in_line
and not line.startswith(
"/Herwig/"):
92 insert_commands.append(cd_command+
"/"+line)
94 insert_commands.append(line)
97 read_commands.append(line)
100 return cd_in_line,cd_command,set_commands,read_commands,create_commands,insert_commands
105 athMsgLog.info(
"Hello from the config-checker!")
108 version = h_version[0]
109 subversion = h_version[2]
110 subsubversion = h_version[4]
111 athMsgLog.info(
"The current Herwig version is "+version+
"."+subversion+
"."+subsubversion)
114 files = [f
for f
in os.listdir(
'.')
if os.path.isfile(f)]
118 HerwigINFile.append(file)
121 run_name = HerwigINFile[0]
122 athMsgLog.info(
"The Herwig7 *.in file is "+run_name)
130 f =
open(run_name,
"r")
134 if not line.startswith(
"#"):
135 cd,cd_cmd,set_commands,read_commands,create_commands,insert_commands =
sort_commands(line,
136 cd_in_line,cd_command,set_commands,
137 read_commands,create_commands,insert_commands)
138 cd_in_line,cd_command = cd,cd_cmd
144 create_commands =
clean_string(create_commands,
"create ",
"")
146 read_commands =
clean_string(read_commands,
"snippets/",
"")
149 include_path = os.environ[
'HERWIG7_PATH']+
"/share/Herwig/"
150 snippet_path = os.environ[
'HERWIG7_PATH']+
"/share/Herwig/snippets/"
152 include_files = [f
for f
in os.listdir(include_path)]
153 snippet_files = [f
for f
in os.listdir(snippet_path)]
157 for file
in include_files:
158 for command
in read_commands:
160 read_files.append(include_path+file)
161 for file
in snippet_files:
162 for command
in read_commands:
164 read_files.append(snippet_path+file)
167 for file
in read_files:
168 if ".in" not in file:
169 athMsgLog.info(
"Skipping file " + file +
" since it does not contain any in-file")
170 athMsgLog.info(
"It is just a directory, can be ignored.")
177 if not line.startswith(
"#"):
178 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)
179 cd_in_line,cd_command = cd,cd_cmd
186 create_commands =
clean_string(create_commands,
"create ",
"")
188 read_commands =
clean_string(read_commands,
"snippets/",
"")
196 athMsgLog.debug(
"\n These are the commands found by the Herwig7JOChecker:\n")
200 athMsgLog.debug(
"\n")
210 with open(
"HerwigCommandDuplicates.txt",
"w")
as file:
218 with open(
"HerwigCommands.txt",
"w")
as file:
224 if found_duplicate1
or found_duplicate2
or found_duplicate3:
225 athMsgLog.warn(
"There were some settings which are overwritten, please check the log-file HerwigCommandDuplicates.txt")
228 athMsgLog.info(
"Commands have been written to HerwigCommands.txt")
229 athMsgLog.info(
"Duplicates have been written to HerwigCommandsDuplicates.txt")
230 athMsgLog.info(
"Godybe from the config-checker!")