Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
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"
13#include "JNet/JControlHost.hh"
15#include "JDAQ/JDAQEventIO.hh"
18#include "JSupport/JSupport.hh"
21#include "JIO/JByteArrayIO.hh"
22
23
24namespace 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 */
46 JEventGenerator(const std::string& name,
47 const std::string& server,
49 const int level) :
50 JDAQClient(name, server, logger, level),
51 datawriter()
52 {
54
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
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
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()) {
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
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 */
215int 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}
KM3NeT DAQ constants, bit handling, etc.
int main(int argc, char *argv[])
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Scanning of objects from multiple files according a format that follows from the extension of each fi...
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Utility class to parse parameter values.
ROOT TTree parameter settings of various packages.
Scheduling of actions via fixed latency intervals.
int getRunNumber() const
Get run number.
Definition JDAQCHSM.hh:111
std::string name
Definition JDAQCHSM.hh:165
JDAQStateMachine::ev_configure_event ev_configure
Utility class to parse parameter values.
bool read(const JEquation &equation)
Read equation.
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
unsigned long long usec_wall
Definition JTimer.hh:238
void stop()
Stop timer.
Definition JTimer.hh:127
void reset()
Reset timer.
Definition JTimer.hh:93
void start()
Start timer.
Definition JTimer.hh:106
Byte array binary output.
void clear()
Clear buffer.
Exception for ControlHost.
Simple data structure to support I/O of equations (see class JLANG::JEquation).
The template JSharedPointer class can be used to share a pointer to an object.
Wrapper class around STL string class.
Definition JString.hh:29
JString & trim()
Trim string.
Definition JString.hh:229
static void Throw(const bool option)
Definition JThrow.hh:37
Message logging based on ControlHost.
Interface for logging messages.
Definition JLogger.hh:22
Message logging based on std::ostream.
ControlHost class.
Utility class to parse command line options.
Definition JParser.hh:1698
General purpose class for object reading from a list of file names.
virtual void rewind() override
Rewind.
virtual bool hasNext() override
Check availability of next element.
virtual const pointer_type & next() override
Get next element.
Data structure for all trigger parameters.
Control unit client base class.
JSharedPointer< JControlHost > server
message server
void replaceEvent(const JTag &oldTag, const JTag &newTag, JDAQEvent_t &event)
Replace tag of given event in event table.
void run()
Run as run control client following command messages via JNET::JControlHost.
JMessageLogger logger
message logger
virtual bool enter(const JArgs &args)
Enter the state machine.
Runcontrol client to simulate data filter(s).
virtual void actionQuit(int length, const char *buffer)
virtual void actionRunning()
This method is repeatedly called when this client machine is in state Running and the clock interval ...
virtual void actionStart(int length, const char *buffer)
virtual void actionReset(int length, const char *buffer)
JSUPPORT::JMultipleFileScanner< KM3NETDAQ::JDAQEvent > inputFile
virtual void actionStop(int length, const char *buffer)
virtual void actionConfigure(int length, const char *buffer)
JTRIGGER::JTriggerParameters parameters
JSharedPointer< JControlHost > datawriter
JEventGenerator(const std::string &name, const std::string &server, JLogger *logger, const int level)
Constructor.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
JTriggerParameters getTriggerParameters(const JMultipleFileScanner_t &file_list)
Get trigger parameters.
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39
static const JNET::JTag RC_EVTGENERATOR
Definition JDAQTags.hh:70
static const JNET::JTag IO_EVENT
Definition JDAQTags.hh:88
static const JNET::JTag RC_CMD
Definition JDAQTags.hh:66
std::string getProcessName(const std::string &name, const std::string &process)
Get process name of run control client.
static const JNET::JTag IO_TRIGGER_PARAMETERS
Definition JDAQTags.hh:90
Level specific message streamers.
void setClockInterval(const long long int interval_us)
Set interval time.
long long int getClockDelay() const
Get total delay time.
long long int getClockInterval() const
Get interval time.