Belle II Software  release-05-01-25
ZMQClasses.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Nils Braun *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <daq/hbasf2/apps/ZMQClasses.h>
11 #include <framework/logging/Logger.h>
12 
13 using namespace Belle2;
14 
16 {
19  m_output.reset(new ZMQNullConnection);
20 }
21 
22 void ZMQReadySender::addOptions(po::options_description& desc)
23 {
25  desc.add_options()
26  ("input", boost::program_options::value<std::string>(&m_inputAddress)->required(),
27  "where to read the events from")
28  ("bufferSize", boost::program_options::value<unsigned int>(&m_bufferSize)->default_value(m_bufferSize),
29  "how many events to keep in the buffer");
30 }
31 
33 {
36  m_output.reset(new ZMQNullConnection);
37 }
38 
39 void ZMQAcceptor::addOptions(po::options_description& desc)
40 {
42  desc.add_options()
43  ("input", boost::program_options::value<std::string>(&m_inputAddress)->required(),
44  "where to read the events from");
45 }
46 
48 {
52 }
53 
54 void ZMQWorker::addOptions(po::options_description& desc)
55 {
57  desc.add_options()
58  ("input", boost::program_options::value<std::string>(&m_inputAddress)->required(),
59  "where to read the events from")
60  ("output", boost::program_options::value<std::string>(&m_outputAddress)->required(),
61  "where to send the events to")
62  ("bufferSize", boost::program_options::value<unsigned int>(&m_bufferSize)->default_value(m_bufferSize),
63  "how many events to keep in the buffer");
64 }
65 
67 {
68  auto message = m_input->handleIncomingData();
69  B2ASSERT("There should always be a message", message);
70 
71  if (message->isMessage(EMessageTypes::c_terminateMessage)) {
72  m_terminate = true;
73  }
74 
75  m_output->handleEvent(std::move(message));
76 }
Belle2::ZMQStandardApp< ZMQLoadBalancedInput, ZMQNullConnection >::m_output
std::unique_ptr< ZMQNullConnection > m_output
Pointer to the output connection. Should be set in initialize.
Definition: ZMQApp.h:79
Belle2::ZMQConfirmedOutput
Output part of a confirmed connection.
Definition: ZMQConfirmedConnection.h:116
Belle2::ZMQReadySender::initialize
void initialize() final
Initialize the two connections using the command line arguments.
Definition: ZMQClasses.cc:15
Belle2::ZMQWorker::addOptions
void addOptions(po::options_description &desc) final
Add the parameters to the cmd line arguments.
Definition: ZMQClasses.cc:54
Belle2::ZMQConfirmedInput
Input part of a confirmed connection.
Definition: ZMQConfirmedConnection.h:65
Belle2::ZMQWorker::m_bufferSize
unsigned int m_bufferSize
Parameter: buffer size.
Definition: ZMQClasses.h:88
Belle2::ZMQReadySender::m_inputAddress
std::string m_inputAddress
Parameter: input address.
Definition: ZMQClasses.h:45
Belle2::ZMQStandardApp< ZMQLoadBalancedInput, ZMQConfirmedOutput >::m_terminate
bool m_terminate
Can be set by functions to terminate the main loop at the next possibility.
Definition: ZMQApp.h:83
Belle2::ZMQAcceptor::addOptions
void addOptions(po::options_description &desc) final
Add the parameters to the cmd line arguments.
Definition: ZMQClasses.cc:39
Belle2::ZMQStandardApp< ZMQLoadBalancedInput, ZMQNullConnection >::m_parent
std::shared_ptr< ZMQParent > m_parent
Pointer to the ZMQParent to be used as base for all connections.
Definition: ZMQApp.h:75
Belle2::ZMQAcceptor::m_inputAddress
std::string m_inputAddress
Parameter: input address.
Definition: ZMQClasses.h:64
Belle2::ZMQStandardApp::addOptions
virtual void addOptions(po::options_description &desc)
Override in a derived class to add the command line arguments. Do not forget to call this base functi...
Definition: ZMQApp.details.h:134
Belle2::ZMQNullConnection
Connection doing just nothing: without the capability to pull, send or receive. Useful for template i...
Definition: ZMQNullConnection.h:31
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ZMQWorker::m_outputAddress
std::string m_outputAddress
Parameter: output address.
Definition: ZMQClasses.h:86
Belle2::ZMQAcceptor::initialize
void initialize() final
Initialize the two connections using the command line arguments.
Definition: ZMQClasses.cc:32
Belle2::ZMQLoadBalancedInput
Input part of a load-balanced connection.
Definition: ZMQLoadBalancedConnection.h:50
Belle2::ZMQReadySender::m_bufferSize
unsigned int m_bufferSize
Parameter: buffer size.
Definition: ZMQClasses.h:47
Belle2::ZMQWorker::handleInput
void handleInput() final
Transport the message from the input to the output connection.
Definition: ZMQClasses.cc:66
Belle2::ZMQReadySender::addOptions
void addOptions(po::options_description &desc) final
Add the parameters to the cmd line arguments.
Definition: ZMQClasses.cc:22
Belle2::ZMQStandardApp::initialize
virtual void initialize()
Override in a derived class to initialize the connections from the given command line arguments....
Definition: ZMQApp.details.h:127
Belle2::ZMQWorker::initialize
void initialize() final
Initialize the two connections using the command line arguments.
Definition: ZMQClasses.cc:47
Belle2::ZMQStandardApp< ZMQLoadBalancedInput, ZMQNullConnection >::m_input
std::unique_ptr< ZMQLoadBalancedInput > m_input
Pointer to the input connection. Should be set in initialize.
Definition: ZMQApp.h:77
Belle2::ZMQWorker::m_inputAddress
std::string m_inputAddress
Parameter: input address.
Definition: ZMQClasses.h:84