-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDeliveryType.h
More file actions
405 lines (372 loc) · 10.8 KB
/
DeliveryType.h
File metadata and controls
405 lines (372 loc) · 10.8 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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// 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.
/*
* File: DeliveryType.h
* Author: John Lång (john.larry.lang@cern.ch)
*
* Created on 17 July 2015, 9:54
*/
#ifndef O2_DCS_DELIVERY_TYPE
#define O2_DCS_DELIVERY_TYPE
#include <string>
#include <bitset>
#include <stdexcept>
#include "DetectorsDCS/GenericFunctions.h"
namespace o2::dcs
{
/**
* <p>DeliveryType is a piece of meta-information used for deducing types of
* DPVAL payloads and DIM service description strings used with services
* providing data to ADAPOS. DPCOMs use the DeliveryType of DPIDs to infer
* the correct interpretation of payload data when being put into a
* <tt>std::ofstream</tt>. Also, ADAPOS Engine uses DeliveryTypes for DIM
* service subscription (and Load Generator for generating services).</p>
* <p>Every DeliveryType, except <tt>VOID</tt>, has a raw and DPVAL
* variant. A DIM service publishing payloads in DPVALs has a different
* format and binary layout than a DIM service publishing only raw data, so
* this distinction is critical to ADAPOS Engine.</p>
*
* @see ADAPRO::ADAPOS::DataPointCompositeObject
* @see ADAPRO::ADAPOS::DataPointIdentifier
* @see ADAPRO::ADAPOS::DataPointValue
*/
enum DeliveryType {
/**
* This DeliveryType is included only for testing and debugging
* when the payload of a DPVAL is not going to be accessed. Accessing
* the payload of a DPVAL with this DeliveryType results in a domain
* error.
*/
VOID = 0,
/**
* <tt>Binary</tt> is the general payload data type. This is the raw
* variant.
*/
RAW_BINARY = 64,
/**
* <tt>Binary</tt> is the general payload data type. This is the DPVAL
* variant.
*/
DPVAL_BINARY = 192,
/**
* <tt>Int</tt> stands for a 32-bit signed integer. This is the raw
* variant. The numerical value of <tt>RAW_INT</tt> corresponds with the
* WinCC constant <tt>DPEL_INT</tt>.
*/
RAW_INT = 21,
/**
* <tt>Int</tt> stands for a 32-bit signed integer. This is the DPVAL
* variant.
*/
DPVAL_INT = 149,
/**
* <tt>Uint</tt> stands for a 32-bit unsigned integer. This is the raw
* variant. The numerical value of <tt>RAW_UINT</tt> corresponds with
* the WinCC constant <tt>DPEL_UINT</tt>.
*/
RAW_UINT = 20,
/**
* <tt>Uint</tt> stands for a 32-bit insigned integer. This is the DPVAL
* variant.
*/
DPVAL_UINT = 148,
/**
* <tt>Double</tt> stands for IEEE 754 double precision floating point
* number (64 bit). This is the raw variant. The numerical value of
* <tt>RAW_INT</tt> corresponds with the WinCC constant
* <tt>DPEL_FLOAT</tt>.
*/
RAW_DOUBLE = 22,
/**
* <tt>Double</tt> stands for IEEE 754 double precision floating point
* number (64 bit). This is the DPVAL variant.
*/
DPVAL_DOUBLE = 150,
/**
* <tt>Bool</tt> stands for a boolean. This is the raw variant. The
* numerical value of <tt>RAW_BOOL</tt> corresponds with the WinCC
* constant <tt>DPEL_BOOL</tt>.
*/
RAW_FLOAT = 28,
/**
* <tt>Float</tt> stands for IEEE 754 single precision floating point
* number (64 bit). This is the raw variant. The numerical value of
* <tt>RAW_INT</tt> corresponds with the WinCC constant
* <tt>DPEL_FLOAT</tt>.
*/
DPVAL_FLOAT = 156,
/**
* <tt>Float</tt> stands for IEEE 754 single precision floating point
* number (64 bit). This is the DPVAL variant.
*/
RAW_BOOL = 23,
/**
* <tt>Bool</tt> stands for a boolean. This is the DPVAL variant.
*/
DPVAL_BOOL = 151,
/**
* <tt>Char</tt> stands for an ASCII character. This is the raw variant.
* The numerical value of <tt>RAW_CHAR</tt> corresponds with the WinCC
* constant <tt>DPEL_CHAR</tt>.
*/
RAW_CHAR = 19,
/**
* <tt>Char</tt> stands for an ASCII character. This is the raw variant.
*/
DPVAL_CHAR = 147,
/**
* <tt>String</tt> stands for a null-terminated array of ASCII
* characters. This is the raw variant. The numerical value of
* <tt>RAW_STRING</tt> corresponds with the WinCC constant
* <tt>DPEL_STRING</tt>.
*/
RAW_STRING = 25,
/**
* <tt>String</tt> stands for a null-terminated array of ASCII
* characters. This is the DPVAL variant.
*/
DPVAL_STRING = 153,
/**
* <tt>Time</tt> stands for two 32-bit (unsigned) integers containing
* the milliseconds and secodns of a UNIX timestamp. This is the raw
* variant. The numerical value of <tt>RAW_TIME</tt> corresponds with
* the WinCC constant <tt>DPEL_DYN_UINT</tt>.
*/
RAW_TIME = 4,
/**
* <tt>Time</tt> stands for two 32-bit (unsigned) integers containing
* the milliseconds and secodns of a UNIX timestamp. This is the DPVAL
* variant.
*/
DPVAL_TIME = 132
};
template <>
inline DeliveryType read(const std::string& str)
{
if (str == "Raw/Int") {
return RAW_INT;
} else if (str == "Raw/Uint") {
return RAW_UINT;
} else if (str == "Raw/Float") {
return RAW_FLOAT;
} else if (str == "Raw/Double") {
return RAW_DOUBLE;
} else if (str == "Raw/Bool") {
return RAW_BOOL;
} else if (str == "Raw/Char") {
return RAW_CHAR;
} else if (str == "Raw/String") {
return RAW_STRING;
} else if (str == "Raw/Binary") {
return RAW_BINARY;
} else if (str == "Raw/Time") {
return RAW_TIME;
} else if (str == "DPVAL/Int") {
return DPVAL_INT;
} else if (str == "DPVAL/Uint") {
return DPVAL_UINT;
} else if (str == "DPVAL/Float") {
return DPVAL_FLOAT;
} else if (str == "DPVAL/Double") {
return DPVAL_DOUBLE;
} else if (str == "DPVAL/Bool") {
return DPVAL_BOOL;
} else if (str == "DPVAL/Char") {
return DPVAL_CHAR;
} else if (str == "DPVAL/String") {
return DPVAL_STRING;
} else if (str == "DPVAL/Binary") {
return DPVAL_BINARY;
} else if (str == "DPVAL/Time") {
return DPVAL_TIME;
} else if (str == "Void") {
return VOID;
} else {
throw std::domain_error("\"" + str +
"\" doesn't represent a DeliveryType.");
}
}
template <>
inline std::string show(const DeliveryType type)
{
switch (type) {
case RAW_INT:
return "Raw/Int";
case RAW_UINT:
return "Raw/Uint";
case RAW_BOOL:
return "Raw/Bool";
case RAW_CHAR:
return "Raw/Char";
case RAW_FLOAT:
return "Raw/Float";
case RAW_DOUBLE:
return "Raw/Double";
case RAW_TIME:
return "Raw/Time";
case RAW_STRING:
return "Raw/String";
case RAW_BINARY:
return "Raw/Binary";
case DPVAL_INT:
return "DPVAL/Int";
case DPVAL_UINT:
return "DPVAL/Uint";
case DPVAL_BOOL:
return "DPVAL/Bool";
case DPVAL_CHAR:
return "DPVAL/Char";
case DPVAL_FLOAT:
return "DPVAL/Float";
case DPVAL_DOUBLE:
return "DPVAL/Double";
case DPVAL_TIME:
return "DPVAL/Time";
case DPVAL_STRING:
return "DPVAL/String";
case DPVAL_BINARY:
return "DPVAL/Binary";
case VOID:
return "Void";
default:
throw std::domain_error("Illegal DeliveryType.");
}
}
/**
* Returns <tt>true</tt> if and only if the given DeliveryType is a DPVAL
* variant.
*
* @param type The DeliveryType to be checked.
* @return The result.
* @throws std::domain_error If applied to an invalid value.
*/
inline bool DPVAL_variant(const DeliveryType type)
{
switch (type) {
case DPVAL_INT:
case DPVAL_UINT:
case DPVAL_BOOL:
case DPVAL_CHAR:
case DPVAL_FLOAT:
case DPVAL_DOUBLE:
case DPVAL_TIME:
case DPVAL_STRING:
case DPVAL_BINARY:
return true;
case RAW_INT:
case RAW_UINT:
case RAW_BOOL:
case RAW_CHAR:
case RAW_FLOAT:
case RAW_DOUBLE:
case RAW_TIME:
case RAW_STRING:
case RAW_BINARY:
case VOID:
return false;
default:
throw std::domain_error("Illegal DeliveryType.");
}
}
/**
* Returns the DIM description string for a DIM service with the given
* DeliveryType.
*
* @param type The DeliveryType.
* @return The corresponding DIM service description string.
* @throws std::domain_error If applied to an invalid value.
*/
inline std::string dim_description(const DeliveryType type)
{
switch (type) {
case RAW_INT:
return "I:1";
case RAW_UINT:
return "I:1";
case RAW_BOOL:
return "I:1";
case RAW_CHAR:
return "C:4";
case RAW_FLOAT:
return "F:1";
case RAW_DOUBLE:
return "D:1";
case RAW_TIME:
return "I:2";
case RAW_STRING:
return "C:55";
case RAW_BINARY:
return "C:56";
case DPVAL_INT:
return "S:2;I:1;I:1";
case DPVAL_UINT:
return "S:2;I:1;I:1";
case DPVAL_BOOL:
return "S:2;I:1;I:1";
case DPVAL_CHAR:
return "S:2;I:1;C:4";
case DPVAL_FLOAT:
return "S:2;I:1;F:1";
case DPVAL_DOUBLE:
return "S:2;I:1;D:1";
case DPVAL_TIME:
return "S:2;I:1;I:2";
case DPVAL_STRING:
return "S:2;I:1;C:55";
case DPVAL_BINARY:
return "S:2;I:1;C:56";
case VOID:
default:
throw std::domain_error("Illegal DeliveryType.");
}
}
/**
* Returns the size of a buffer required to store the binary contents of a
* DIM service of the given data type.
*
* @param type The DeliveryType.
* @return Size of the payload.
* @throws std::domain_error If applied to an invalid value.
*/
inline size_t dim_buffer_size(const DeliveryType type)
{
switch (type) {
case RAW_INT:
case RAW_UINT:
case RAW_BOOL:
case RAW_CHAR:
case RAW_FLOAT:
return 4;
case RAW_DOUBLE:
case RAW_TIME:
return 8;
case RAW_STRING:
return 55;
case RAW_BINARY:
return 56;
case DPVAL_INT:
case DPVAL_UINT:
case DPVAL_BOOL:
case DPVAL_CHAR:
case DPVAL_FLOAT:
case DPVAL_DOUBLE:
case DPVAL_TIME:
case DPVAL_STRING:
case DPVAL_BINARY:
return 64;
case VOID:
return 0;
default:
throw std::domain_error("Illegal DeliveryType.");
}
}
} // namespace o2::dcs
#endif /* O2_DCS_DELIVERY_TYPE */