Belle II Software  release-05-01-25
b2hlt_prepareRawInputFile.py
1 #!/usr/bin/env python3
2 
3 # ************************************************************************#
4 # BASF2 (Belle Analysis Framework 2) #
5 # Copyright(C) 2019 - Belle II Collaboration #
6 # #
7 # Author: The Belle II Collaboration #
8 # Contributors: Nils Braun #
9 # #
10 # This software is provided "as is" without any warranty. #
11 # ************************************************************************#
12 
13 import basf2
14 from softwaretrigger.constants import HLT_INPUT_OBJECTS, EXPRESSRECO_INPUT_OBJECTS
15 
16 import os
17 from argparse import ArgumentParser
18 
19 
20 if __name__ == '__main__':
21  parser = ArgumentParser(description="Helper script to convert a root file into an input file needed for HLT ZMQ tests.")
22  parser.add_argument("input_file", help="Input file name")
23  parser.add_argument("output_file", help="Output file name")
24  parser.add_argument("--number", help="How many events should be converted (default 10)", default=10, type=int)
25  parser.add_argument("--expressreco", help="Convert to express reco format, instead of HLT", action="store_true")
26 
27  args = parser.parse_args()
28  input_file = args.input_file
29  output_file = args.output_file
30 
31  basf2.conditions.override_globaltags([])
32  path = basf2.Path()
33 
34  branchNames = HLT_INPUT_OBJECTS
35  if args.expressreco:
36  branchNames = EXPRESSRECO_INPUT_OBJECTS
37 
38  extension = os.path.splitext(input_file)[-1]
39  if extension == ".root":
40  path.add_module("RootInput", inputFileName=input_file, branchNames=branchNames)
41  else:
42  raise AttributeError(f"Do not understand file format of {input_file}")
43 
44  if not args.expressreco:
45  path.add_module("Root2Raw", outputFileName=output_file + ".raw")
46  path.add_module("SeqRootOutput", outputFileName=output_file + ".sroot")
47  path.add_module("RootOutput", outputFileName=output_file + ".root")
48  basf2.process(path, args.number)
softwaretrigger.constants
Definition: constants.py:1
basf2.process
def process(path, max_event=0)
Definition: __init__.py:25