Jpp  master_rocky-43-ge265d140c
the software that should make you happy
Functions
JPutData.cc File Reference

Auxiliary program to send messages to ControlHost server. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "Jeep/JTimekeeper.hh"
#include "JSystem/JTime.hh"
#include "JNet/JControlHost.hh"

Go to the source code of this file.

Functions

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

Detailed Description

Auxiliary program to send messages to ControlHost server.

The option -H <hostname>[:port] correponds to the hostname and the port of the server, respectively. The options -t and -T correspond to the ControlHost tag(s) for free and all subscription, respectively. The option -R corresponds to the rate at which messages will be sent.

Author
mdejong

Definition in file JPutData.cc.

Function Documentation

◆ main()

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

Definition at line 23 of file JPutData.cc.

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 }
#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:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
Time keeper.
Definition: JTimekeeper.hh:34
Exception for ControlHost.
Definition: JException.hh:486
ControlHost class.
ControlHost tag.
Definition: JTag.hh:38
Utility class to parse command line options.
Definition: JParser.hh:1698
static const JTag DISPTAG_UNDEFINED(0)
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
static const JLocalTime getLocalTime
Function object to get local time in micro seconds.
Definition: JSTDTypes.hh:14