Belle II Software development
ZMQROIConnection.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/connections/ZMQROIConnection.h>
9#include <arpa/inet.h>
10
11using namespace Belle2;
12
13ZMQDataAndROIOutput::ZMQDataAndROIOutput(const std::string& dataAddress, const std::string& roiAddress,
14 bool addEventSize, const std::shared_ptr<ZMQParent>& parent) :
15 m_dataOutput(dataAddress, addEventSize, parent), m_roiOutput(roiAddress, false, parent) {}
16
17void ZMQDataAndROIOutput::handleEvent(std::unique_ptr<ZMQNoIdMessage> message)
18{
19 if (message->isMessage(EMessageTypes::c_rawDataMessage) or message->isMessage(EMessageTypes::c_eventMessage)) {
20 B2ASSERT("The data message needs to be present!", message->getDataMessage().size() > 0);
21 B2ASSERT("The roi message needs to be present!", message->getAdditionalDataMessage().size() > 0);
22
23 m_dataOutput.handleEvent(std::move(message->getDataMessage()));
24 m_roiOutput.handleEvent(std::move(message->getAdditionalDataMessage()));
25 }
26}
27
29{
31 m_dataOutput.handleIncomingData();
32 }
34 m_roiOutput.handleIncomingData();
35 }
36}
37
39{
40 return m_dataOutput.isReady() and m_roiOutput.isReady();
41}
42
43std::vector<zmq::socket_t*> ZMQDataAndROIOutput::getSockets() const
44{
45 return {m_dataOutput.getSockets()[0], m_roiOutput.getSockets()[0]};
46}
47
49{
50 return m_dataOutput.getMonitoringJSON();
51}
52
54{
55 return m_roiOutput.getMonitoringJSON();
56}
static bool hasMessage(const ZMQConnection *connection)
Check if the given connection as an incoming message (right now, no waiting).
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.
ZMQDataAndROIOutput(const std::string &dataAddress, const std::string &roiAddress, bool addEventSize, const std::shared_ptr< ZMQParent > &parent)
Initialize the raw and roi connection.
Abstract base class for different kinds of events.