Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "ConfigOption.h"
#include "PRadETChannel.h"
#include "et.h"
#include <csignal>
#include <thread>
#include <chrono>
#include <iostream>
#define PROGRESS_COUNT 10
using namespace std::chrono;
volatile std::sig_atomic_t gSignalStatus;
void signal_handler(int signal) {
gSignalStatus = signal;
}
int main(int argc, char* argv[]) try
{
// setup input arguments
ConfigOption conf_opt;
conf_opt.AddLongOpt(ConfigOption::help_message, "help");
conf_opt.AddOpt(ConfigOption::arg_require, 'h');
conf_opt.AddOpt(ConfigOption::arg_require, 'p');
conf_opt.AddOpt(ConfigOption::arg_require, 'f');
conf_opt.AddOpt(ConfigOption::arg_require, 'i');
conf_opt.SetDesc("usage: %0");
conf_opt.SetDesc('h', "host address of the ET system, default \"localhost\".");
conf_opt.SetDesc('p', "port to connect, default 11111.");
conf_opt.SetDesc('f', "memory mapped et file, default \"/tmp/et_feeder\".");
conf_opt.SetDesc('i', "interval in milliseconds to write data, default \"100\"");
if (!conf_opt.ParseArgs(argc, argv) || conf_opt.NbofArgs() != 0) {
std::cout << conf_opt.GetInstruction() << std::endl;
return -1;
}
std::string host = "localhost";
int port = 11111;
std::string etf = "/tmp/et_feeder";
int interval = 100;
for (auto &opt : conf_opt.GetOptions()) {
switch (opt.mark) {
case 'h':
host = opt.var.String();
break;
case 'c':
port = opt.var.Int();
break;
case 'f':
etf = opt.var.String();
break;
case 'i':
interval = opt.var.Int();
break;
default :
std::cout << conf_opt.GetInstruction() << std::endl;
return -1;
}
}
// attach to ET system
auto ch = new PRadETChannel(100*1024*1024);
ch->Open(host.c_str(), port, etf.c_str());
ch->NewStation("Data Catcher");
ch->AttachStation();
// install signal handler
std::signal(SIGINT, signal_handler);
int count = 0;
while (true) {
if (gSignalStatus == SIGINT) {
std::cout << "Received control-C, exiting..." << std::endl;
ch->ForceClose();
break;
}
system_clock::time_point start(system_clock::now());
system_clock::time_point next(start + std::chrono::milliseconds(interval));
std::cout << "Read " << ch->Read() << " events from ET." << "\r" << std::flush;
std::this_thread::sleep_until(next);
}
std::cout << "Read " << count << " events from ET." << std::endl;
return 0;
} catch (PRadException e) {
std::cerr << e.FailureType() << ": " << e.FailureDesc() << std::endl;
return -1;
} catch (...) {
std::cerr << "?unknown exception" << std::endl;
}