Belle II Software development
b2hlt_convert2raw.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from softwaretrigger.constants import HLT_INPUT_OBJECTS
13
14import os
15from argparse import ArgumentParser
16
17
18if __name__ == '__main__':
19 parser = ArgumentParser()
20 parser.add_argument("input_file", help="Input file name")
21 parser.add_argument("output_file", help="Output file name")
22 parser.add_argument("--number", help="How many events should be converted", default=0, type=int)
23
24 args = parser.parse_args()
25 input_file = args.input_file
26 output_file = args.output_file
27
28 path = basf2.Path()
29 extension = os.path.splitext(input_file)[-1]
30 if extension == ".root":
31 path.add_module("RootInput", inputFileName=input_file, branchNames=HLT_INPUT_OBJECTS)
32 elif extension == ".sroot":
33 path.add_module("SeqRootInput", inputFileName=input_file)
34 else:
35 raise AttributeError(f"Do not understand file format of {input_file}")
36
37 path.add_module("Root2Raw", outputFileName=output_file)
38 basf2.process(path, args.number)