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