Belle II Software  release-08-01-10
ZMQROIOutput Class Reference

Dedicated output to send ROI messages to the PXD ONSEN system. More...

#include <ZMQROIConnection.h>

Inheritance diagram for ZMQROIOutput:
Collaboration diagram for ZMQROIOutput:

Public Types

using ReactorFunction = std::function< void(void)>
 Typedef of a function which will be called if a connection has a message.
 

Public Member Functions

 ZMQROIOutput (const std::string &outputAddress, const std::shared_ptr< ZMQParent > &parent)
 Create a new ROI output basically initializing the raw output member.
 
void handleEvent (zmq::message_t message)
 Send a message and add the PXD specific header and trailer.
 
std::string getMonitoringJSON () const final
 Copy the functionality from the raw output.
 
void handleIncomingData ()
 Copy the functionality from the raw output.
 
bool isReady () const final
 Copy the functionality from the raw output.
 
std::vector< zmq::socket_t * > getSockets () const final
 Copy the functionality from the raw output.
 
std::string getEndPoint () const
 Return the connection string.
 
template<class AClass >
void log (const std::string &key, const AClass &value)
 Store a value under a certain key. Different types of values can be stored, namely long, double or string. Mixtures are not allowed for a given key.
 
void increment (const std::string &key)
 Increment the value with the given key (only numerical values). If not present, set to 1.
 
void decrement (const std::string &key)
 Decrement the value with the given key (only numerical values). If not present, set to -1.
 
template<size_t MAX_SIZE = 100>
void average (const std::string &key, double value)
 Instead of storeing the double value directly under the given key, store the average of the last MAX_SIZE values.
 
template<size_t AVERAGE_SIZE = 2000>
void timeit (const std::string &key)
 Measure the rate of calls with the same key every AVERAGE_SIZE calls (and also display the last time AVERAGE_SIZE was reached under <key>_last_measurement)
 
void logTime (const std::string &key)
 Store the current time as a string under the given key.
 

Static Public Member Functions

static bool poll (const std::map< const ZMQConnection *, ReactorFunction > &connectionList, int timeout)
 Poll on the given connections and call the attached function if a messages comes in. More...
 
static bool hasMessage (const ZMQConnection *connection)
 Check if the given connection as an incoming message (right now, no waiting).
 

Private Member Functions

void addHeader (char *buffer, unsigned int size)
 Helper function to add the header with the given message size.
 
void addTrailer (char *buffer)
 Helper function to add the trailer.
 

Private Attributes

ZMQRawOutput m_rawOutput
 The used raw output.
 
std::map< std::string, std::variant< long, double, std::string > > m_monitoring
 Internal storage of all stored values.
 
std::unordered_map< std::string, std::tuple< std::vector< double >, size_t > > m_averages
 Internal storage of the previous values when calculating averages.
 
std::unordered_map< std::string, std::tuple< unsigned long, std::chrono::system_clock::time_point > > m_timeCounters
 Internal storage how often the timeit function for a given key was called and when it has last reached MAX_SIZE.
 

Static Private Attributes

static constexpr const unsigned int HEADER_SIZE = sizeof(struct h2m_header_t)
 Size of the header in bytes.
 
static constexpr const unsigned int TRAILER_SIZE = sizeof(struct h2m_footer_t)
 Size of the trailer in bytes.
 

Detailed Description

Dedicated output to send ROI messages to the PXD ONSEN system.

Behaves exactly the same as a RawOutput (it is implemented with one) but adds the PXD-specific headers and trailers around the message when sending.

Definition at line 30 of file ZMQROIConnection.h.

Member Function Documentation

◆ poll()

bool poll ( const std::map< const ZMQConnection *, ReactorFunction > &  connectionList,
int  timeout 
)
staticinherited

Poll on the given connections and call the attached function if a messages comes in.

If after timeout milliseconds still no message is received, return anyways. If timeout is 0, do not wait. If timeout is -1, wait infinitely.

Returns true if a message was received on any socket, false otherwise. Attention: in case of an interrupted system call (e.g. because a signal was received) the function might return anyways with a negative result even before the timeout!

Definition at line 27 of file ZMQConnection.cc.


The documentation for this class was generated from the following file: