Belle II Software  release-08-01-10
example_support.py
1 
8 
9 # This file includes helpers used in the local example script and are not needed for the production environment
10 import basf2
11 from time import sleep
12 import zmq
13 
14 
15 class SleepOnInitModule(basf2.Module):
16  """Helper module to sleep 20 seconds on init (to mimik geometry loading)"""
17 
18  def __init__(self):
19  """Make the module parallel processing certified"""
20  super().__init__()
21  self.set_property_flags(basf2.ModulePropFlags.PARALLELPROCESSINGCERTIFIED)
22 
23  def initialize(self):
24  """Sleep 20 seconds"""
25  sleep(20)
26 
27 
28 def add_input_module(path, input_address, add_expressreco_objects):
29  """Add the ZMQ input module in the settings used for the examples"""
30  input_module = path.add_module("HLTZMQ2Ds", input=input_address, addExpressRecoObjects=add_expressreco_objects)
31 
32  return input_module
33 
34 
35 def add_reco_modules(path, dqm_address, mimik_startup):
36  """Add the reconstruction modules in the settings used for the examples"""
37  if mimik_startup:
38  path.add_module(SleepOnInitModule())
39 
40  if dqm_address:
41  path.add_module("HLTDQM2ZMQ", output=dqm_address, sendOutInterval=5)
42  path.add_module("DAQMonitor")
43 
44 
45 def add_output_module(path, output_address, raw):
46  """Add the ZMQ output module in the settings used for the examples"""
47  path.add_module("HLTDs2ZMQ", output=output_address, raw=raw)
48 
49 
50 def create_socket(context, address):
51  """Create a socket out of the given address"""
52  socket = context.socket(zmq.DEALER)
53  socket.connect(address)
54 
55  return socket
56 
57 
58 def get_sockets(settings):
59  """Create all monitoring sockets for the given settings dictionary"""
60  ctx = zmq.Context()
61  sockets = {name: create_socket(ctx, address) for name, address in settings["monitor"].items()}
62  return sockets