ATLAS Offline Software
Classes | Functions | Variables
LHETools Namespace Reference

Classes

class  Event
 
class  EventInfo
 
class  Particle
 
class  Record
 

Functions

def FindDuplicates (inFileName=None, crashMode=False, printDuplicated=False)
 

Variables

 LHEToolsLog = Logging.logging.getLogger('MCJobOptionUtils/LHETools.py')
 

Function Documentation

◆ FindDuplicates()

def LHETools.FindDuplicates (   inFileName = None,
  crashMode = False,
  printDuplicated = False 
)

Definition at line 220 of file LHETools.py.

220 def FindDuplicates(inFileName=None, crashMode=False, printDuplicated=False):
221  if inFileName == None:
222  LHEToolsLog.error("No input file for Duplicate finder")
223  raise RuntimeError
224 
225  if printDuplicated:
226  LHEToolsLog.info("Possible duplicated events in lhe file will be printed out if any")
227 
228  if printDuplicated:
229  LHEToolsLog.info("Possible duplicated events in lhe file will be printed out if any")
230 
231  # writing awk script to be executed on the input lhe file
232  fScript = open("finder.awk", 'w')
233  fScript.write(
234 """BEGIN{RS="<event>"; ORS=""; FS="</event>"; OFS=""; nDuplicates=0}
235 {
236 if (NR==1) {
237  print $1 > \""""+inFileName+"-new"+"""\"
238  ORS=\"\\n\"
239 }
240 else {
241  c[$1]++;
242  if (c[$1]==1) {print \"<event>\"$1\"</event>\" > \""""+inFileName+"-new"+"""\" }
243  else {print \"<event>\"$1\"</event>\" > \""""+inFileName+"-duplicates"+"""\"; nDuplicates++}
244 }
245 }
246 END{print \"</LesHouchesEvents>\\n\" > \""""+inFileName+"-new"+"""\"; print nDuplicates}""")
247  fScript.close()
248 
249  command = 'awk -f finder.awk '+inFileName+" > nDuplicates.txt"
250  try:
251  os.system(command)
252  except:
253  LHEToolsLog.error("Impossible to execute awk script")
254  raise RuntimeError
255 
256  # read the number of duplicate events from temp file
257  fnDuplicates = open("nDuplicates.txt", 'r')
258  s = fnDuplicates.read().rstrip()
259  fnDuplicates.close()
260 
261  if int(s) >0:
262  fDuplicates = open(inFileName+"-duplicates", 'r')
263  # some usefull prints
264  LHEToolsLog.info(s+" duplicate events were found in "+inFileName)
265  if printDuplicated:
266  LHEToolsLog.info("Possible duplicated events in lhe file will be printed out if any")
267  for line in fDuplicates:
268  LHEToolsLog.info(line)
269  fDuplicates.close() # don't need it anymore
270  # either crash of replace file
271  if(crashMode):
272  LHEToolsLog.error("Duplicate events found. To avoid this crash, use crashmode=False. Exiting...")
273  raise RuntimeError
274  else:
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)
279  else:
280  LHEToolsLog.info("No duplicate events was found in "+inFileName)
281  os.remove(inFileName+"-new") # removing the useless "-new" file

Variable Documentation

◆ LHEToolsLog

LHETools.LHEToolsLog = Logging.logging.getLogger('MCJobOptionUtils/LHETools.py')

Definition at line 7 of file LHETools.py.

CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Trk::open
@ open
Definition: BinningType.h:40
LHETools.FindDuplicates
def FindDuplicates(inFileName=None, crashMode=False, printDuplicated=False)
Definition: LHETools.py:220
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567