Program name: CLBReplay.
Description: This program provide a way to send back to one of the DAQ tools the data contained in DQ or CLBSK dump data, via UDP. The program must run on the same computer where the DAQ tool is running.
Use $ CLBReplay -h for a detailed help.
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
93 usleep(sleep_time);
94 }
95
96 std::cout << "File finished\n";
97
98 return EXIT_SUCCESS;
99}