3 from __future__
import print_function
12 if output_file
is None:
13 output_file = input_file
14 if not os.path.exists(os.path.dirname(os.path.realpath(output_file))):
15 os.makedirs(os.path.dirname(os.path.realpath(output_file)))
18 with open(
'tmp.txt',
'w')
as fw:
19 with open(input_file,
'r') as ftmp: 21 if re.search(
'\s*</event>', line):
23 fw.write(
'<event_num num="' +
str(nevent) +
'"> ' +
str(nevent) +
'</event_num>\n')
25 if output_file
is not None:
26 os.rename(
"tmp.txt", output_file)
28 os.rename(
"tmp.txt", input_file)
32 if __name__==
"__main__":
34 parser = argparse.ArgumentParser(
35 description=
"Add numbers to lhe")
36 parser.add_argument(
"input_file", type=str,
37 help=
"Input LHE file path.")
38 parser.add_argument(
"-o",
"--output-file", default=
None, type=str,
39 help=
"Output LHE file path. If not specified, output to input file")
40 args = parser.parse_args()
42 logging.info(
'>>> launch addLHEnumbers.py in %s' % os.path.abspath(os.getcwd()))
44 logging.info(
'>>> Input file: [%s]' % args.input_file)
45 logging.info(
'>>> Write to output: %s ' % args.output_file)
def number_events(input_file, output_file=None, offset=0)