209 def process_valid_interfaces(input_file="HerwigConfigDecoder_InterfaceDump.txt", output_file="HerwigConfigDecoder_ConfigParameters.txt"):
210 """Process valid interfaces for each /Herwig/ path, execute 'get' commands, and save results.
213 input_file (str): Path to the input file containing Herwig paths and interfaces (default: 'HerwigConfigDecoder_InterfaceDump.txt').
214 output_file (str): Path to the output file for interface results (default: 'HerwigConfigDecoder_ConfigParameters.txt').
218 herwig_path_env = os.getenv(
'HERWIG7_PATH')
219 if not herwig_path_env:
220 athMsgLog.error(
"Error: Environment variable HERWIG7_PATH is not set")
224 with open(input_file,
'r')
as infile,
open(output_file,
'w')
as outfile:
225 content = infile.read()
226 blocks = content.split(
'\n\n')
233 lines = block.split(
'\n')
234 if not lines
or not lines[0].startswith(
'/Herwig/'):
237 herwig_path = lines[0].strip()
238 if herwig_path
in seen_paths:
239 athMsgLog.debug(f
"Skipped duplicate path in herwig_results.txt: {herwig_path}")
241 seen_paths.add(herwig_path)
242 block_paths.append(herwig_path)
245 line.strip()[2:]
for line
in lines[1:]
246 if line.strip().startswith(
'* ')
249 if not valid_interfaces:
250 errors.append((herwig_path, f
"No valid interfaces found for {herwig_path}"))
251 outfile.write(f
"{herwig_path}\nNo valid interfaces found\n\n")
254 all_tasks.extend([(herwig_path, interface)
for interface
in valid_interfaces])
257 athMsgLog.info(
"No interfaces to process")
259 for _, error_msg
in errors:
260 athMsgLog.debug(error_msg)
264 athMsgLog.info(f
"Processing {len(all_tasks)} interfaces")
268 for _, error_msg
in errors:
269 athMsgLog.debug(error_msg)
273 for herwig_path, get_command, filtered_output
in results:
274 if herwig_path
not in path_results:
275 path_results[herwig_path] = []
276 path_results[herwig_path].
append((get_command, filtered_output))
279 for herwig_path
in block_paths:
280 if herwig_path
not in path_results:
282 athMsgLog.debug(f
"Processing interfaces for {herwig_path}:")
283 outfile.write(f
"{herwig_path}\n")
284 for get_command, filtered_output
in path_results[herwig_path]:
285 athMsgLog.debug(f
"{get_command} ::: {filtered_output}")
286 outfile.write(f
"{get_command} ::: {filtered_output}\n")
289 athMsgLog.info(f
"Interface results saved to {output_file}")
291 except FileNotFoundError:
292 athMsgLog.info(f
"Error: Input file '{input_file}' not found")
293 except Exception
as e:
294 athMsgLog.info(f
"Error: An error occurred during interface processing: {str(e)}")