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;
30 std::string file_name;
32 po::options_description desc(
"b2hlt_file2rb FILE-NAME RING-BUFFER-NAME SHM-NAME SHM-ID");
34 (
"help,h",
"Print this help message")
35 (
"ring-buffer-name,r", po::value<std::string>(&ringBufferName)->required(),
"name of the ring buffer")
36 (
"file-name,f", po::value<std::string>(&file_name)->required(),
"file name to write to")
37 (
"shm-name,n", po::value<std::string>(&shmName)->required(),
"name of the shm for flow output")
38 (
"shm-id,i", po::value<unsigned int>(&shmID)->required(),
"id in the shm for flow output")
39 (
"raw", po::bool_switch(&raw)->default_value(
false),
"send and receive raw data instead of event buffers")
40 (
"repeat", po::bool_switch(&repeat)->default_value(
false),
"repeat after the file is finished");
43 po::positional_options_description p;
44 p.add(
"file-name", 1).add(
"ring-buffer-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,
"r")) {
77 B2ERROR(
"Can not open file");
81 while (mainLoop.isRunning() and not terminate) {
84 size = file.get_wordbuf(buffer, MAXEVTSIZE);
86 size = file.get(
reinterpret_cast<char*
>(buffer), MAXEVTSIZE);
91 file.open(file_name, raw,
"r");
94 B2RESULT(
"Reached end of file");
97 }
else if (size < 0) {
98 if (mainLoop.isRunning()) {
99 B2ERROR(
"Error in receiving the event! Aborting.");
104 B2ASSERT(
"Size is negative! This should be handled above. Not good!", size > 0);
108 EvtMessage message(
reinterpret_cast<char*
>(buffer));
109 if (message.type() == MSG_TERMINATE) {
110 B2RESULT(
"Having received terminate message");
116 flow.log(size *
sizeof(
int));
119 const int returnValue = mainLoop.writeToRingBufferWaiting(ringBuffer, buffer, size);
121 if (returnValue <= 0) {
122 if (mainLoop.isRunning()) {
123 B2ERROR(
"Writing to the ring buffer failed!");
128 B2ASSERT(
"Written size is negative! This should be handled above. Not good!", returnValue > 0);
132 if (nevt % 5000 == 0) {
133 B2RESULT(
"b2hlt_file2rb event number: " << nevt);
137 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.