Belle II Software development
ZMQROIConnection.h
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#pragma once
9
10#include <framework/pcore/zmq/connections/ZMQRawConnection.h>
11#include <framework/pcore/zmq/utils/ZMQParent.h>
12#include <framework/pcore/zmq/messages/ZMQNoIdMessage.h>
13#include <daq/roisend/h2m.h>
14
15#include <zmq.hpp>
16
17namespace Belle2 {
30 class ZMQROIOutput : public ZMQConnection {
31 public:
33 ZMQROIOutput(const std::string& outputAddress, const std::shared_ptr<ZMQParent>& parent);
34
36 void handleEvent(zmq::message_t message);
38 std::string getMonitoringJSON() const final;
42 bool isReady() const final;
44 std::vector<zmq::socket_t*> getSockets() const final;
46 std::string getEndPoint() const { return m_rawOutput.getEndPoint(); }
47 private:
49 static constexpr const unsigned int HEADER_SIZE = sizeof(struct h2m_header_t);
51 static constexpr const unsigned int TRAILER_SIZE = sizeof(struct h2m_footer_t);
52
55
57 void addHeader(char* buffer, unsigned int size);
59 void addTrailer(char* buffer);
60 };
61
71 public:
73 ZMQDataAndROIOutput(const std::string& dataAddress, const std::string& roiAddress, bool addEventSize,
74 const std::shared_ptr<ZMQParent>& parent);
75
77 std::string getMonitoringJSON() const final;
79 std::string getROIMonitoringJSON() const;
80
82 void handleEvent(std::unique_ptr<ZMQNoIdMessage> message);
84 void handleIncomingData();
86 bool isReady() const final;
88 std::vector<zmq::socket_t*> getSockets() const final;
90 std::string getEndPoint() const { return m_dataOutput.getEndPoint() + ";" + m_roiOutput.getEndPoint(); }
91 private:
96 };
98}
std::string getEndPoint() const
Return the connection string for this socket.
Base class for every connection with virtual functions to be implemented:
Definition: ZMQConnection.h:31
Helper connection hosting both a normal raw and a ROI output and sending to both at the same time.
std::string getEndPoint() const
Return the connection string.
void handleIncomingData()
Handle both a socket (dis)connect by raw or ROI.
ZMQRawOutput m_dataOutput
The used raw connection.
std::string getROIMonitoringJSON() const
Get the monitoring JSON from the ROI connection.
bool isReady() const final
Ready only when both sockets are ready.
std::string getMonitoringJSON() const final
Get the monitoring JSON from the raw connection.
ZMQRawOutput m_roiOutput
The used ROI connection.
void handleEvent(std::unique_ptr< ZMQNoIdMessage > message)
Send the normal data message to raw and the additional message to ROI.
std::vector< zmq::socket_t * > getSockets() const final
Return both sockets for polling.
Dedicated output to send ROI messages to the PXD ONSEN system.
void addTrailer(char *buffer)
Helper function to add the trailer.
std::string getEndPoint() const
Return the connection string.
void handleIncomingData()
Copy the functionality from the raw output.
ZMQROIOutput(const std::string &outputAddress, const std::shared_ptr< ZMQParent > &parent)
Create a new ROI output basically initializing the raw output member.
static constexpr const unsigned int HEADER_SIZE
Size of the header in bytes.
void handleEvent(zmq::message_t message)
Send a message and add the PXD specific header and trailer.
static constexpr const unsigned int TRAILER_SIZE
Size of the trailer in bytes.
void addHeader(char *buffer, unsigned int size)
Helper function to add the header with the given message size.
bool isReady() const final
Copy the functionality from the raw output.
std::string getMonitoringJSON() const final
Copy the functionality from the raw output.
std::vector< zmq::socket_t * > getSockets() const final
Copy the functionality from the raw output.
ZMQRawOutput m_rawOutput
The used raw output.
Output connection to speak to non-zmq sockets via a ZMQ_STREAM socket.
Abstract base class for different kinds of events.
STL namespace.