Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
clb_replay.cpp
Go to the documentation of this file.
1/**
2
3 Program name: CLBReplay
4
5 Description:
6 This program provide a way to send back to one of the DAQ tools
7 the data contained in DQ or CLBSK dump data, via UDP.
8 The program must run on the same computer where the DAQ tool is running.
9
10 Use
11 $ CLBReplay -h
12 for a detailed help.
13
14 E-mail: carmelo.pellegrino@bo.infn.it
15 Date: 9 April 2015
16
17 \author Carmelo Pellegrino
18*/
19
20#include <iostream>
21#include <boost/program_options.hpp>
22#include <boost/asio.hpp>
23#include <fstream>
24#include <string>
25
26
27namespace po = boost::program_options;
28
29int main(int argc, char* argv[])
30{
31 std::string filename;
32 unsigned int port = 0;
33 unsigned int sleep_time;
34
35 po::options_description desc("Options");
36 desc.add_options()
37 ("help,h", "Print this help and exit.")
38 ("dumpfile,d",
39 po::value<std::string>(&filename)->required(),
40 "Set the name of the data file to send back to DQ or CLBSwissKnife.")
41 ("port,p",
42 po::value<unsigned int>(&port)->required(),
43 "Set the UDP port to send the data through")
44 ("sleep,s",po::value<unsigned int>(&sleep_time)->default_value(1000),"sleep time between sending data packets (in microseconds)");
45
46 try
47 {
48 po::variables_map vm;
49 po::store(
50 po::command_line_parser(argc, argv).options(desc).run(),
51 vm);
52
53 if (vm.count("help"))
54 {
55 std::cout << desc << std::endl;
56 return EXIT_SUCCESS;
57 }
58
59 po::notify(vm);
60 }
61 catch (const po::error& e)
62 {
63 std::cerr << "CLBReplay: Error: " << e.what() << '\n'
64 << desc << std::endl;
65 return EXIT_FAILURE;
66 }
67 catch (const std::runtime_error& e)
68 {
69 std::cerr << "CLBReplay: Error: " << e.what() << '\n'
70 << desc << std::endl;
71 return EXIT_FAILURE;
72 }
73
74 std::ifstream input_file(filename.c_str());
75 boost::asio::ip::udp::udp::endpoint endpoint(
76 boost::asio::ip::address::from_string("127.0.0.1"),
77 port);
78
79 boost::asio::io_service service;
80 boost::asio::ip::udp::socket sock(service, boost::asio::ip::udp::udp::v4());
81
82 char buffer[10000];
83
84 while (input_file && input_file.peek() != EOF)
85 {
86 unsigned int datagram_size = 0;
87 input_file.read((char*) &datagram_size, sizeof(datagram_size));
88
89 input_file.read(buffer, datagram_size);
90
91 sock.send_to(boost::asio::buffer(buffer, datagram_size), endpoint);
92 // wait xx ms to give to the DAQ tool the time to complete the read-out
93 usleep(sleep_time);
94 }
95
96 std::cout << "File finished\n";
97
98 return EXIT_SUCCESS;
99}
int main(int argc, char *argv[])
Program name: CLBReplay.