9#include <framework/pcore/RingBuffer.h>
10#include <daq/rfarm/event/hltsocket/HLTMainLoop.h>
11#include <framework/logging/Logger.h>
12#include <framework/pcore/EvtMessage.h>
14#include <boost/program_options.hpp>
17#define MAXEVTSIZE 80000000
18#define RBUFSIZE 10000000
22namespace po = boost::program_options;
24int main(
int argc,
char* argv[])
26 std::vector<std::string> inputRingBufferNames;
27 std::vector<std::string> outputRingBufferNames;
29 po::options_description desc(
"b2hlt_rb2rb");
31 (
"help,h",
"Print this help message")
32 (
"input-ring-buffer-name,r", po::value<std::vector<std::string>>(&inputRingBufferNames)->required(),
33 "name of the input ring buffers")
34 (
"output-ring-buffer-name,r", po::value<std::vector<std::string>>(&outputRingBufferNames)->required(),
35 "name of the output ring buffers");
39 po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
40 }
catch (std::exception& e) {
44 if (vm.count(
"help")) {
45 std::cout << desc << std::endl;
51 }
catch (std::exception& e) {
55 if (outputRingBufferNames.empty() or inputRingBufferNames.empty()) {
56 B2FATAL(
"Need at least one output and input ring buffer!");
60 std::vector<RingBuffer*> inputRingBuffers;
61 for (
const std::string& bufferName : inputRingBufferNames) {
62 inputRingBuffers.push_back(
new RingBuffer(bufferName.c_str(), RBUFSIZE));
63 inputRingBuffers.back()->dump_db();
66 std::vector<RingBuffer*> outputRingBuffers;
67 for (
const std::string& bufferName : outputRingBufferNames) {
68 outputRingBuffers.push_back(
new RingBuffer(bufferName.c_str(), RBUFSIZE));
69 outputRingBuffers.back()->dump_db();
74 int* buffer =
new int[MAXEVTSIZE];
77 auto inputRingBuffer = inputRingBuffers.begin();
78 auto outputRingBuffer = outputRingBuffers.begin();
80 while (mainLoop.isRunning()) {
82 const int size = mainLoop.readFromRingBufferWaiting(*inputRingBuffer, buffer);
85 if (mainLoop.isRunning()) {
86 B2ERROR(
"Writing to the ring buffer failed!");
91 B2ASSERT(
"Size is negative! This should be handled above. Not good!", size > 0);
94 const int returnValue = mainLoop.writeToRingBufferWaiting(*outputRingBuffer, buffer, size);
96 if (returnValue <= 0) {
97 if (mainLoop.isRunning()) {
98 B2ERROR(
"Writing to the ring buffer failed!");
103 B2ASSERT(
"Written size is negative! This should be handled above. Not good!", returnValue > 0);
107 if (nevt % 5000 == 0) {
108 B2RESULT(
"b2hlt_rb2socket event number: " << nevt);
112 if (inputRingBuffer == inputRingBuffers.end()) {
113 inputRingBuffer = inputRingBuffers.begin();
116 if (outputRingBuffer == outputRingBuffers.end()) {
117 outputRingBuffer = outputRingBuffers.begin();
121 B2RESULT(
"Program terminated.");
Class to manage a Ring Buffer placed in an IPC shared memory.
Abstract base class for different kinds of events.