forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDCSDataGeneratorSpec.h
More file actions
304 lines (270 loc) · 11.1 KB
/
DCSDataGeneratorSpec.h
File metadata and controls
304 lines (270 loc) · 11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef O2_DCS_DATAGENERATOR_H
#define O2_DCS_DATAGENERATOR_H
/// @file DataGeneratorSpec.h
/// @brief Dummy data generator
#include <unistd.h>
#include <TRandom.h>
#include <TDatime.h>
#include <TStopwatch.h>
#include "DetectorsDCS/DataPointIdentifier.h"
#include "DetectorsDCS/DataPointValue.h"
#include "DetectorsDCS/DataPointCompositeObject.h"
#include "DetectorsDCS/DeliveryType.h"
#include "Framework/DeviceSpec.h"
#include "Framework/ConfigParamRegistry.h"
#include "Framework/ControlService.h"
#include "Framework/WorkflowSpec.h"
#include "Framework/Task.h"
#include "Framework/Logger.h"
using namespace o2::framework;
namespace o2
{
namespace dcs
{
class DCSDataGenerator : public o2::framework::Task
{
using DPID = o2::dcs::DataPointIdentifier;
using DPVAL = o2::dcs::DataPointValue;
using DPCOM = o2::dcs::DataPointCompositeObject;
public:
void init(o2::framework::InitContext& ic) final
{
mMaxTF = ic.options().get<int64_t>("max-timeframes");
LOG(INFO) << "mMaxTF = " << mMaxTF;
DPID dpidtmp;
// chars
std::string dpAliaschar = "TestChar_0";
DPID::FILL(dpidtmp, dpAliaschar, mtypechar);
mDPIDvectFull.push_back(dpidtmp);
mNumDPsFull++;
mNumDPscharFull++;
// ints
for (int i = 0; i < 50000; i++) {
std::string dpAliasint = "TestInt_" + std::to_string(i);
DPID::FILL(dpidtmp, dpAliasint, mtypeint);
mDPIDvectFull.push_back(dpidtmp);
mNumDPsFull++;
mNumDPsintFull++;
if (i < 100) {
mDPIDvectDelta.push_back(dpidtmp);
mNumDPsDelta++;
mNumDPsintDelta++;
}
}
// doubles
for (int i = 0; i < 4; i++) {
std::string dpAliasdouble = "TestDouble_" + std::to_string(i);
DPID::FILL(dpidtmp, dpAliasdouble, mtypedouble);
mDPIDvectFull.push_back(dpidtmp);
mNumDPsFull++;
mNumDPsdoubleFull++;
}
// strings
std::string dpAliasstring0 = "TestString_0";
DPID::FILL(dpidtmp, dpAliasstring0, mtypestring);
mDPIDvectFull.push_back(dpidtmp);
mNumDPsFull++;
mNumDPsstringFull++;
LOG(INFO) << "Number of DCS data points: " << mNumDPsFull << " (full map); " << mNumDPsDelta << " (delta map)";
}
void run(o2::framework::ProcessingContext& pc) final
{
uint64_t tfid;
for (auto& input : pc.inputs()) {
tfid = header::get<o2::framework::DataProcessingHeader*>(input.header)->startTime;
LOG(DEBUG) << "tfid = " << tfid;
if (tfid >= mMaxTF) {
LOG(INFO) << "Data generator reached TF " << tfid << ", stopping";
pc.services().get<o2::framework::ControlService>().endOfStream();
pc.services().get<o2::framework::ControlService>().readyToQuit(o2::framework::QuitRequest::Me);
}
break; // we break because one input is enough to get the TF ID
}
LOG(DEBUG) << "TF: " << tfid << " --> building binary blob...";
uint16_t flags = 0;
uint16_t milliseconds = 0;
TDatime currentTime;
uint32_t seconds = currentTime.Get();
uint64_t payload[7];
memset(payload, 0, sizeof(uint64_t) * 7);
payload[0] = (uint64_t)tfid + 33; // adding 33 to have visible chars and strings
DPVAL valchar(flags, milliseconds + tfid * 10, seconds + tfid, payload, mtypechar);
DPVAL valint(flags, milliseconds + tfid * 10, seconds + tfid, payload, mtypeint);
DPVAL valdouble(flags, milliseconds + tfid * 10, seconds + tfid, payload, mtypedouble);
DPVAL valstring(flags, milliseconds + tfid * 10, seconds + tfid, payload, mtypestring);
LOG(DEBUG) << "Value used for char DPs:";
LOG(DEBUG) << valchar << " --> " << (char)valchar.payload_pt1;
LOG(DEBUG) << "Value used for int DPs:";
LOG(DEBUG) << valint << " --> " << (int)valint.payload_pt1;
LOG(DEBUG) << "Value used for double DPs:";
LOG(DEBUG) << valdouble << " --> " << (double)valdouble.payload_pt1;
char tt[56];
memcpy(&tt[0], &valstring.payload_pt1, 56);
LOG(DEBUG) << "Value used for string DPs:";
LOG(DEBUG) << valstring << " --> " << tt;
// full map (all DPs)
mBuildingBinaryBlock.Start(mFirstTF);
std::vector<DPCOM> dpcomVectFull;
for (int i = 0; i < mNumDPscharFull; i++) {
dpcomVectFull.emplace_back(mDPIDvectFull[i], valchar);
}
for (int i = 0; i < mNumDPsintFull; i++) {
dpcomVectFull.emplace_back(mDPIDvectFull[mNumDPscharFull + i], valint);
}
for (int i = 0; i < mNumDPsdoubleFull; i++) {
dpcomVectFull.emplace_back(mDPIDvectFull[mNumDPscharFull + mNumDPsintFull + i], valdouble);
}
for (int i = 0; i < mNumDPsstringFull; i++) {
dpcomVectFull.emplace_back(mDPIDvectFull[mNumDPscharFull + mNumDPsintFull + mNumDPsdoubleFull + i], valstring);
}
// delta map (only DPs that changed)
mDeltaBuildingBinaryBlock.Start(mFirstTF);
std::vector<DPCOM> dpcomVectDelta;
for (int i = 0; i < mNumDPscharDelta; i++) {
dpcomVectDelta.emplace_back(mDPIDvectDelta[i], valchar);
}
for (int i = 0; i < mNumDPsintDelta; i++) {
dpcomVectDelta.emplace_back(mDPIDvectDelta[mNumDPscharDelta + i], valint);
}
for (int i = 0; i < mNumDPsdoubleDelta; i++) {
dpcomVectDelta.emplace_back(mDPIDvectDelta[mNumDPscharDelta + mNumDPsintDelta + i], valdouble);
}
for (int i = 0; i < mNumDPsstringDelta; i++) {
dpcomVectDelta.emplace_back(mDPIDvectDelta[mNumDPscharDelta + mNumDPsintDelta + mNumDPsdoubleDelta + i],
valstring);
}
// Full map
auto svect = dpcomVectFull.size();
LOG(DEBUG) << "dpcomVectFull has size " << svect;
for (int i = 0; i < svect; i++) {
LOG(DEBUG) << "i = " << i << ", DPCOM = " << dpcomVectFull[i];
}
std::vector<char> buff(mNumDPsFull * sizeof(DPCOM));
char* dptr = buff.data();
for (int i = 0; i < svect; i++) {
memcpy(dptr + i * sizeof(DPCOM), &dpcomVectFull[i], sizeof(DPCOM));
}
auto sbuff = buff.size();
LOG(DEBUG) << "size of output buffer = " << sbuff;
mBuildingBinaryBlock.Stop();
LOG(DEBUG) << "TF: " << tfid << " --> ...binary blob prepared: realTime = "
<< mBuildingBinaryBlock.RealTime() << ", cpuTime = "
<< mBuildingBinaryBlock.CpuTime();
LOG(DEBUG) << "TF: " << tfid << " --> sending snapshot...";
mSnapshotSending.Start(mFirstTF);
pc.outputs().snapshot(Output{"DCS", "DATAPOINTS", 0, Lifetime::Timeframe}, buff.data(), sbuff);
mSnapshotSending.Stop();
LOG(DEBUG) << "TF: " << tfid << " --> ...snapshot sent: realTime = " << mSnapshotSending.RealTime()
<< ", cpuTime = " << mSnapshotSending.CpuTime();
// Delta map
auto svectDelta = dpcomVectDelta.size();
LOG(DEBUG) << "dpcomVectDelta has size " << svect;
for (int i = 0; i < svectDelta; i++) {
LOG(DEBUG) << "i = " << i << ", DPCOM = " << dpcomVectDelta[i];
}
std::vector<char> buffDelta(mNumDPsDelta * sizeof(DPCOM));
char* dptrDelta = buffDelta.data();
for (int i = 0; i < svectDelta; i++) {
memcpy(dptrDelta + i * sizeof(DPCOM), &dpcomVectDelta[i], sizeof(DPCOM));
}
auto sbuffDelta = buffDelta.size();
LOG(DEBUG) << "size of output (delta) buffer = " << sbuffDelta;
mDeltaBuildingBinaryBlock.Stop();
LOG(DEBUG) << "TF: " << tfid << " --> ...binary (delta) blob prepared: realTime = "
<< mDeltaBuildingBinaryBlock.RealTime() << ", cpuTime = " << mDeltaBuildingBinaryBlock.CpuTime();
LOG(DEBUG) << "TF: " << tfid << " --> sending (delta) snapshot...";
mDeltaSnapshotSending.Start(mFirstTF);
pc.outputs().snapshot(Output{"DCS", "DATAPOINTSdelta", 0, Lifetime::Timeframe}, buffDelta.data(), sbuffDelta);
mDeltaSnapshotSending.Stop();
LOG(DEBUG) << "TF: " << tfid << " --> ...snapshot (delta) sent: realTime = "
<< mDeltaSnapshotSending.RealTime() << ", cpuTime = "
<< mDeltaSnapshotSending.CpuTime();
/*
LOG(INFO) << "Reading back";
DPCOM dptmp;
for (int i = 0; i < svect; i++) {
memcpy(&dptmp, dptr + i * sizeof(DPCOM), sizeof(DPCOM));
LOG(DEBUG) << "Check: Reading from generator: i = " << i << ", DPCOM = " << dptmp;
}
*/
/*
auto& tmpDPmap = pc.outputs().make<std::unordered_map<DPID, DPVAL>>(o2::framework::OutputRef{"output", 0});
tmpDPmap[mcharVar] = valchar;
tmpDPmap[mintVar0] = valint;
tmpDPmap[mintVar1] = valint;
tmpDPmap[mintVar2] = valint;
tmpDPmap[mdoubleVar0] = valdouble;
tmpDPmap[mdoubleVar1] = valdouble;
tmpDPmap[mdoubleVar2] = valdouble;
if (tfid % 3 == 0)
tmpDPmap[mdoubleVar3] = valdouble; // to test the case when a DP is not updated, we skip some updates
tmpDPmap[mstringVar0] = valstring;
*/
mFirstTF = false;
mTFs++;
}
void endOfStream(o2::framework::EndOfStreamContext& ec) final
{
LOG(INFO) << "number of processed TF: " << mTFs;
LOG(INFO) << " --> time to prepare binary blob: realTime = "
<< mBuildingBinaryBlock.RealTime() / mTFs << ", cpuTime = "
<< mBuildingBinaryBlock.CpuTime() / mTFs;
LOG(INFO) << " --> time to send snapshot: realTime = "
<< mSnapshotSending.RealTime() / mTFs << ", cpuTime = "
<< mSnapshotSending.CpuTime() / mTFs;
LOG(INFO) << " --> time to prepare binary blob: realTime = "
<< mDeltaBuildingBinaryBlock.RealTime() / mTFs << ", cpuTime = "
<< mDeltaBuildingBinaryBlock.CpuTime() / mTFs;
LOG(INFO) << " --> time to send snapshot: realTime = "
<< mDeltaSnapshotSending.RealTime() / mTFs << ", cpuTime = "
<< mDeltaSnapshotSending.CpuTime() / mTFs;
}
private:
uint64_t mMaxTF = 1;
uint64_t mNumDPsFull = 0;
uint64_t mNumDPscharFull = 0;
uint64_t mNumDPsintFull = 0;
uint64_t mNumDPsdoubleFull = 0;
uint64_t mNumDPsstringFull = 0;
uint64_t mNumDPsDelta = 0;
uint64_t mNumDPscharDelta = 0;
uint64_t mNumDPsintDelta = 0;
uint64_t mNumDPsdoubleDelta = 0;
uint64_t mNumDPsstringDelta = 0;
std::vector<DPID> mDPIDvectFull; // for full map
std::vector<DPID> mDPIDvectDelta; // for delta map (containing only DPs that changed)
DeliveryType mtypechar = RAW_CHAR;
DeliveryType mtypeint = RAW_INT;
DeliveryType mtypedouble = RAW_DOUBLE;
DeliveryType mtypestring = RAW_STRING;
TStopwatch mBuildingBinaryBlock;
TStopwatch mDeltaBuildingBinaryBlock;
TStopwatch mSnapshotSending;
TStopwatch mDeltaSnapshotSending;
bool mFirstTF = true;
uint64_t mTFs = 0;
};
} // namespace dcs
namespace framework
{
DataProcessorSpec getDCSDataGeneratorSpec()
{
return DataProcessorSpec{
"dcs-data-generator",
Inputs{},
Outputs{{{"outputDCS"}, "DCS", "DATAPOINTS"}, {{"outputDCSdelta"}, "DCS", "DATAPOINTSdelta"}},
AlgorithmSpec{adaptFromTask<o2::dcs::DCSDataGenerator>()},
Options{{"max-timeframes", VariantType::Int64, 99999999999ll, {"max TimeFrames to generate"}}}};
}
} // namespace framework
} // namespace o2
#endif