REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Data Structures | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes
TRestMessenger Class Reference

Detailed Description

TRestMessenger

This metadata helps to recieve/dispatch messages across processes(UNIX process) For example, we start two restManager with TRestMessenger added as metadata. For one of them, we add a "sendMessage" task after "processEvent". Then, when the process chain finishes, it will dispatch the message containing, e.g., the output file name. Then, the other restManager can get the message and be notified that the file is done. It can therefore do some operations to this file, e.g., add to TRestAnalysisPlot file list and update the plots.

By default it uses shared memory. Can be overridden by REST packages, adding more communication methods(http, kafka, etc.)

Each TRestMessenger connects to a message pool in shared memory. Each message pool is limited with 100 messages. Each message is limited with 256 bytes. When sending message, the message is added to the message pool. When receiving message, the logic is more like "consuming": message is taken out from the pool and given to the specific process. It will be erased after being consumed. TRestMessenger cannot consume the message sent by self process.

The rml definition is like follows. We need to add serval <pool sections in its config section to define the message pools. The token of the pool is equivalent to the shm key, where two processes with a same token can access to a same memory.

<TRestManager name="CoBoDataAnalysis" title="Example" verboseLevel="info" >
<TRestMessenger name="Messager" title="Example" verboseLevel="info"
messageSource="outputfile" token="116027"/>
<addTask command="Messager->SendMessage()" value="ON"/>
Managing applications and executing tasks.
Definition: TRestManager.h:16

RESTsoft - Software for Rare Event Searches with TPCs

History of developments:

2020-Aug: First implementation and concept Ni Kaixiang

Author
Ni Kaixiang

Definition at line 29 of file TRestMessenger.h.

Inheritance diagram for TRestMessenger:
TRestMetadata

Data Structures

struct  messagepool_t
 

Public Member Functions

 ClassDefOverride (TRestMessenger, 1)
 
virtual std::string ConsumeMessage ()
 
virtual bool IsConnected ()
 
void PrintMetadata () override
 Implemented it in the derived metadata class to print out specific metadata information. More...
 
virtual void SendMessage (std::string message="")
 
virtual std::vector< std::string > ShowMessagePool ()
 
 TRestMessenger (int token, std::string mode="TwoWay")
 

Protected Types

enum  CommMode { MessagePool_Host , MessagePool_Client , MessagePool_TwoWay }
 

Protected Member Functions

virtual void AddPool (std::string message)
 
virtual void InitFromConfigFile () override
 To make settings from rml file. This method must be implemented in the derived class. More...
 
virtual void Initialize () override
 Making default settings. More...
 
bool lock (messagepool_t *pool, int timeoutMs=1000)
 
bool unlock (messagepool_t *pool, int timeoutMs=1000)
 

Protected Attributes

CommMode fMode
 
std::string fPoolSource
 
std::string fPoolToken
 
TRestRunfRun
 

Private Attributes

messagepool_tfMessagePool
 
int fShmId
 

Member Enumeration Documentation

◆ CommMode

enum TRestMessenger::CommMode
protected

Definition at line 71 of file TRestMessenger.h.

Constructor & Destructor Documentation

◆ TRestMessenger() [1/2]

TRestMessenger::TRestMessenger ( )

Definition at line 88 of file TRestMessenger.cxx.

◆ TRestMessenger() [2/2]

TRestMessenger::TRestMessenger ( int  token,
std::string  mode = "TwoWay" 
)

Definition at line 100 of file TRestMessenger.cxx.

◆ ~TRestMessenger()

TRestMessenger::~TRestMessenger ( )

Definition at line 90 of file TRestMessenger.cxx.

Member Function Documentation

◆ AddPool()

void TRestMessenger::AddPool ( std::string  message)
protectedvirtual

Definition at line 234 of file TRestMessenger.cxx.

◆ ConsumeMessage()

string TRestMessenger::ConsumeMessage ( )
virtual

Definition at line 318 of file TRestMessenger.cxx.

◆ InitFromConfigFile()

void TRestMessenger::InitFromConfigFile ( )
overrideprotectedvirtual

To make settings from rml file. This method must be implemented in the derived class.

Reimplemented from TRestMetadata.

Definition at line 119 of file TRestMessenger.cxx.

◆ Initialize()

void TRestMessenger::Initialize ( )
overrideprotectedvirtual

Making default settings.

Reimplemented from TRestMetadata.

Definition at line 107 of file TRestMessenger.cxx.

◆ IsConnected()

virtual bool TRestMessenger::IsConnected ( )
inlinevirtual

Definition at line 90 of file TRestMessenger.h.

◆ lock()

bool TRestMessenger::lock ( messagepool_t pool,
int  timeoutMs = 1000 
)
protected

Definition at line 203 of file TRestMessenger.cxx.

◆ PrintMetadata()

void TRestMessenger::PrintMetadata ( )
overridevirtual

Implemented it in the derived metadata class to print out specific metadata information.

Prints metadata content on screen. Usually overloaded by the derived metadata class.

Reimplemented from TRestMetadata.

Definition at line 351 of file TRestMessenger.cxx.

◆ SendMessage()

void TRestMessenger::SendMessage ( std::string  message = "")
virtual

Definition at line 267 of file TRestMessenger.cxx.

◆ ShowMessagePool()

vector< string > TRestMessenger::ShowMessagePool ( )
virtual

Definition at line 292 of file TRestMessenger.cxx.

◆ unlock()

bool TRestMessenger::unlock ( messagepool_t pool,
int  timeoutMs = 1000 
)
protected

Definition at line 218 of file TRestMessenger.cxx.

Field Documentation

◆ fMessagePool

messagepool_t* TRestMessenger::fMessagePool
private

Definition at line 68 of file TRestMessenger.h.

◆ fMode

CommMode TRestMessenger::fMode
protected

Definition at line 75 of file TRestMessenger.h.

◆ fPoolSource

std::string TRestMessenger::fPoolSource
protected

Definition at line 77 of file TRestMessenger.h.

◆ fPoolToken

std::string TRestMessenger::fPoolToken
protected

Definition at line 76 of file TRestMessenger.h.

◆ fRun

TRestRun* TRestMessenger::fRun
protected

Definition at line 73 of file TRestMessenger.h.

◆ fShmId

int TRestMessenger::fShmId
private

Definition at line 67 of file TRestMessenger.h.


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