10 #include <daq/rfarm/manager/RFFlowStat.h>
11 #include <framework/pcore/RingBuffer.h>
12 #include <daq/rfarm/event/hltsocket/HLTMainLoop.h>
13 #include <daq/rfarm/event/hltsocket/HLTFile.h>
14 #include <framework/logging/Logger.h>
15 #include <framework/pcore/EvtMessage.h>
17 #include <boost/program_options.hpp>
20 #define MAXEVTSIZE 80000000
23 namespace po = boost::program_options;
25 int main(
int argc,
char* argv[])
27 std::string ringBufferName;
31 std::string file_name;
33 po::options_description desc(
"b2hlt_rb2socket RING-BUFFER-NAME FILE-NAME SHM-NAME SHM-ID");
35 (
"help,h",
"Print this help message")
36 (
"ring-buffer-name,r", po::value<std::string>(&ringBufferName)->required(),
"name of the ring buffer")
37 (
"file-name,f", po::value<std::string>(&file_name)->required(),
"file name to write to")
38 (
"shm-name,n", po::value<std::string>(&shmName)->required(),
"name of the shm for flow output")
39 (
"shm-id,i", po::value<unsigned int>(&shmID)->required(),
"id in the shm for flow output")
40 (
"raw", po::bool_switch(&raw)->default_value(
false),
"send and receive raw data instead of event buffers");
43 po::positional_options_description p;
44 p.add(
"ring-buffer-name", 1).add(
"file-name", 1).add(
"shm-name", 1).add(
"shm-id", 1);
48 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
49 }
catch (std::exception& e) {
53 if (vm.count(
"help")) {
54 std::cout << desc << std::endl;
60 }
catch (std::exception& e) {
66 RFFlowStat flow((
char*)shmName.c_str(), shmID, ringBuffer);
67 int* buffer =
new int[MAXEVTSIZE];
74 bool terminate =
false;
76 if (not file.open(file_name, raw,
"w")) {
77 B2ERROR(
"Can not open file");
81 while (mainLoop.isRunning() and not terminate) {
83 const int size = mainLoop.readFromRingBufferWaiting(ringBuffer, buffer);
86 if (mainLoop.isRunning()) {
87 B2ERROR(
"Writing to the ring buffer failed!");
92 B2ASSERT(
"Size is negative! This should be handled above. Not good!", size > 0);
95 flow.log(size *
sizeof(
int));
98 returnValue = file.put_wordbuf(buffer, size);
100 EvtMessage message(
reinterpret_cast<char*
>(buffer));
101 returnValue = file.put(message.buffer(), message.size());
103 if (message.type() == MSG_TERMINATE) {
104 B2RESULT(
"Having received terminate message");
108 if (returnValue <= 0) {
109 if (mainLoop.isRunning()) {
110 B2ERROR(
"Error in writing the event! Aborting.");
115 B2ASSERT(
"Written size is negative! This should be handled above. Not good!", returnValue > 0);
119 if (nevt % 5000 == 0) {
120 B2RESULT(
"b2hlt_rb2file event number: " << nevt);
124 B2RESULT(
"Program terminated.");