Belle II Software development
steering.py
1
8import basf2
9import hbasf2
10
11from zmq_daq.example_support import add_input_module, add_reco_modules, add_output_module
12
13from argparse import ArgumentParser
14import ROOT
15
16
17class RandomTestModule(basf2.Module):
18 """Print some random numbers to check reproducibility"""
19
20 def __init__(self):
21 """Make sure we can run in multiple processes"""
22 super().__init__()
23 self.set_property_flags(basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED)
24 self.evt = ROOT.Belle2.PyStoreObj("EventMetaData")
25
26 def event(self):
27 """Print the first 5 random numbers"""
28 numbers = [f"First 5 random values in event({self.evt.getExperiment()}, {self.evt.getRun()}, {self.evt.getEvent()}):"]
29 numbers += ["%08x" % ROOT.gRandom.Integer(0xffffffff) for i in range(5)]
30 basf2.B2INFO(" ".join(numbers))
31
32
33if __name__ == '__main__':
34 basf2.reset_database()
35 basf2.use_central_database("data_reprocessing_prompt")
36 basf2.set_nprocesses(2)
37
38 parser = ArgumentParser(description="Example steering file for the ZMQ tests")
39 parser.add_argument("--input", required=True, help="ZMQ Input Address")
40 parser.add_argument("--output", required=True, help="ZMQ Output Address")
41 parser.add_argument("--dqm", required=False, default="", help="ZMQ DQM Address (or empty for no DQM)")
42 parser.add_argument("--raw", action="store_true", help="Send out data in raw format")
43 parser.add_argument("--expressreco", action="store_true", help="Also initialize express reco objects")
44 parser.add_argument("--mimik-startup", action="store_true", help="Mimik the geometry loading with a sleep")
45
46 args = parser.parse_args()
47
48 path = basf2.Path()
49 reco_path = basf2.Path()
50
51 input_module = add_input_module(path, input_address=args.input, add_expressreco_objects=args.expressreco)
52
53 reco_path.add_module(RandomTestModule())
54 add_reco_modules(reco_path, dqm_address=args.dqm, mimik_startup=args.mimik_startup)
55
56 input_module.if_value("==0", reco_path, basf2.AfterConditionPath.CONTINUE)
57
58 add_output_module(path, output_address=args.output, raw=args.raw)
59
60 if args.dqm:
61 hbasf2.process(path, [args.output, args.dqm], False)
62 else:
63 hbasf2.process(path, [args.output], False)