Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
clb_replay.cpp File Reference
#include <iostream>
#include <boost/program_options.hpp>
#include <boost/asio.hpp>
#include <fstream>
#include <string>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Program name: CLBReplay. More...
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

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.

E-mail: carme.nosp@m.lo.p.nosp@m.elleg.nosp@m.rino.nosp@m.@bo.i.nosp@m.nfn..nosp@m.it Date: 9 April 2015

Author
Carmelo Pellegrino

Definition at line 29 of file clb_replay.cpp.

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 }
then usage $script[port]< option > nPossible options
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.