Skip to content

Commit

Permalink
Fix the regex to match the LHE tags in mergeLHE.py
Browse files Browse the repository at this point in the history
Backport of cms-sw#34804
  • Loading branch information
colizz committed Aug 13, 2021
1 parent 11f2a69 commit fb3c78c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions GeneratorInterface/LHEInterface/scripts/mergeLHE.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def merge(self):
for i in range(len(self._f)):
header = []
line = next(self._f[i])
while not line.startswith('<init>') and not line.startswith('<init '):
while not re.search('\s*<init(>|\s)', line):
header.append(line)
line = next(self._f[i])
# 'header' includes all contents before reaches <init>
Expand All @@ -207,7 +207,7 @@ def merge(self):
for i in range(len(self._f)):
init = []
line = next(self._f[i])
while not line.startswith('</init>'):
while not re.search('\s*</init>', line):
init.append(line)
line = next(self._f[i])
# 'init_str' includes all contents inside <init>...</init>
Expand All @@ -220,9 +220,9 @@ def merge(self):
nevent = 0
while True:
line = next(self._f[i])
if line.startswith('</event>'):
if re.search('\s*</event>', line):
nevent += 1
if line.startswith('</LesHouchesEvents>'):
if re.search('\s*</LesHouchesEvents>', line):
break
_fwtmp.write(line)
self._nevent.append(nevent)
Expand Down Expand Up @@ -253,16 +253,16 @@ def merge(self):
sign = lambda x: -1 if x < 0 else 1
for line in ftmp:
event_line += 1
if line.startswith('<event'):
if re.search('\s*<event.*>', line):
event_line = 0
if event_line == 1:
# modify the XWGTUP appeared in the first line of the
# <event> block
orig_wgt = float(line.split()[2])
fw.write(re.sub(r'(^\s*\S+\s+\S+\s+)\S+(.+)', r'\g<1>%+.7E\g<2>' \
% (sign(orig_wgt) * self._uwgt), line))
elif line.startswith('<wgt '):
addi_wgt_str = re.search(r'^\<wgt.*\>\s*(\S+)\s*\<\/wgt\>', line).group(1)
elif re.search('\s*<wgt.*>.*</wgt>', line):
addi_wgt_str = re.search(r'\<wgt.*\>\s*(\S+)\s*\<\/wgt\>', line).group(1)
fw.write(line.replace(
addi_wgt_str, '%+.7E' % (float(addi_wgt_str) / orig_wgt * self._uwgt)))
else:
Expand Down

0 comments on commit fb3c78c

Please sign in to comment.