42{
43 int dq_port = 4000;
44 unsigned int hit_rate = 10;
45
46 std::string dq_address;
47
48 std::string input_filename("");
49 std::string configuration_filename("");
50
51 unsigned int deltaTS = 100;
52
53 unsigned int MTU = 1500;
54
55 unsigned int run_number = 24;
56
57 po::options_description desc("Options");
58 desc.add_options()
59 ("help,h", "Print this help and exit.")
60 ("port,p",
61 po::value<int>(&dq_port)->required(),
62 "Set the port to send data trough.")
63 ("address,a",
64 po::value<std::string>(&dq_address)->required(),
65 "Set the IP address to send data to.")
66 ("timeslice,t",
67 po::value<unsigned int>(&deltaTS)->default_value(deltaTS),
68 "Set the value of the time slice duration in milliseconds.")
69 ("hitrate,r",
70 po::value<unsigned int>(&hit_rate)->default_value(hit_rate),
71 "Set the desired hit rate in kHz.")
72 ("runnnumber,n",
73 po::value<unsigned int>(&run_number)->default_value(run_number),
74 "Set the run number.")
75 ("mtu,m",
76 po::value<unsigned int>(&MTU)->default_value(MTU),
77 "Set the Maximum Transfer Unit (MTU), i.e. the maximum UDP packet size.")
78 ("conf,c",
79 po::value<std::string>(&configuration_filename)->default_value(configuration_filename),
80 "Provide a file with the set of DOM ID to simulate. It must be in the form \"1 2 3 5 6 11\".");
81
82 try {
83 po::variables_map vm;
84 po::store(
85 po::command_line_parser(argc, argv).options(desc).run(),
86 vm);
87
88 if (vm.count("help")) {
89 std::cout << desc << std::endl;
90 return EXIT_SUCCESS;
91 }
92
93 po::notify(vm);
94 } catch (const po::error& e) {
95 std::cerr << "CLBsimu: Error: " << e.what() << '\n'
96 << desc << std::endl;
97 return EXIT_FAILURE;
98 } catch (const std::runtime_error& e) {
99 std::cerr << "CLBsimu: Error: " << e.what() << '\n'
100 << desc << std::endl;
101 return EXIT_FAILURE;
102 }
103
105
106 if (range.empty()) {
107 std::cerr << "FATAL: No DOM ID range available. Exiting\n";
108 return EXIT_FAILURE;
109 }
110
111 std::cout << "Program UP!\n";
112 std::cout << "here is the configuration:\n";
119
120 std::cout << "DOM IDs:\n";
121
122 for (unsigned int i = 0; i < range.size(); ++i) {
123 std::cout << range[i] << ' ';
124 }
125 std::cout << '\n';
126
127 FrameGenerator generator(range, deltaTS, run_number, MTU, hit_rate);
128
130
131 boost::asio::io_service service;
132
133 boost::asio::ip::udp::socket sock(service, boost::asio::ip::udp::udp::v4());
134
135 boost::asio::ip::udp::udp::resolver resolver(service);
136
137 boost::asio::ip::udp::udp::resolver::query query(
138 boost::asio::ip::udp::udp::v4(),
139 dq_address,
140 boost::lexical_cast<std::string>(dq_port));
141
142 boost::asio::ip::udp::udp::endpoint const destination = *resolver.resolve(query);
143
144 while (true) {
145 for (unsigned int i = 0; i < range.size(); i++) {
146 generator.getNext(data);
147
148 sock.send_to(boost::asio::buffer(data), destination);
149 }
150 }
151}
DOMRange_t createDOMRange(const std::string &filename="")