Belle II Software  release-05-01-25
ZMQROIConnection.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, Markus Prim *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <daq/hbasf2/connections/ZMQROIConnection.h>
11 #include <arpa/inet.h>
12 
13 using namespace Belle2;
14 
15 ZMQDataAndROIOutput::ZMQDataAndROIOutput(const std::string& dataAddress, const std::string& roiAddress,
16  bool addEventSize, const std::shared_ptr<ZMQParent>& parent) :
17  m_dataOutput(dataAddress, addEventSize, parent), m_roiOutput(roiAddress, false, parent) {}
18 
19 void ZMQDataAndROIOutput::handleEvent(std::unique_ptr<ZMQNoIdMessage> message)
20 {
21  if (message->isMessage(EMessageTypes::c_rawDataMessage) or message->isMessage(EMessageTypes::c_eventMessage)) {
22  B2ASSERT("The data message needs to be present!", message->getDataMessage().size() > 0);
23  B2ASSERT("The roi message needs to be present!", message->getAdditionalDataMessage().size() > 0);
24 
25  m_dataOutput.handleEvent(std::move(message->getDataMessage()));
26  m_roiOutput.handleEvent(std::move(message->getAdditionalDataMessage()));
27  }
28 }
29 
31 {
34  }
37  }
38 }
39 
41 {
42  return m_dataOutput.isReady() and m_roiOutput.isReady();
43 }
44 
45 std::vector<zmq::socket_t*> ZMQDataAndROIOutput::getSockets() const
46 {
47  return {m_dataOutput.getSockets()[0], m_roiOutput.getSockets()[0]};
48 }
49 
51 {
53 }
54 
56 {
58 }
Belle2::ZMQDataAndROIOutput::handleEvent
void handleEvent(std::unique_ptr< ZMQNoIdMessage > message)
Send the normal data message to raw and the additional message to ROI.
Definition: ZMQROIConnection.cc:19
Belle2::ZMQDataAndROIOutput::ZMQDataAndROIOutput
ZMQDataAndROIOutput(const std::string &dataAddress, const std::string &roiAddress, bool addEventSize, const std::shared_ptr< ZMQParent > &parent)
Initialize the raw and roi connection.
Definition: ZMQROIConnection.cc:15
Belle2::ZMQDataAndROIOutput::getMonitoringJSON
std::string getMonitoringJSON() const final
Get the monitoring JSON from the raw connection.
Definition: ZMQROIConnection.cc:50
Belle2::ZMQDataAndROIOutput::isReady
bool isReady() const final
Ready only when both sockets are ready.
Definition: ZMQROIConnection.cc:40
Belle2::ZMQDataAndROIOutput::m_roiOutput
ZMQRawOutput m_roiOutput
The used ROI connection.
Definition: ZMQROIConnection.h:65
Belle2::ZMQDataAndROIOutput::getSockets
std::vector< zmq::socket_t * > getSockets() const final
Return both sockets for polling.
Definition: ZMQROIConnection.cc:45
Belle2::ZMQRawOutput::handleIncomingData
void handleIncomingData()
Handle incoming data: a socket (dis)connect.
Definition: ZMQRawConnection.cc:183
Belle2::ZMQDataAndROIOutput::m_dataOutput
ZMQRawOutput m_dataOutput
The used raw connection.
Definition: ZMQROIConnection.h:63
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
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::ZMQDataAndROIOutput::handleIncomingData
void handleIncomingData()
Handle both a socket (dis)connect by raw or ROI.
Definition: ZMQROIConnection.cc:30
Belle2::ZMQRawOutput::isReady
bool isReady() const final
If no socket is connected, this connection is not ready.
Definition: ZMQRawConnection.cc:204
Belle2::ZMQLogger::getMonitoringJSON
virtual std::string getMonitoringJSON() const
Convert the stored monitoring values to a JSON string ready for sending out via a message.
Definition: ZMQLogger.cc:17
Belle2::ZMQConnection::hasMessage
static bool hasMessage(const ZMQConnection *connection)
Check if the given connection as an incoming message (right now, no waiting).
Definition: ZMQConnection.cc:22
Belle2::ZMQDataAndROIOutput::getROIMonitoringJSON
std::string getROIMonitoringJSON() const
Get the monitoring JSON from the ROI connection.
Definition: ZMQROIConnection.cc:55
Belle2::ZMQConnectionOverSocket::getSockets
std::vector< zmq::socket_t * > getSockets() const final
The socket used for polling is just the stored socket.
Definition: ZMQConnection.cc:85