Jpp 21.0.0-rc.1-88-g0130508c4
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#include <memory>
8
10
11#include "JNet/JControlHost.hh"
12#include "JDAQ/JDAQEventIO.hh"
15#include "JSupport/JSupport.hh"
18#include "JIO/JByteArrayIO.hh"
19#include "Jeep/JParser.hh"
20#include "Jeep/JProperties.hh"
21#include "Jeep/JTimer.hh"
22#include "Jeep/JTimekeeper.hh"
23
24
25namespace KM3NETDAQ {
26
27
28 using namespace JPP;
29
30
31 /**
32 * Runcontrol client to simulate data filter(s).
33 * In state running, this application will send events to the data writer.
34 */
36 public JDAQClient
37 {
38 public:
39 /**
40 * Constructor.
41 *
42 * \param name name of client
43 * \param server name of command message server
44 * \param logger pointer to logger
45 * \param level debug level
46 */
47 JEventGenerator(const std::string& name,
48 const std::string& server,
50 const int level) :
51 JDAQClient(name, server, logger, level),
52 datawriter()
53 {
55
57 }
58
59
60 virtual void actionConfigure(int length, const char* buffer)
61 {
62 using namespace std;
63 using namespace JPP;
64
65 inputFile.clear();
66
67 JString destination;
68
69 JProperties properties(JEquationParameters("=", ";", "", ""));
70
71 properties["datawriter"] = destination = "localhost";
72 properties["inputFile"] = inputFile;
73 properties["eventRate_Hz"] = eventRate_Hz = 1.0;
74
75 properties.read(string(buffer, length));
76
77 destination = destination.trim();
78
79 try {
80 datawriter.reset(new JControlHost(destination));
81 }
82 catch(const JControlHostException& exception) {
83 JErrorStream(logger) << exception;
84 }
85
86 if (eventRate_Hz > 0.0)
87 setClockInterval((long long int) (1.0e6 / eventRate_Hz));
88 else
89 setClockInterval(0ULL);
90
92
93 JDebugStream(logger) << "Event interval time " << getClockInterval() << " us";
94 }
95
96
97 virtual void actionReset(int length, const char* buffer)
98 {
99 JDebugStream(logger) << "actionReset()";
100
102
103 datawriter.reset();
104 }
105
106
107 virtual void actionQuit(int length, const char* buffer)
108 {}
109
110
111 virtual void actionStart(int length, const char* buffer)
112 {
113 using namespace std;
114
115 numberOfEvents = 0;
116 numberOfBytes = 0;
117
118 ostringstream os;
119
120 // Test 1
121 /*
122 os << " abcdefg " << getRunNumber() << ' ' << parameters;
123 */
124 //
125 os << getRunNumber() << ' ' << parameters;
126 //
127 datawriter->PutFullString(IO_TRIGGER_PARAMETERS, os.str());
128
129 // Test 2
130 /*
131 os.str("");
132
133 os << getRunNumber() << ' ' << JTriggerParameters();
134
135 datawriter->PutFullString(IO_TRIGGER_PARAMETERS, os.str());
136 */
137 timer.reset();
138 }
139
140
141 virtual void actionStop(int length, const char* buffer)
142 {
143 JDebugStream(logger) << "actionStop()";
144
145 if (timer.usec_wall > 0) JNoticeStream(logger) << "I/O [MB/s] " << numberOfBytes / timer.usec_wall;
146 if (numberOfEvents > 0) JNoticeStream(logger) << "Delay/event [ms] " << getClockDelay() / numberOfEvents / 1000;
147 }
148
149
150 virtual void actionRunning()
151 {
152 //JDebugStream(logger) << "actionRunning()";
153
154 using namespace JPP;
155
156 static JIO::JByteArrayWriter out;
157
158 if (datawriter.get() != NULL) {
159
160 if (!inputFile.hasNext()) {
162 }
163
164 if (inputFile.hasNext()) {
165
166 timer.start();
167
168 JDAQEvent* event = inputFile.next();
169
170 event->setRunNumber(getRunNumber());
171
172 out.clear();
173
174 out << *event;
175
176 try {
177
178 datawriter->PutFullData(IO_EVENT, out.data(), out.size());
179
180 numberOfEvents += 1;
181 numberOfBytes += out.size();
182 }
183 catch(const JControlHostException& exception) {
184 JErrorStream(logger) << exception;
185 }
186
187 timer.stop();
188 }
189 }
190
191 //JDebugStream(logger) << "actionRunning() return";
192 }
193
194
195 private:
196 std::shared_ptr<JControlHost> datawriter;
197
200
203
204 JEEP::JTimer timer; // timer for I/O measurement
205 long long int numberOfBytes; // total number of bytes
206 };
207}
208
209
210/**
211 * \file
212 *
213 * Program for real-time simulation of data.
214 * \author mdejong
215 */
216int main(int argc, char* argv[])
217{
218 using namespace std;
219
220 string server;
221 string logger;
222 string client_name;
223 bool use_cout;
224 int debug;
225
226 try {
227
228 JParser<> zap("Program for real-time simulation of data.");
229
230 zap['H'] = make_field(server) = "localhost";
231 zap['M'] = make_field(logger) = "localhost";
232 zap['u'] = make_field(client_name) = "%";
233 zap['c'] = make_field(use_cout);
234 zap['d'] = make_field(debug) = 3;
235
236 zap(argc, argv);
237 }
238 catch(const exception &error) {
239 FATAL(error.what() << endl);
240 }
241
242
243 using namespace KM3NETDAQ;
244 using namespace JPP;
245
246 JLogger* out = NULL;
247
248 if (use_cout)
249 out = new JStreamLogger(cout);
250 else
251 out = new JControlHostLogger(logger);
252
253 JEventGenerator enigma(getProcessName(client_name, argv[0]), server, out, debug);
254
255 enigma.enter();
256 enigma.run();
257}
KM3NeT DAQ constants, bit handling, etc.
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
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:2140
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).
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:1697
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)
std::shared_ptr< JControlHost > datawriter
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
JEventGenerator(const std::string &name, const std::string &server, JLogger *logger, const int level)
Constructor.
int main()
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.