8#include <daq/rfarm/manager/RFFlowStat.h>
9#include <framework/pcore/RingBuffer.h>
10#include <daq/rfarm/event/hltsocket/HLTMainLoop.h>
11#include <daq/rfarm/event/hltsocket/HLTFile.h>
12#include <framework/logging/Logger.h>
13#include <framework/pcore/EvtMessage.h>
15#include <boost/program_options.hpp>
18#define MAXEVTSIZE 80000000
21namespace po = boost::program_options;
23int main(
int argc,
char* argv[])
25 std::string ringBufferName;
29 std::string file_name;
31 po::options_description desc(
"b2hlt_rb2socket RING-BUFFER-NAME FILE-NAME SHM-NAME SHM-ID");
33 (
"help,h",
"Print this help message")
34 (
"ring-buffer-name,r", po::value<std::string>(&ringBufferName)->required(),
"name of the ring buffer")
35 (
"file-name,f", po::value<std::string>(&file_name)->required(),
"file name to write to")
36 (
"shm-name,n", po::value<std::string>(&shmName)->required(),
"name of the shm for flow output")
37 (
"shm-id,i", po::value<unsigned int>(&shmID)->required(),
"id in the shm for flow output")
38 (
"raw", po::bool_switch(&raw)->default_value(
false),
"send and receive raw data instead of event buffers");
41 po::positional_options_description p;
42 p.add(
"ring-buffer-name", 1).add(
"file-name", 1).add(
"shm-name", 1).add(
"shm-id", 1);
46 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
47 }
catch (std::exception& e) {
51 if (vm.count(
"help")) {
52 std::cout << desc << std::endl;
58 }
catch (std::exception& e) {
64 RFFlowStat flow((
char*)shmName.c_str(), shmID, ringBuffer);
65 int* buffer =
new int[MAXEVTSIZE];
72 bool terminate =
false;
74 if (not file.open(file_name, raw,
"w")) {
75 B2ERROR(
"Can not open file");
79 while (mainLoop.isRunning() and not terminate) {
81 const int size = mainLoop.readFromRingBufferWaiting(ringBuffer, buffer);
84 if (mainLoop.isRunning()) {
85 B2ERROR(
"Writing to the ring buffer failed!");
90 B2ASSERT(
"Size is negative! This should be handled above. Not good!", size > 0);
93 flow.log(size *
sizeof(
int));
96 returnValue = file.put_wordbuf(buffer, size);
98 EvtMessage message(
reinterpret_cast<char*
>(buffer));
99 returnValue = file.put(message.buffer(), message.size());
101 if (message.type() == MSG_TERMINATE) {
102 B2RESULT(
"Having received terminate message");
106 if (returnValue <= 0) {
107 if (mainLoop.isRunning()) {
108 B2ERROR(
"Error in writing the event! Aborting.");
113 B2ASSERT(
"Written size is negative! This should be handled above. Not good!", returnValue > 0);
117 if (nevt % 5000 == 0) {
118 B2RESULT(
"b2hlt_rb2file event number: " << nevt);
122 B2RESULT(
"Program terminated.");
Class to manage streamed object.
Class to manage a Ring Buffer placed in an IPC shared memory.
Abstract base class for different kinds of events.