Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JDistributer.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <iomanip>
4 #include <vector>
5 
6 #include "JDAQ/JDAQTimeslice.hh"
7 #include "JDAQ/JDAQEvent.hh"
9 
10 #include "JDAQ/JDAQTags.hh"
13 #include "JLang/JSinglePointer.hh"
14 
15 #include "Jeep/JParser.hh"
16 #include "Jeep/JMessage.hh"
17 
18 
19 /**
20  * \file
21  *
22  * Example program to distribute data through control host.
23  * \author gmaggi
24  */
25 int main(int argc, char* argv[])
26 {
27  using namespace std;
28  using namespace JPP;
29 
30  string hostname;
31  vector<JHostname> destinations;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Example program to test receiving of objects from ControlHost server.");
37 
38  zap['H'] = make_field(hostname) = "localhost";
39  zap['D'] = make_field(destinations) ;
40  zap['d'] = make_field(debug) = 1;
41 
42  zap(argc, argv);
43  }
44  catch(const exception &error) {
45  FATAL(error.what() << endl);
46  }
47 
48  using namespace KM3NETDAQ;
49 
50  typedef JDAQEvent data_type;
51 
52  if (destinations.empty()) {
53  FATAL("Destination is empty" << endl);
54  }
55 
56 
57  typedef JSinglePointer<JControlHostObjectOutput<data_type> > pointerHostObject;
58 
60 
61  for (vector<JHostname>::iterator i = destinations.begin(); !destinations.empty(); ) {
62 
63  DEBUG("connection " << *i << ' ' << flush);
64 
65  try {
66 
67  output.push_back(new JControlHostObjectOutput<data_type>(*i));
68 
69  i = destinations.erase(i);
70 
71  DEBUG("succeeded");
72  }
73  catch(const exception& error) {
74  ++i;
75  DEBUG("failed");
76  }
77  DEBUG(endl);
78 
79  if (i == destinations.end()) {
80  sleep(1);
81  i = destinations.begin();
82  }
83  }
84 
85  vector<pointerHostObject>::iterator out= output.begin();
86 
87  try {
88 
89  JControlHostObjectIterator<data_type> in(hostname);
90 
91  while (in.hasNext()) {
92 
93  data_type* p = in.next();
94 
95  DEBUG("I got data " << endl);
96 
97  try {
98  (*out)->put(*p);
99  ++out;
100  }
101  catch(const exception& error) {
102  ERROR(error.what() << endl);
103  out = output.erase(out);
104  }
105 
106  if (out == output.end()) {
107  out = output.begin();
108  }
109  }
110  }
111  catch(const exception& error) {
112  ERROR(error.what() << endl);
113  }
114 }
Utility class to parse command line options.
Definition: JParser.hh:1410
#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
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:65
Utility class to parse command line options.
Fixed parameters for KM3NeT DAQ.
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60
int main(int argc, char *argv[])
Definition: Main.cpp:15