Belle II Software development
ZMQStandardApp< AInputConnection, AOutputConnection > Class Template Reference

Generic base class for all standalone ZMQ applications. More...

#include <ZMQApp.h>

Public Member Functions

void initFromConsole (const std::string &description, int argc, char *argv[])
 Should be called before the main() function to initialize the connections using the paremeters given on command line.
 
void main ()
 Start the main loop polling on the output and monitoring connections and eventually also on the input if the output is ready.
 

Protected Member Functions

virtual void initialize ()
 Override in a derived class to initialize the connections from the given command line arguments. Do not forget to call this base function also.
 
virtual void addOptions (po::options_description &desc)
 Override in a derived class to add the command line arguments. Do not forget to call this base function also.
 
virtual void handleExternalSignal (EMessageTypes)
 Will get called for every signal message on the monitoring connection. Can be overridden in a derived class. Empty by default.
 
virtual void handleInput ()
 Will get called for every message on the input connection. Can be overridden in a derived class. Calls handleIncomingData by default.
 
virtual void handleOutput ()
 Will get called for every message on the output connection. Can be overridden in a derived class. Calls handleIncomingData by default.
 
virtual void handleTimeout ()
 Will get called on a timeout. Can be overridden in a derived class. Empty by default.
 
virtual void fillMonitoringJSON (std::stringstream &buffer) const
 Using the connections, fill up a buffer with the content to be monitored.
 
bool terminated () const
 Check if the main loop will be exited on next occasion. Can be set via the "m_terminate" flag.
 
void resetTimer ()
 Helper function to reset the start time and the remaining time.
 
void pollEvent (bool pollOnInput)
 Poll until a single event is retreived.
 

Protected Attributes

std::shared_ptr< ZMQParentm_parent
 Pointer to the ZMQParent to be used as base for all connections.
 
std::unique_ptr< AInputConnection > m_input
 Pointer to the input connection. Should be set in initialize.
 
std::unique_ptr< AOutputConnection > m_output
 Pointer to the output connection. Should be set in initialize.
 
std::unique_ptr< ZMQSimpleConnectionm_monitor
 Pointer to the monitoring connection. Should be set in initialize.
 
bool m_terminate = false
 Can be set by functions to terminate the main loop at the next possibility.
 
unsigned int m_timeout = 0
 If set to a value != 0, will call handleTimeout with this frequency (in seconds).
 
bool m_monitorHasPriority = false
 Flag to break out of the polling loop to check for monitoring messages. Except for the finalcollector you probably do not want this.
 

Private Member Functions

bool checkTimer ()
 Helper function to check, if the timeout should happen.
 
void updateTimer ()
 Helper function to update the remaining time.
 
void handleMonitoring ()
 Handle an incoming message on the monitoring socket by either calling handleExternalSignal() or by passing on the monitor JSONs of the connections.
 

Private Attributes

HLTMainLoop m_mainLoop
 Internal signal handler.
 
std::string m_monitoringAddress
 Storage for the monitoring address for the cmd arguments.
 
int m_remainingTime = -1
 Counter for the remaining time until a timeout happens.
 
std::chrono::system_clock::time_point m_start
 Start time for the timeout.
 

Detailed Description

template<class AInputConnection, class AOutputConnection>
class Belle2::ZMQStandardApp< AInputConnection, AOutputConnection >

Generic base class for all standalone ZMQ applications.

It always consists of three connections, two of them are given as template parameters: the input and the output connection. By default, the main loop listens on the output and monitoring socket(s) while the output is not ready and also listens on the input if the output is ready.

Before starting the main loop, the virtual initialize() function should be called. When the input socket receives a message, the virtual "handleInput" function is called (defaults to handleIncomingData of the connection). When the output socket receives a message, the virtual "handleOutput" function is called (defaults to handleIncomingData of the connection). When the monitoring receives a signal message, the virtual "handleExternalSignal" function is called (defaults to nothing). When the timeout is set to a value other than 0, the virtual handleTimeout function is called with the given frequency (defaults to nothing).

Be reimplementing those four functions (or parts of them), the behaviour can be customized.

Definition at line 46 of file ZMQApp.h.

Member Data Documentation

◆ m_input

std::unique_ptr<AInputConnection> m_input
protected

Pointer to the input connection. Should be set in initialize.

Definition at line 67 of file ZMQApp.h.

◆ m_mainLoop

HLTMainLoop m_mainLoop
private

Internal signal handler.

Definition at line 102 of file ZMQApp.h.

◆ m_monitor

std::unique_ptr<ZMQSimpleConnection> m_monitor
protected

Pointer to the monitoring connection. Should be set in initialize.

Definition at line 71 of file ZMQApp.h.

◆ m_monitorHasPriority

bool m_monitorHasPriority = false
protected

Flag to break out of the polling loop to check for monitoring messages. Except for the finalcollector you probably do not want this.

Definition at line 77 of file ZMQApp.h.

◆ m_monitoringAddress

std::string m_monitoringAddress
private

Storage for the monitoring address for the cmd arguments.

Definition at line 104 of file ZMQApp.h.

◆ m_output

std::unique_ptr<AOutputConnection> m_output
protected

Pointer to the output connection. Should be set in initialize.

Definition at line 69 of file ZMQApp.h.

◆ m_parent

std::shared_ptr<ZMQParent> m_parent
protected

Pointer to the ZMQParent to be used as base for all connections.

Definition at line 65 of file ZMQApp.h.

◆ m_remainingTime

int m_remainingTime = -1
private

Counter for the remaining time until a timeout happens.

Definition at line 106 of file ZMQApp.h.

◆ m_start

std::chrono::system_clock::time_point m_start
private

Start time for the timeout.

Definition at line 108 of file ZMQApp.h.

◆ m_terminate

bool m_terminate = false
protected

Can be set by functions to terminate the main loop at the next possibility.

Definition at line 73 of file ZMQApp.h.

◆ m_timeout

unsigned int m_timeout = 0
protected

If set to a value != 0, will call handleTimeout with this frequency (in seconds).

Definition at line 75 of file ZMQApp.h.


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