Belle II Software  release-05-01-25
ZMQRawConnection.h
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 #pragma once
11 
12 #include <framework/pcore/zmq/connections/ZMQConnection.h>
13 #include <framework/pcore/zmq/utils/ZMQParent.h>
14 
15 #include <zmq.hpp>
16 
17 #include <string>
18 #include <memory>
19 
20 namespace Belle2 {
43  class ZMQRawInput : public ZMQConnectionOverSocket {
44  public:
46  ZMQRawInput(const std::string& inputAddress, unsigned int maximalBufferSize, bool receiveEventMessages,
47  const std::shared_ptr<ZMQParent>& parent);
48 
56  std::vector<zmq::message_t> handleIncomingData();
57 
59  void clear();
60 
61  private:
63  unsigned int m_maximalBufferSize;
65  std::vector<char> m_buffer;
67  size_t m_writeAddress = 0;
69  unsigned int m_currentSize = 0;
73  std::string m_inputIdentity = "";
74  };
75 
89  class ZMQRawOutput : public ZMQConnectionOverSocket {
90  public:
92  ZMQRawOutput(const std::string& outputAddress, bool addEventSize, const std::shared_ptr<ZMQParent>& parent);
93 
95  virtual void handleEvent(zmq::message_t message);
99  bool isReady() const final;
100 
101  private:
103  std::string m_dataIdentity = "";
105  bool m_addEventSize = false;
106  };
108 }
Belle2::ZMQRawOutput::m_dataIdentity
std::string m_dataIdentity
Internal storage of the connected identity to no have multiple connections.
Definition: ZMQRawConnection.h:111
Belle2::ZMQRawInput::m_receiveEventMessages
bool m_receiveEventMessages
Parameter to receive event messages (see above)
Definition: ZMQRawConnection.h:79
Belle2::ZMQRawInput::clear
void clear()
Reset the internal buffer and counter.
Definition: ZMQRawConnection.cc:42
Belle2::ZMQRawOutput::handleIncomingData
void handleIncomingData()
Handle incoming data: a socket (dis)connect.
Definition: ZMQRawConnection.cc:183
Belle2::ZMQRawInput::m_maximalBufferSize
unsigned int m_maximalBufferSize
Parameter for the maximal buffer size. If this size is reached, a FATAL will be issued.
Definition: ZMQRawConnection.h:71
Belle2::ZMQRawOutput::m_addEventSize
bool m_addEventSize
Parameter to add the event size to a message.
Definition: ZMQRawConnection.h:113
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::ZMQRawInput::m_inputIdentity
std::string m_inputIdentity
Internal storage of the connected socket to check if we get messages from multiple ones.
Definition: ZMQRawConnection.h:81
Belle2::ZMQRawOutput::handleEvent
virtual void handleEvent(zmq::message_t message)
Pass on the message - maybe by prefixing it with a htonl-converted data size in bytes.
Definition: ZMQRawConnection.cc:160
Belle2::ZMQRawInput::m_currentSize
unsigned int m_currentSize
How large should the full message be? The information is from the first int of the message.
Definition: ZMQRawConnection.h:77
Belle2::ZMQRawInput::handleIncomingData
std::vector< zmq::message_t > handleIncomingData()
Block until a TCP packet can be received from the socket.
Definition: ZMQRawConnection.cc:48
Belle2::ZMQRawInput::m_buffer
std::vector< char > m_buffer
Internal storage for the buffer.
Definition: ZMQRawConnection.h:73
Belle2::ZMQRawOutput::isReady
bool isReady() const final
If no socket is connected, this connection is not ready.
Definition: ZMQRawConnection.cc:204
Belle2::ZMQConnectionOverSocket
Specialized connection over a ZMQ socket.
Definition: ZMQConnection.h:72
Belle2::ZMQRawInput::ZMQRawInput
ZMQRawInput(const std::string &inputAddress, unsigned int maximalBufferSize, bool receiveEventMessages, const std::shared_ptr< ZMQParent > &parent)
Create a new raw input connection. The bind or connect behavior is chosen according to the given addr...
Definition: ZMQRawConnection.cc:18
Belle2::ZMQRawOutput
Output connection to speak to non-zmq sockets via a ZMQ_STREAM socket.
Definition: ZMQRawConnection.h:97
Belle2::ZMQRawOutput::ZMQRawOutput
ZMQRawOutput(const std::string &outputAddress, bool addEventSize, const std::shared_ptr< ZMQParent > &parent)
Create a new raw output connection. The bind or connect behavior is chosen according to the given add...
Definition: ZMQRawConnection.cc:143
Belle2::ZMQRawInput::m_writeAddress
size_t m_writeAddress
Where in the buffer are we currently writing to.
Definition: ZMQRawConnection.h:75