#include #include #include #include #include #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" #include "Jeep/JTimekeeper.hh" #include "JSystem/JTime.hh" #include "JNet/JControlHost.hh" /** * \file * * Auxiliary program to receive messages from ControlHost server. * * The option -H \[: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 received. * \author mdejong */ int main(int argc, const char *argv[]) { using namespace std; string hostname; set tagList; set TagList; double rate_Hz; int numberOfEvents; int debug; try { JParser<> zap("Auxiliary program to receive messages from ControlHost server."); zap['H'] = make_field(hostname) = "localhost"; zap['t'] = make_field(tagList); zap['T'] = make_field(TagList); zap['R'] = make_field(rate_Hz); zap['n'] = make_field(numberOfEvents) = numeric_limits::max(); zap['d'] = make_field(debug) = 3; zap['t'] = JPARSER::initialised(); zap['T'] = JPARSER::initialised(); zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (tagList.empty() && TagList.empty()) FATAL("No tags specified."); using namespace JPP; JControlHost::Throw(true); try { JControlHost in(hostname); { JSubscriptionList buffer; for (set::const_iterator i = tagList.begin(); i != tagList.end(); ++i) { buffer.add(JSubscriptionAny(*i)); } for (set::const_iterator i = TagList.begin(); i != TagList.end(); ++i) { buffer.add(JSubscriptionAll(*i)); } DEBUG("Subscription: " << buffer.toString() << endl); in.Subscribe(buffer); in.SendMeAlways(); } JTimekeeper timer((long long int) (1.0e6 / rate_Hz)); JPrefix prefix; vector buffer; int all = 0; int few = 0; long long int t0 = 0; for (int i = 1; i <= numberOfEvents; ++i) { in.WaitHead(prefix); if (i == 1) { timer.reset(); t0 = getLocalTime(); } buffer.resize(prefix.getSize()); in.GetFullData(buffer.data(), buffer.size()); if (TagList.find(prefix) != TagList.end()) { ++all; } if (tagList.find(prefix) != tagList.end()) { ++few; } if (i%1000 == 0) { const long long int t1 = getLocalTime(); DEBUG("Time [us] " << setw(10) << t1 - t0 << endl); DEBUG(" [us] " << setw(10) << timer.getDelay() / i << endl); DEBUG("Count all " << setw(10) << all << endl); DEBUG("Count few " << setw(10) << few << endl); } timer.wait(); } } catch(const JControlHostException& error) { ERROR(error << endl); } }