Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Functions
clb_simu.cpp File Reference
#include <iostream>
#include "frame_generator.hh"
#include <unistd.h>
#include <string>
#include <fstream>
#include <boost/program_options.hpp>
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>

Go to the source code of this file.

Macros

#define cool_print(a)   { std::cout << #a" = " << a << std::endl; }
 

Functions

DOMRange_t createDOMRange (const std::string &filename="")
 
int main (int argc, char *argv[])
 

Macro Definition Documentation

#define cool_print (   a)    { std::cout << #a" = " << a << std::endl; }
Author
cpellegrino

Definition at line 17 of file clb_simu.cpp.

Function Documentation

DOMRange_t createDOMRange ( const std::string &  filename = "")

Definition at line 19 of file clb_simu.cpp.

20 {
22  if (filename.empty()) {
23  range.push_back(9);
24  range.push_back(11);
25  range.push_back(23);
26  range.push_back(12);
27  range.push_back(8);
28  } else {
29  std::ifstream config(filename.c_str());
30  while (config) {
31  int dom_id = -1;
32  config >> dom_id;
33  if (dom_id >= 0) {
34  range.push_back(dom_id);
35  }
36  }
37  }
38  return range;
39 }
uint32_t dom_id(frame_idx_t idx)
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
int main ( int  argc,
char *  argv[] 
)

Definition at line 41 of file clb_simu.cpp.

42 {
43  int dq_port = 4000;
44  unsigned int hit_rate = 10; // kHz
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 
104  DOMRange_t range = createDOMRange(configuration_filename);
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";
113  cool_print(dq_address);
114  cool_print(dq_port);
115  cool_print(deltaTS);
116  cool_print(MTU);
117  cool_print(run_number);
118  cool_print(hit_rate);
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 
129  raw_data_t data;
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 }
#define cool_print(a)
Definition: clb_simu.cpp:17
then usage $script[port]< option > nPossible options
void store(const std::string &file_name, const JDetector &detector)
Store detector to output file.
z range($ZMAX-$ZMIN)< $MINIMAL_DZ." fi fi typeset -Z 4 STRING typeset -Z 2 FLOOR JPlot1D -f $
DOMRange_t createDOMRange(const std::string &filename="")
Definition: clb_simu.cpp:19