Belle II Software development
b2hlt_prepareRawInputFile.py
1#!/usr/bin/env python3
2
3
10
11import basf2
12from softwaretrigger.constants import HLT_INPUT_OBJECTS, EXPRESSRECO_INPUT_OBJECTS
13
14import os
15from argparse import ArgumentParser
16
17
18if __name__ == '__main__':
19 parser = ArgumentParser(description="Helper script to convert a root file into an input file needed for HLT ZMQ tests.")
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 10)", default=10, type=int)
23 parser.add_argument("--expressreco", help="Convert to express reco format, instead of HLT", action="store_true")
24
25 args = parser.parse_args()
26 input_file = args.input_file
27 output_file = args.output_file
28
29 basf2.conditions.override_globaltags([])
30 path = basf2.Path()
31
32 branchNames = HLT_INPUT_OBJECTS
33 if args.expressreco:
34 branchNames = EXPRESSRECO_INPUT_OBJECTS
35
36 extension = os.path.splitext(input_file)[-1]
37 if extension == ".root":
38 path.add_module("RootInput", inputFileName=input_file, branchNames=branchNames)
39 else:
40 raise AttributeError(f"Do not understand file format of {input_file}")
41
42 if not args.expressreco:
43 path.add_module("Root2Raw", outputFileName=output_file + ".raw")
44 path.add_module("SeqRootOutput", outputFileName=output_file + ".sroot")
45 path.add_module("RootOutput", outputFileName=output_file + ".root")
46 basf2.process(path, args.number)