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;
32 std::string file_name;
34 po::options_description desc(
"b2hlt_file2rb FILE-NAME RING-BUFFER-NAME SHM-NAME SHM-ID");
36 (
"help,h",
"Print this help message")
37 (
"ring-buffer-name,r", po::value<std::string>(&ringBufferName)->required(),
"name of the ring buffer")
38 (
"file-name,f", po::value<std::string>(&file_name)->required(),
"file name to write to")
39 (
"shm-name,n", po::value<std::string>(&shmName)->required(),
"name of the shm for flow output")
40 (
"shm-id,i", po::value<unsigned int>(&shmID)->required(),
"id in the shm for flow output")
41 (
"raw", po::bool_switch(&raw)->default_value(
false),
"send and receive raw data instead of event buffers")
42 (
"repeat", po::bool_switch(&repeat)->default_value(
false),
"repeat after the file is finished");
45 po::positional_options_description p;
46 p.add(
"file-name", 1).add(
"ring-buffer-name", 1).add(
"shm-name", 1).add(
"shm-id", 1);
50 po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
51 }
catch (std::exception& e) {
55 if (vm.count(
"help")) {
56 std::cout << desc << std::endl;
62 }
catch (std::exception& e) {
68 RFFlowStat flow((
char*)shmName.c_str(), shmID, ringBuffer);
69 int* buffer =
new int[MAXEVTSIZE];
76 bool terminate =
false;
78 if (not file.open(file_name, raw,
"r")) {
79 B2ERROR(
"Can not open file");
83 while (mainLoop.isRunning() and not terminate) {
86 size = file.get_wordbuf(buffer, MAXEVTSIZE);
88 size = file.get(
reinterpret_cast<char*
>(buffer), MAXEVTSIZE);
93 file.open(file_name, raw,
"r");
96 B2RESULT(
"Reached end of file");
99 }
else if (size < 0) {
100 if (mainLoop.isRunning()) {
101 B2ERROR(
"Error in receiving the event! Aborting.");
106 B2ASSERT(
"Size is negative! This should be handled above. Not good!", size > 0);
110 EvtMessage message(
reinterpret_cast<char*
>(buffer));
111 if (message.type() == MSG_TERMINATE) {
112 B2RESULT(
"Having received terminate message");
118 flow.log(size *
sizeof(
int));
121 const int returnValue = mainLoop.writeToRingBufferWaiting(ringBuffer, buffer, size);
123 if (returnValue <= 0) {
124 if (mainLoop.isRunning()) {
125 B2ERROR(
"Writing to the ring buffer failed!");
130 B2ASSERT(
"Written size is negative! This should be handled above. Not good!", returnValue > 0);
134 if (nevt % 5000 == 0) {
135 B2RESULT(
"b2hlt_file2rb event number: " << nevt);
139 B2RESULT(
"Program terminated.");