Belle II Software  release-08-01-10
ZMQClasses.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 #include <daq/hbasf2/apps/ZMQClasses.h>
9 #include <framework/logging/Logger.h>
10 
11 using namespace Belle2;
12 
14 {
17  m_output.reset(new ZMQNullConnection);
18 }
19 
20 void ZMQReadySender::addOptions(po::options_description& desc)
21 {
23  desc.add_options()
24  ("input", boost::program_options::value<std::string>(&m_inputAddress)->required(),
25  "where to read the events from")
26  ("bufferSize", boost::program_options::value<unsigned int>(&m_bufferSize)->default_value(m_bufferSize),
27  "how many events to keep in the buffer");
28 }
29 
31 {
34  m_output.reset(new ZMQNullConnection);
35 }
36 
37 void ZMQAcceptor::addOptions(po::options_description& desc)
38 {
40  desc.add_options()
41  ("input", boost::program_options::value<std::string>(&m_inputAddress)->required(),
42  "where to read the events from");
43 }
44 
46 {
50 }
51 
52 void ZMQWorker::addOptions(po::options_description& desc)
53 {
55  desc.add_options()
56  ("input", boost::program_options::value<std::string>(&m_inputAddress)->required(),
57  "where to read the events from")
58  ("output", boost::program_options::value<std::string>(&m_outputAddress)->required(),
59  "where to send the events to")
60  ("bufferSize", boost::program_options::value<unsigned int>(&m_bufferSize)->default_value(m_bufferSize),
61  "how many events to keep in the buffer");
62 }
63 
65 {
66  auto message = m_input->handleIncomingData();
67  B2ASSERT("There should always be a message", message);
68 
69  if (message->isMessage(EMessageTypes::c_terminateMessage)) {
70  m_terminate = true;
71  }
72 
73  m_output->handleEvent(std::move(message));
74 }
std::string m_inputAddress
Parameter: input address.
Definition: ZMQClasses.h:54
void initialize() final
Initialize the two connections using the command line arguments.
Definition: ZMQClasses.cc:30
void addOptions(po::options_description &desc) final
Add the parameters to the cmd line arguments.
Definition: ZMQClasses.cc:37
Input part of a confirmed connection.
Output part of a confirmed connection.
Input part of a load-balanced connection.
Connection doing just nothing: without the capability to pull, send or receive. Useful for template i...
unsigned int m_bufferSize
Parameter: buffer size.
Definition: ZMQClasses.h:37
std::string m_inputAddress
Parameter: input address.
Definition: ZMQClasses.h:35
void initialize() final
Initialize the two connections using the command line arguments.
Definition: ZMQClasses.cc:13
void addOptions(po::options_description &desc) final
Add the parameters to the cmd line arguments.
Definition: ZMQClasses.cc:20
std::shared_ptr< ZMQParent > m_parent
Pointer to the ZMQParent to be used as base for all connections.
Definition: ZMQApp.h:65
std::unique_ptr< ZMQNullConnection > m_output
Pointer to the output connection. Should be set in initialize.
Definition: ZMQApp.h:69
bool m_terminate
Can be set by functions to terminate the main loop at the next possibility.
Definition: ZMQApp.h:73
std::unique_ptr< ZMQLoadBalancedInput > m_input
Pointer to the input connection. Should be set in initialize.
Definition: ZMQApp.h:67
unsigned int m_bufferSize
Parameter: buffer size.
Definition: ZMQClasses.h:78
std::string m_inputAddress
Parameter: input address.
Definition: ZMQClasses.h:74
void initialize() final
Initialize the two connections using the command line arguments.
Definition: ZMQClasses.cc:45
void addOptions(po::options_description &desc) final
Add the parameters to the cmd line arguments.
Definition: ZMQClasses.cc:52
std::string m_outputAddress
Parameter: output address.
Definition: ZMQClasses.h:76
void handleInput() final
Transport the message from the input to the output connection.
Definition: ZMQClasses.cc:64
virtual void initialize()
Override in a derived class to initialize the connections from the given command line arguments....
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...
Abstract base class for different kinds of events.