Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JGetData.cc File Reference

Auxiliary program to receive messages from ControlHost server. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <set>
#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 receive messages from 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 <rate [Hz]> corresponds to the rate at which messages will be received.

Author
mdejong

Definition in file JGetData.cc.

Function Documentation

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

Definition at line 24 of file JGetData.cc.

25 {
26  using namespace std;
27 
28  string hostname;
29  set<JNET::JTag> tagList;
30  set<JNET::JTag> TagList;
31  double rate_Hz;
32  int numberOfEvents;
33  int debug;
34 
35  try {
36 
37  JParser<> zap("Auxiliary program to receive messages from ControlHost server.");
38 
39  zap['H'] = make_field(hostname) = "localhost";
40  zap['t'] = make_field(tagList);
41  zap['T'] = make_field(TagList);
42  zap['R'] = make_field(rate_Hz);
43  zap['n'] = make_field(numberOfEvents) = numeric_limits<int>::max();
44  zap['d'] = make_field(debug) = 3;
45 
46  zap['t'] = JPARSER::initialised();
47  zap['T'] = JPARSER::initialised();
48 
49  zap(argc, argv);
50  }
51  catch(const exception &error) {
52  FATAL(error.what() << endl);
53  }
54 
55 
56  if (tagList.empty() && TagList.empty())
57  FATAL("No tags specified.");
58 
59  using namespace JPP;
60 
61  JControlHost::Throw(true);
62 
63  try {
64 
65  JControlHost in(hostname);
66 
67  {
68  JSubscriptionList buffer;
69 
70  for (set<JTag>::const_iterator i = tagList.begin(); i != tagList.end(); ++i) {
71  buffer.add(JSubscriptionAny(*i));
72  }
73 
74  for (set<JTag>::const_iterator i = TagList.begin(); i != TagList.end(); ++i) {
75  buffer.add(JSubscriptionAll(*i));
76  }
77 
78  DEBUG("Subscription: " << buffer.toString() << endl);
79 
80  in.Subscribe(buffer);
81  in.SendMeAlways();
82  }
83 
84  JTimekeeper timer((long long int) (1.0e6 / rate_Hz));
85 
86  JPrefix prefix;
87  vector<char> buffer;
88 
89  int all = 0;
90  int few = 0;
91 
92  long long int t0 = 0;
93 
94  for (int i = 1; i <= numberOfEvents; ++i) {
95 
96  in.WaitHead(prefix);
97 
98  if (i == 1) {
99 
100  timer.reset();
101 
102  t0 = getLocalTime();
103  }
104 
105  buffer.resize(prefix.getSize());
106 
107  in.GetFullData(buffer.data(), buffer.size());
108 
109  if (TagList.find(prefix) != TagList.end()) { ++all; }
110  if (tagList.find(prefix) != tagList.end()) { ++few; }
111 
112  if (i%1000 == 0) {
113 
114  const long long int t1 = getLocalTime();
115 
116  DEBUG("Time [us] " << setw(10) << t1 - t0 << endl);
117  DEBUG("<delay> [us] " << setw(10) << timer.getDelay() / i << endl);
118  DEBUG("Count all " << setw(10) << all << endl);
119  DEBUG("Count few " << setw(10) << few << endl);
120  }
121 
122  timer.wait();
123  }
124 
125  }
126  catch(const JControlHostException& error) {
127  ERROR(error << endl);
128  }
129 }
Utility class to parse command line options.
Definition: JParser.hh:1410
Empty structure for specification of parser element that is initialised (i.e.
Definition: JParser.hh:64
static const JLocalTime getLocalTime
Function object to get local time in micro seconds.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1836
#define ERROR(A)
Definition: JMessage.hh:64
int debug
debug level
Definition: JSirene.cc:59
#define FATAL(A)
Definition: JMessage.hh:65
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60