Jpp  15.0.1-rc.2-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
27 namespace po = boost::program_options;
28 
29 int main(int argc, char* argv[])
30 {
31  std::string filename;
32  unsigned int port = 0;
33 
34  po::options_description desc("Options");
35  desc.add_options()
36  ("help,h", "Print this help and exit.")
37  ("dumpfile,d",
38  po::value<std::string>(&filename)->required(),
39  "Set the name of the data file to send back to DQ or CLBSwissKnife.")
40  ("port,p",
41  po::value<unsigned int>(&port)->required(),
42  "Set the UDP port to send the data through");
43 
44  try
45  {
46  po::variables_map vm;
47  po::store(
48  po::command_line_parser(argc, argv).options(desc).run(),
49  vm);
50 
51  if (vm.count("help"))
52  {
53  std::cout << desc << std::endl;
54  return EXIT_SUCCESS;
55  }
56 
57  po::notify(vm);
58  }
59  catch (const po::error& e)
60  {
61  std::cerr << "CLBReplay: Error: " << e.what() << '\n'
62  << desc << std::endl;
63  return EXIT_FAILURE;
64  }
65  catch (const std::runtime_error& e)
66  {
67  std::cerr << "CLBReplay: Error: " << e.what() << '\n'
68  << desc << std::endl;
69  return EXIT_FAILURE;
70  }
71 
72  std::ifstream input_file(filename.c_str());
73  boost::asio::ip::udp::udp::endpoint endpoint(
74  boost::asio::ip::address::from_string("127.0.0.1"),
75  port);
76 
77  boost::asio::io_service service;
78  boost::asio::ip::udp::socket sock(service, boost::asio::ip::udp::udp::v4());
79 
80  char buffer[10000];
81 
82  while (input_file && input_file.peek() != EOF)
83  {
84  unsigned int datagram_size = 0;
85  input_file.read((char*) &datagram_size, sizeof(datagram_size));
86 
87  input_file.read(buffer, datagram_size);
88 
89  sock.send_to(boost::asio::buffer(buffer, datagram_size), endpoint);
90  // wait 1ms to give to the DAQ tool the time to complete the read-out
91  usleep(1000);
92  }
93 
94  std::cout << "File finished\n";
95 
96  return EXIT_SUCCESS;
97 }
int main(int argc, char *argv[])
Definition: Main.cc:15
then usage $script[port]< option > nPossible options
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.