Jpp  17.3.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JEventGenerator.cc
Go to the documentation of this file.
1 #include <string>
2 #include <iostream>
3 #include <sstream>
4 #include <iomanip>
5 #include <vector>
6 #include <limits>
7 
8 #include "Jeep/JParser.hh"
9 #include "Jeep/JProperties.hh"
10 #include "Jeep/JTimer.hh"
11 #include "Jeep/JTimekeeper.hh"
12 #include "JLang/JSharedPointer.hh"
13 #include "JNet/JControlHost.hh"
15 #include "JDAQ/JDAQEventIO.hh"
18 #include "JSupport/JSupport.hh"
21 #include "JIO/JByteArrayIO.hh"
22 
23 
24 namespace KM3NETDAQ {
25 
26 
27  using namespace JPP;
28 
29 
30  /**
31  * Runcontrol client to simulate data filter(s).
32  * In state running, this application will send events to the data writer.
33  */
35  public JDAQClient
36  {
37  public:
38  /**
39  * Constructor.
40  *
41  * \param name name of client
42  * \param server name of command message server
43  * \param logger pointer to logger
44  * \param level debug level
45  */
47  const std::string& server,
48  JLogger* logger,
49  const int level) :
50  JDAQClient(name, server, logger, level),
51  datawriter()
52  {
53  replaceEvent(RC_CMD, RC_EVTGENERATOR, ev_configure);
54 
55  JControlHost::Throw(true);
56  }
57 
58 
59  virtual void actionConfigure(int length, const char* buffer)
60  {
61  using namespace std;
62  using namespace JPP;
63 
64  inputFile.clear();
65 
66  JString destination;
67 
68  JProperties properties(JEquationParameters("=", ";", "", ""));
69 
70  properties["datawriter"] = destination = "localhost";
71  properties["inputFile"] = inputFile;
72  properties["eventRate_Hz"] = eventRate_Hz = 1.0;
73 
74  properties.read(string(buffer, length));
75 
76  destination = destination.trim();
77 
78  try {
79  datawriter.reset(new JControlHost(destination));
80  }
81  catch(const JControlHostException& exception) {
82  JErrorStream(logger) << exception;
83  }
84 
85  if (eventRate_Hz > 0.0)
86  setClockInterval((long long int) (1.0e6 / eventRate_Hz));
87  else
88  setClockInterval(0ULL);
89 
90  parameters = getTriggerParameters(inputFile);
91 
92  JDebugStream(logger) << "Event interval time " << getClockInterval() << " us";
93  }
94 
95 
96  virtual void actionReset(int length, const char* buffer)
97  {
98  JDebugStream(logger) << "actionReset()";
99 
100  inputFile.rewind();
101 
102  datawriter.reset();
103  }
104 
105 
106  virtual void actionQuit(int length, const char* buffer)
107  {}
108 
109 
110  virtual void actionStart(int length, const char* buffer)
111  {
112  using namespace std;
113 
114  numberOfEvents = 0;
115  numberOfBytes = 0;
116 
117  ostringstream os;
118 
119  // Test 1
120  /*
121  os << " abcdefg " << getRunNumber() << ' ' << parameters;
122  */
123  //
124  os << getRunNumber() << ' ' << parameters;
125  //
126  datawriter->PutFullString(IO_TRIGGER_PARAMETERS, os.str());
127 
128  // Test 2
129  /*
130  os.str("");
131 
132  os << getRunNumber() << ' ' << JTriggerParameters();
133 
134  datawriter->PutFullString(IO_TRIGGER_PARAMETERS, os.str());
135  */
136  timer.reset();
137  }
138 
139 
140  virtual void actionStop(int length, const char* buffer)
141  {
142  JDebugStream(logger) << "actionStop()";
143 
144  if (timer.usec_wall > 0) JNoticeStream(logger) << "I/O [MB/s] " << numberOfBytes / timer.usec_wall;
145  if (numberOfEvents > 0) JNoticeStream(logger) << "Delay/event [ms] " << getClockDelay() / numberOfEvents / 1000;
146  }
147 
148 
149  virtual void actionRunning()
150  {
151  //JDebugStream(logger) << "actionRunning()";
152 
153  using namespace JPP;
154 
155  static JIO::JByteArrayWriter out;
156 
157  if (datawriter.is_valid()) {
158 
159  if (!inputFile.hasNext()) {
160  inputFile.rewind();
161  }
162 
163  if (inputFile.hasNext()) {
164 
165  timer.start();
166 
167  JDAQEvent* event = inputFile.next();
168 
169  event->setRunNumber(getRunNumber());
170 
171  out.clear();
172 
173  out << *event;
174 
175  try {
176 
177  datawriter->PutFullData(IO_EVENT, out.data(), out.size());
178 
179  numberOfEvents += 1;
180  numberOfBytes += out.size();
181  }
182  catch(const JControlHostException& exception) {
183  JErrorStream(logger) << exception;
184  }
185 
186  timer.stop();
187  }
188  }
189 
190  //JDebugStream(logger) << "actionRunning() return";
191  }
192 
193 
194  private:
196 
199 
200  Long64_t numberOfEvents;
201  double eventRate_Hz;
202 
203  JEEP::JTimer timer; // timer for I/O measurement
204  long long int numberOfBytes; // total number of bytes
205  };
206 }
207 
208 
209 /**
210  * \file
211  *
212  * Program for real-time simulation of data.
213  * \author mdejong
214  */
215 int main(int argc, char* argv[])
216 {
217  using namespace std;
218 
219  string server;
220  string logger;
221  string client_name;
222  bool use_cout;
223  int debug;
224 
225  try {
226 
227  JParser<> zap("Program for real-time simulation of data.");
228 
229  zap['H'] = make_field(server) = "localhost";
230  zap['M'] = make_field(logger) = "localhost";
231  zap['u'] = make_field(client_name) = "%";
232  zap['c'] = make_field(use_cout);
233  zap['d'] = make_field(debug) = 3;
234 
235  zap(argc, argv);
236  }
237  catch(const exception &error) {
238  FATAL(error.what() << endl);
239  }
240 
241 
242  using namespace KM3NETDAQ;
243  using namespace JPP;
244 
245  JLogger* out = NULL;
246 
247  if (use_cout)
248  out = new JStreamLogger(cout);
249  else
250  out = new JControlHostLogger(logger);
251 
252  JEventGenerator enigma(getProcessName(client_name, argv[0]), server, out, debug);
253 
254  enigma.enter();
255  enigma.run();
256 }
Utility class to parse command line options.
Definition: JParser.hh:1517
bool read(const JEquation &equation)
Read equation.
Definition: JProperties.hh:677
Data structure for all trigger parameters.
int main(int argc, char *argv[])
Definition: Main.cc:15
ROOT TTree parameter settings of various packages.
Wrapper class around STL string class.
Definition: JString.hh:27
virtual void actionStart(int length, const char *buffer)
ControlHost class.
JSharedPointer< JControlHost > datawriter
std::string getProcessName(const std::string &name, const std::string &process)
Get process name of run control client.
Message logging based on std::ostream.
JSUPPORT::JMultipleFileScanner< KM3NETDAQ::JDAQEvent > inputFile
Interface for logging messages.
Definition: JLogger.hh:22
Message logging based on ControlHost.
then echo Enter input within $TIMEOUT_S seconds echo n User name
Definition: JCookie.sh:42
Utility class to parse parameter values.
Definition: JProperties.hh:496
*fatal Wrong number of arguments esac JCookie sh typeset Z DETECTOR typeset Z SOURCE_RUN typeset Z TARGET_RUN set_variable PARAMETERS_FILE $WORKDIR parameters
Definition: diff-Tuna.sh:38
Simple data structure to support I/O of equations (see class JLANG::JEquation).
static const JNET::JTag IO_TRIGGER_PARAMETERS
Definition: JDAQTags.hh:68
void run()
Run as run control client following command messages via JNET::JControlHost.
Definition: JDAQClient.hh:662
Utility class to parse parameter values.
JTRIGGER::JTriggerParameters parameters
Scheduling of actions via fixed latency intervals.
The template JSharedPointer class can be used to share a pointer to an object.
virtual void actionStop(int length, const char *buffer)
event< ev_daq > ev_configure
Definition: JDAQCHSM.chsm:175
virtual void actionReset(int length, const char *buffer)
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1993
int getRunNumber(const std::string &file_name)
Get run number for given file name of data taking run.
Runcontrol client to simulate data filter(s).
Auxiliary class for CPU timing and usage.
Definition: JTimer.hh:32
then awk string
Level specific message streamers.
Exception for ControlHost.
Definition: JException.hh:468
static const JNET::JTag RC_EVTGENERATOR
Definition: JDAQTags.hh:48
#define FATAL(A)
Definition: JMessage.hh:67
Scanning of objects from multiple files according a format that follows from the extension of each fi...
JEventGenerator(const std::string &name, const std::string &server, JLogger *logger, const int level)
Constructor.
Control unit client base class.
Definition: JDAQClient.hh:273
General purpose class for object reading from a list of file names.
Utility class to parse command line options.
virtual bool enter(const JArgs &args)
Enter the state machine.
Definition: JDAQClient.hh:364
static const JNET::JTag RC_CMD
Definition: JDAQTags.hh:44
static const JNET::JTag IO_EVENT
Definition: JDAQTags.hh:66
Byte array binary output.
KM3NeT DAQ constants, bit handling, etc.
virtual void actionQuit(int length, const char *buffer)
virtual void actionConfigure(int length, const char *buffer)
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
static void Throw(const bool option)
Enable/disable throw option.
Definition: JThrow.hh:37
virtual void actionRunning()
This method is repeatedly called when this client machine is in state Running and the clock interval ...
int debug
debug level
JTriggerCounter_t next()
Increment trigger counter.