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

Example program to distribute data through control host. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "JDAQ/JDAQTimeslice.hh"
#include "JDAQ/JDAQEvent.hh"
#include "JDAQ/JDAQSummaryslice.hh"
#include "JDAQ/JDAQTags.hh"
#include "JNet/JControlHostObjectIterator.hh"
#include "JNet/JControlHostObjectOutput.hh"
#include "JLang/JSinglePointer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

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

Detailed Description

Example program to distribute data through control host.

Author
gmaggi

Definition in file JDistributer.cc.

Function Documentation

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

Definition at line 25 of file JDistributer.cc.

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
#define FATAL(A)
Definition: JMessage.hh:65
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:60