Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JPutData.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <limits>
5
6#include "Jeep/JParser.hh"
7#include "Jeep/JMessage.hh"
8#include "Jeep/JTimekeeper.hh"
9#include "JSystem/JTime.hh"
10#include "JNet/JControlHost.hh"
11
12
13/**
14 * \file
15 *
16 * Auxiliary program to send messages to ControlHost server.
17 *
18 * The option <tt>-H <hostname>[:port]</tt> correponds to the hostname and the port of the server, respectively.
19 * The options <tt>-t</tt> and <tt>-T</tt> correspond to the ControlHost tag(s) for free and all subscription, respectively.
20 * The option <tt>-R</tt> corresponds to the rate at which messages will be sent.
21 * \author mdejong
22 */
23int main(int argc, const char *argv[])
24{
25 using namespace std;
26 using namespace JPP;
27
28 string hostname;
29 JTag tag;
30 JTag Tag;
31 double rate_Hz;
32 int numberOfEvents;
33 int size;
34 int debug;
35
36 try {
37
38 JParser<> zap("Auxiliary program to send messages to ControlHost server.");
39
40 zap['H'] = make_field(hostname) = "localhost";
41 zap['t'] = make_field(tag) = DISPTAG_UNDEFINED;
42 zap['T'] = make_field(Tag) = DISPTAG_UNDEFINED;
43 zap['R'] = make_field(rate_Hz);
44 zap['n'] = make_field(numberOfEvents) = numeric_limits<int>::max();
45 zap['s'] = make_field(size) = 1024;
46 zap['d'] = make_field(debug) = 3;
47
48 zap(argc, argv);
49 }
50 catch(const exception &error) {
51 FATAL(error.what() << endl);
52 }
53
54
55 if (tag == DISPTAG_UNDEFINED && Tag == DISPTAG_UNDEFINED) {
56 FATAL("No tags specified.");
57 }
58
59 JControlHost::Throw(true);
60
61 try {
62
63 JControlHost out(hostname);
64
65 JTimekeeper timer((long long int) (1.0e6 / rate_Hz));
66
67 vector<char> buffer(size);
68
69 for (int i = 0; i != size; ++i) {
70 buffer[i] = 'a' + (i%26);
71 }
72
73 int all = 0;
74 int few = 0;
75
76 timer.reset();
77
78 const long long int t0 = getLocalTime();
79
80 for (int i = 1; i <= numberOfEvents; ++i) {
81
82 if (Tag != DISPTAG_UNDEFINED) { out.PutFullData(Tag, buffer.data(), buffer.size()); ++all; }
83 if (tag != DISPTAG_UNDEFINED) { out.PutFullData(tag, buffer.data(), buffer.size()); ++few; }
84
85 if (i%100 == 0) {
86
87 const long long int t1 = getLocalTime();
88
89 DEBUG("Time [us] " << setw(10) << t1 - t0 << endl);
90 DEBUG("<delay> [us] " << setw(10) << timer.getDelay() / i << endl);
91 DEBUG("Count all " << setw(10) << all << endl);
92 DEBUG("Count few " << setw(10) << few << endl);
93 }
94
95 timer.wait();
96 }
97 }
98 catch(const JControlHostException& error) {
99 ERROR(error << endl);
100 }
101}
102
103
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, const char *argv[])
Definition JPutData.cc:23
System time information.
Scheduling of actions via fixed latency intervals.
Time keeper.
long long int getDelay() const
Get total delay time.
void wait() const
Wait until the number of time intervals has elapsed since the last call to the reset method.
void reset(const long long int t0)
Reset time.
Exception for ControlHost.
ControlHost class.
int PutFullData(const JTag &tag, const void *buffer, const long long int length)
Send data.
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).