Jpp
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JNet
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/JDAQTimesliceIO.hh
"
7
#include "
JDAQ/JDAQEventIO.hh
"
8
#include "
JDAQ/JDAQSummarysliceIO.hh
"
9
10
#include "
JDAQ/JDAQTags.hh
"
11
#include "
JNet/JControlHostObjectIterator.hh
"
12
#include "
JNet/JControlHostObjectOutput.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
using namespace
KM3NETDAQ;
30
31
string
hostname;
32
vector<JHostname>
destinations;
33
int
debug
;
34
35
try
{
36
37
JParser<>
zap(
"Example program to distribute data through control host."
);
38
39
zap[
'H'
] =
make_field
(hostname) =
"localhost"
;
40
zap[
'D'
] =
make_field
(destinations);
41
zap[
'd'
] =
make_field
(
debug
) = 1;
42
43
zap(argc, argv);
44
}
45
catch
(
const
exception &error) {
46
FATAL
(error.what() << endl);
47
}
48
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_t;
58
59
vector<pointerHostObject_t>
output;
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);
// okay; remove destination
70
71
DEBUG
(
"succeeded."
);
72
}
73
catch
(
const
exception& error) {
74
++i;
// skip; maintain destination
75
DEBUG
(
"failed."
);
76
}
77
DEBUG
(endl);
78
79
if
(i == destinations.end()) {
// round robin
80
sleep(1);
81
i = destinations.begin();
82
}
83
}
84
85
vector<pointerHostObject_t>::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;
// okay; maintain destination
100
}
101
catch
(
const
exception& error) {
102
ERROR
(error.what() << endl);
103
out = output.erase(out);
// error; remove destination
104
}
105
106
if
(out == output.end()) {
// round robin
107
out = output.begin();
108
}
109
}
110
}
111
catch
(
const
exception& error) {
112
ERROR
(error.what() << endl);
113
}
114
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1493
JLANG::JAbstractObjectIterator::next
virtual const pointer_type & next()
Get next element.
Definition:
JAbstractObjectIterator.hh:71
in
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition:
JSirene.sh:45
std::vector
Definition:
JSTDTypes.hh:12
JLANG::JSinglePointer
The template JSinglePointer class can be used to hold a pointer to an object.
Definition:
JSinglePointer.hh:24
JControlHostObjectIterator.hh
KM3NETDAQ::JDAQEvent
DAQ Event.
Definition:
JDAQEvent.hh:30
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1954
JControlHostObjectOutput.hh
ERROR
#define ERROR(A)
Definition:
JMessage.hh:66
JDAQSummarysliceIO.hh
debug
int debug
debug level
Definition:
JSirene.cc:61
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JNET::JControlHostObjectIterator
Object iteration through ControlHost.
Definition:
JControlHostObjectIterator.hh:31
JParser.hh
Utility class to parse command line options.
JNET::JControlHostObjectOutput
Implemenation of object output through ControlHost.
Definition:
JControlHostObjectOutput.hh:36
JLANG::JAbstractObjectIterator::hasNext
virtual bool hasNext()
Check availability of next element.
Definition:
JAbstractObjectIterator.hh:56
JDAQTags.hh
Fixed parameters andd ControlHost tags for KM3NeT DAQ.
JDAQEventIO.hh
JSinglePointer.hh
JDAQTimesliceIO.hh
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
main
int main(int argc, char *argv[])
Definition:
Main.cpp:15
Generated by
1.8.5