8#include <framework/pcore/ProcHandler.h>
9#include <framework/pcore/zmq/processModules/ZMQRxOutputModule.h>
10#include <framework/pcore/zmq/messages/ZMQDefinitions.h>
11#include <framework/pcore/zmq/messages/ZMQMessageFactory.h>
12#include <framework/core/Environment.h>
27 B2ASSERT(
"Module is only allowed in a multiprocessing environment. If you only want to use a single process,"
28 "set the number of processes to at least 1.",
57 const auto multicastAnswer = [
this](
const auto & socket) {
58 auto message = ZMQMessageFactory::fromSocket<ZMQNoIdMessage>(socket);
59 if (message->isMessage(EMessageTypes::c_eventMessage)) {
60 B2DEBUG(100,
"Having received an event backup. Will go in with this.");
65 }
else if (message->isMessage(EMessageTypes::c_lastEventMessage)) {
66 B2DEBUG(100,
"Having received an end message. Will not go on.");
69 }
else if (message->isMessage(EMessageTypes::c_terminateMessage)) {
70 B2DEBUG(100,
"Having received an graceful stop message. Will not go on.");
75 B2ERROR(
"Undefined message on multicast");
79 const auto socketAnswer = [
this](
const auto & socket) {
80 auto message = ZMQMessageFactory::fromSocket<ZMQNoIdMessage>(socket);
81 if (message->isMessage(EMessageTypes::c_eventMessage)) {
91 B2INFO(
"ZMQOutputModule : sending out EndRun record.");
101 B2INFO(
"ZMQOutputModule : sending out HLTZMQ first event.");
111 B2ERROR(
"Undefined message on socket");
116 B2DEBUG(100,
"Start polling");
120 B2ASSERT(
"Output process did not receive any message in some time. Aborting.", pollReply);
123 B2DEBUG(30,
"finished reading in an event.");
124 }
catch (zmq::error_t& ex) {
125 if (ex.num() != EINTR) {
126 B2ERROR(
"There was an error during the Rx output event: " << ex.what());
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
int getNumberProcesses() const
Returns the number of worker processes which should be used for the parallel processing.
static Environment & Instance()
Static method to get a reference to the Environment instance.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Type-safe access to single objects in the data store.
void read(std::unique_ptr< ZMQNoIdMessage > message)
Read in a ZMQ message and rebuilt the data store from it.
void initialize(int compressionLevel, bool handleMergeable)
Initialize this class. Call this e.g. in the first event.
void publish(AZMQMessage message) const
Publish the message to the multicast.
void initialize(const std::string &pubSocketAddress, const std::string &subSocketAddress, const std::string &socketAddress, bool bind)
Initialize the multicast and a data socket of the given type.
void terminate(bool sendGoodbye=true)
Terminate the sockets properly.
void subscribe(EMessageTypes messageType)
Subscribe to the given multicast message type.
static auto createMessage(const std::string &msgIdentity, const EMessageTypes msgType, const std::unique_ptr< EvtMessage > &eventMessage)
Create an ID Message out of an identity, the type and an event message.
int m_param_compressionLevel
Parameter: Compression level of the streamer.
bool m_firstEvent
Set to false if the objects are initialized.
std::string m_param_socketName
Parameter: name of the data socket.
StreamHelper m_streamer
The data store streamer.
ZMQRxOutputModule()
Constructor setting the moudle paramters.
void initialize() override
Initialize the streamer.
ZMQClient m_zmqClient
Our ZMQ client.
void event() override
Receive an event and store it in the datastore. Confirm to the input process.
void terminate() override
Terminate the client and tell the monitor, we are done.
unsigned int m_param_maximalWaitingTime
Maximal time to wait until aborting in ms.
StoreObjPtr< EventMetaData > m_eventMetaData
The event meta data in the data store needed for confirming events.
std::string m_param_xpubProxySocketName
Parameter: name of the pub multicast socket.
bool m_param_handleMergeable
Parameter: Can we handle mergeables?
StoreObjPtr< RandomGenerator > m_randomgenerator
The random generator in the data store.
std::string m_param_xsubProxySocketName
Parameter: name of the sub multicast socket.
int m_endRun
End Run counter.
int m_beginRun
Begin Run counter.
int poll(unsigned int timeout, AMulticastAnswer multicastAnswer, ASocketAnswer socketAnswer) const
Poll both the multicast and the data socket until, either:
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.