220 def FindDuplicates(inFileName=None, crashMode=False, printDuplicated=False):
221 if inFileName ==
None:
222 LHEToolsLog.error(
"No input file for Duplicate finder")
226 LHEToolsLog.info(
"Possible duplicated events in lhe file will be printed out if any")
229 LHEToolsLog.info(
"Possible duplicated events in lhe file will be printed out if any")
232 fScript =
open(
"finder.awk",
'w')
234 """BEGIN{RS="<event>"; ORS=""; FS="</event>"; OFS=""; nDuplicates=0}
237 print $1 > \""""+inFileName+
"-new"+
"""\"
242 if (c[$1]==1) {print \"<event>\"$1\"</event>\" > \""""+inFileName+
"-new"+
"""\" }
243 else {print \"<event>\"$1\"</event>\" > \""""+inFileName+
"-duplicates"+
"""\"; nDuplicates++}
246 END{print \"</LesHouchesEvents>\\n\" > \""""+inFileName+
"-new"+
"""\"; print nDuplicates}""")
249 command =
'awk -f finder.awk '+inFileName+
" > nDuplicates.txt"
253 LHEToolsLog.error(
"Impossible to execute awk script")
257 fnDuplicates =
open(
"nDuplicates.txt",
'r')
258 s = fnDuplicates.read().rstrip()
262 fDuplicates =
open(inFileName+
"-duplicates",
'r')
264 LHEToolsLog.info(s+
" duplicate events were found in "+inFileName)
266 LHEToolsLog.info(
"Possible duplicated events in lhe file will be printed out if any")
267 for line
in fDuplicates:
268 LHEToolsLog.info(line)
272 LHEToolsLog.error(
"Duplicate events found. To avoid this crash, use crashmode=False. Exiting...")
275 LHEToolsLog.info(
"Duplicate events found. Replacing input file "+inFileName+
" by fixed file "+inFileName+
"-new")
276 LHEToolsLog.info(
"Old file saved in "+inFileName+
"-old")
277 os.rename(inFileName,inFileName+
"-old")
278 os.rename(inFileName+
"-new",inFileName)
280 LHEToolsLog.info(
"No duplicate events was found in "+inFileName)
281 os.remove(inFileName+
"-new")