Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JLigierMirror.cc File Reference

A tool to forward messages with the given tags from one ControlHost server (e.g. More...

#include <chrono>
#include <iostream>
#include <set>
#include <string>
#include "JNet/JControlHost.hh"
#include "JIO/JByteArrayIO.hh"
#include "JDAQ/JDAQTags.hh"
#include "JDAQ/JDAQPreambleIO.hh"
#include "JDAQ/JDAQEventHeaderIO.hh"
#include "JSystem/JDateAndTime.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, const char *argv[])
 

Detailed Description

A tool to forward messages with the given tags from one ControlHost server (e.g.

JLigier) to another.

The options -H <source>[:port] and -X <target>[:port] correspond to the host name and the port of the source and target server, respectively.
The options -t and -T correspond to the ControlHost tag(s) with the mode subscription "any" and subscription "all", respectively.

Author
tgal, mdejong

Definition in file JLigierMirror.cc.

Function Documentation

◆ main()

int main ( int argc,
const char * argv[] )

Definition at line 27 of file JLigierMirror.cc.

28{
29 using namespace std;
30 using namespace JPP;
31 using namespace KM3NETDAQ;
32
33 string source;
34 string target;
35 int report_interval; // in seconds
36 set<JNET::JTag> tagList;
37 set<JNET::JTag> TagList;
38 JDAQTriggerMask trigger_mask;
39 int debug;
40
41 try {
42
43 JParser<> zap("Program to forward messages from one ControlHost server to another.");
44
45 zap['H'] = make_field(source) = "localhost";
46 zap['X'] = make_field(target) = "localhost";
47 zap['t'] = make_field(tagList) = JPARSER::initialised();
48 zap['T'] = make_field(TagList) = JPARSER::initialised();
49 zap['@'] = make_field(trigger_mask) = TRIGGER_MASK_ON;
50 zap['i'] = make_field(report_interval) = 30;
51 zap['d'] = make_field(debug) = 2;
52
53 zap(argc, argv);
54 }
55 catch(const exception &error) {
56 FATAL(error.what() << endl);
57 }
58
59
60 if (tagList.empty() && TagList.empty()) {
61 FATAL("No tags specified.");
62 }
63
64 NOTICE("Forwarding messages from " << endl << " " << source << " -> " << target << endl);
65
66
68
69 try {
70
71 JControlHost in (source);
73
74 {
75 NOTICE("with the following tags: ");
76
77 JSubscriptionList buffer;
78
79 for (set<JTag>::const_iterator i = tagList.begin(); i != tagList.end(); ++i) {
80 buffer.add(JSubscriptionAny(*i));
81 NOTICE(*i << "(any) ");
82 }
83
84 for (set<JTag>::const_iterator i = TagList.begin(); i != TagList.end(); ++i) {
85 buffer.add(JSubscriptionAll(*i));
86 NOTICE(*i << "(all) ");
87 }
88
89 NOTICE(endl);
90
91 in.Subscribe(buffer);
92 in.SendMeAlways();
93 }
94
95
96 JPrefix prefix;
97 vector<char> buffer;
98 unsigned int message_count[] = { 0, 0 };
99 float milliseconds_passed;
100 std::chrono::steady_clock::time_point start_time = std::chrono::steady_clock::now();
101
102 for (const string stop("stop"); buffer.size() != stop.size() || string(buffer.data(), stop.size()) != stop; ) {
103
104 in.WaitHead(prefix);
105
106 buffer.resize(prefix.getSize());
107
108 in.GetFullData(buffer.data(), buffer.size());
109
110 message_count[0] += 1;
111
112 DEBUG(getDateAndTime() << ' ' << left << setw(8) << prefix.getTag() << ' ' << right << setw(8) << prefix.getSize() << endl);
113
114 bool dos = false;
115
116 if (prefix.getTag() == IO_EVENT) {
117
118 JDAQPreamble preamble;
119 Version_t version;
120 JDAQEventHeader header;
121
122 JByteArrayReader reader(buffer.data(), buffer.size());
123
124 reader >> preamble;
125 reader >> version;
126 reader >> header;
127
128 dos = header.hasTriggerMask(trigger_mask);
129
130 } else {
131
132 dos = true;
133 }
134
135 if (dos) {
136
137 message_count[1] += 1;
138
139 out.PutFullData(prefix.getTag(), buffer.data(), buffer.size());
140 }
141
142 milliseconds_passed = chrono::duration_cast<chrono::milliseconds>(std::chrono::steady_clock::now() - start_time).count();
143
144 if (milliseconds_passed > report_interval * 1e3) {
145
146 STATUS(getDateAndTime() << " : " << "Message rate: "
147 << message_count[0] / milliseconds_passed * 1e3 << " "
148 << message_count[1] / milliseconds_passed * 1e3 << " Hz" << endl);
149
150 start_time = std::chrono::steady_clock::now();
151
152 message_count[0] = 0;
153 message_count[1] = 0;
154 }
155 }
156 }
157 catch(const JControlHostException& error) {
158 ERROR(error << endl);
159 }
160}
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define NOTICE(A)
Definition JMessage.hh:64
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Byte array binary input.
Exception for ControlHost.
static void Throw(const bool option)
Definition JThrow.hh:37
ControlHost class.
ControlHost prefix.
Definition JPrefix.hh:33
int getSize() const
Get size.
Definition JPrefix.hh:62
Subscription list.
JSubscriptionList & add(const JSubscription &subscription)
Add subscription.
const JTag & getTag() const
Get tag.
Definition JTag.hh:86
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class for trigger mask.
bool hasTriggerMask(const JDAQTriggerMask &mask) const
Has trigger bit pattern.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static JDateAndTime getDateAndTime
Function object to get current date and time.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
static const JDAQTriggerMask TRIGGER_MASK_ON
Trigger mask on;.
static const JNET::JTag IO_EVENT
Definition JDAQTags.hh:88
Target.
Definition JHead.hh:300
Auxiliary class for all subscription.
Auxiliary class for any subscription.
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition JParser.hh:68