Jpp  17.3.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
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/JDate.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

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 
67  JControlHost::Throw(true);
68 
69  try {
70 
71  JControlHost in (source);
72  JControlHost out(target);
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::high_resolution_clock::time_point start_time = std::chrono::high_resolution_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 = (std::chrono::high_resolution_clock::now() - start_time) / std::chrono::milliseconds(1);
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::high_resolution_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 }
ControlHost prefix.
Definition: JPrefix.hh:31
Utility class to parse command line options.
Definition: JParser.hh:1517
Target.
Definition: JHead.hh:298
ControlHost class.
Auxiliary class for trigger mask.
version
Definition: JEditTuneHV.sh:5
#define STATUS(A)
Definition: JMessage.hh:63
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
Definition: JParser.hh:83
int getSize() const
Get size.
Definition: JPrefix.hh:62
Subscription list.
then usage $script[port]< option > nPossible stop
static const JDAQTriggerMask TRIGGER_MASK_ON
Trigger mask on;.
static JDateAndTime getDateAndTime
Function object to get current date and time.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
Byte array binary input.
Definition: JByteArrayIO.hh:25
#define NOTICE(A)
Definition: JMessage.hh:64
Auxiliary class for any subscription.
#define ERROR(A)
Definition: JMessage.hh:66
then awk string
bool hasTriggerMask(const JDAQTriggerMask &mask) const
Has trigger bit pattern.
JSubscriptionList & add(const JSubscription &subscription)
Add subscription.
Exception for ControlHost.
Definition: JException.hh:468
Auxiliary class for all subscription.
Definition: JControlHost.hh:97
const JTag & getTag() const
Get tag.
Definition: JTag.hh:86
#define FATAL(A)
Definition: JMessage.hh:67
static const JNET::JTag IO_EVENT
Definition: JDAQTags.hh:66
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62