BmnRoot
Loading...
Searching...
No Matches
uni_db_structures.h
Go to the documentation of this file.
1#ifndef DB_STRUCTURES_H
2#define DB_STRUCTURES_H
3
4#include "UniValue.h"
5#include "nlohmann/json.hpp"
6
7#include <cstdint>
8#include <cstring>
9#include <string>
10using namespace std;
12
13// unique run number = period_number : run_number
15{
17 {
18 period_number = 0;
19 run_number = 0;
20 }
21 UniqueRunNumber(int period_num, int run_num)
22 {
23 period_number = period_num;
24 run_number = run_num;
25 }
28};
29
30// enumeration 'enumValueType' is corresponding to 'parameter_type' member of the UniParameter class, types:
31// 0 - boolean, 1 - integer, 2 - unsigned integer, 3 - double, 4 - string, 5 - binary, 6 - int+int,
32// 7 - DCH mapping, 8 - GEM mapping, 9 - GEM pedestal mapping, 10 - trigger mapping, 11 - Lorentz shift,
33// 12 - mapping with bool value (serial+channel+bool), 13 - mapping with int, 14 - mapping with double vector,
34// 15 - alignment type, 16 - TDC INL values, 17 - value as JSON format
57
59struct BoolValue : public UniValue
60{
61 uint8_t value;
62
64 size_t GetStorageSize() { return 1; }
65 void ReadValue(unsigned char* source) { Read(source, value); }
66 void WriteValue(unsigned char* destination) { Write(destination, value); }
67};
68
69struct IntValue : public UniValue
70{
71 int32_t value;
72
74 size_t GetStorageSize() { return 4; }
75 void ReadValue(unsigned char* source) { Read(source, value); }
76 void WriteValue(unsigned char* destination) { Write(destination, value); }
77};
78
79struct UIntValue : public UniValue
80{
81 uint32_t value;
82
84 size_t GetStorageSize() { return 4; }
85 void ReadValue(unsigned char* source) { Read(source, value); }
86 void WriteValue(unsigned char* destination) { Write(destination, value); }
87};
88
89struct DoubleValue : public UniValue
90{
91 double value;
92
94 size_t GetStorageSize() { return 8; }
95 void ReadValue(unsigned char* source) { Read(source, value); }
96 void WriteValue(unsigned char* destination) { Write(destination, value); }
97};
98
99struct StringValue : public UniValue
100{
101 string value;
102
104 size_t GetStorageSize() { return value.length() + 1; }
105 void ReadValue(unsigned char* source) { Read(source, value); }
106 void WriteValue(unsigned char* destination) { Write(destination, value); }
107};
108
109struct BinaryValue : public UniValue
110{
111 uint64_t size;
112 unsigned char* value; // char array is stored with the size variable (+8)
113
115 size_t GetStorageSize() { return size + 8; }
116 void ReadValue(unsigned char* source) { Read(source, value, size); }
117 void WriteValue(unsigned char* destination) { Write(destination, value, size); }
118};
119
120struct IIValue : public UniValue
121{
122 int32_t value1;
123 int32_t value2;
124
126 size_t GetStorageSize() { return 8; }
127 void ReadValue(unsigned char* source)
128 {
129 Read(source, value1);
130 Read(source, value2);
131 }
132 void WriteValue(unsigned char* destination)
133 {
134 Write(destination, value1);
135 Write(destination, value2);
136 }
137};
138
139struct DchMapValue : public UniValue
140{
141 int32_t plane;
142 int32_t group;
143 uint32_t crate;
144 int32_t slot;
145 int32_t channel_low;
147
149 size_t GetStorageSize() { return 24; }
150 void ReadValue(unsigned char* source)
151 {
152 Read(source, plane);
153 Read(source, group);
154 Read(source, crate);
155 Read(source, slot);
156 Read(source, channel_low);
157 Read(source, channel_high);
158 }
159 void WriteValue(unsigned char* destination)
160 {
161 Write(destination, plane);
162 Write(destination, group);
163 Write(destination, crate);
164 Write(destination, slot);
165 Write(destination, channel_low);
166 Write(destination, channel_high);
167 }
168};
169
170struct GemMapValue : public UniValue
171{
172 uint32_t serial;
173 int32_t id;
174 int32_t station;
175 int32_t channel_low;
177 int32_t hotZone;
178
180 size_t GetStorageSize() { return 24; }
181 void ReadValue(unsigned char* source)
182 {
183 Read(source, serial);
184 Read(source, id);
185 Read(source, station);
186 Read(source, channel_low);
187 Read(source, channel_high);
188 Read(source, hotZone);
189 }
190 void WriteValue(unsigned char* destination)
191 {
192 Write(destination, serial);
193 Write(destination, id);
194 Write(destination, station);
195 Write(destination, channel_low);
196 Write(destination, channel_high);
197 Write(destination, hotZone);
198 }
199};
200
202{
203 uint32_t serial;
204 int32_t channel;
205 int32_t pedestal;
206 int32_t noise;
207
209 size_t GetStorageSize() { return 16; }
210 void ReadValue(unsigned char* source)
211 {
212 Read(source, serial);
213 Read(source, channel);
214 Read(source, pedestal);
215 Read(source, noise);
216 }
217 void WriteValue(unsigned char* destination)
218 {
219 Write(destination, serial);
220 Write(destination, channel);
221 Write(destination, pedestal);
222 Write(destination, noise);
223 }
224};
225
227{
228 uint32_t serial;
229 uint32_t slot;
230 int32_t channel;
231
233 size_t GetStorageSize() { return 12; }
234 void ReadValue(unsigned char* source)
235 {
236 Read(source, serial);
237 Read(source, slot);
238 Read(source, channel);
239 }
240 void WriteValue(unsigned char* destination)
241 {
242 Write(destination, serial);
243 Write(destination, slot);
244 Write(destination, channel);
245 }
246};
247
248struct MapBoolValue : public UniValue
249{
250 uint32_t serial;
251 int32_t channel;
252 uint8_t value;
253
255 size_t GetStorageSize() { return 9; }
256 void ReadValue(unsigned char* source)
257 {
258 Read(source, serial);
259 Read(source, channel);
260 Read(source, value);
261 }
262 void WriteValue(unsigned char* destination)
263 {
264 Write(destination, serial);
265 Write(destination, channel);
266 Write(destination, value);
267 }
268};
269
270struct MapIntValue : public UniValue
271{
272 uint32_t serial;
273 int32_t channel;
274 int32_t value;
275
277 size_t GetStorageSize() { return 12; }
278 void ReadValue(unsigned char* source)
279 {
280 Read(source, serial);
281 Read(source, channel);
282 Read(source, value);
283 }
284 void WriteValue(unsigned char* destination)
285 {
286 Write(destination, serial);
287 Write(destination, channel);
288 Write(destination, value);
289 }
290};
291
293{
294 uint32_t serial;
295 int32_t channel;
296 vector<double> value; // vector is stored with the size (+8)
297
299 size_t GetStorageSize() { return value.size() * 8 + 16; } // (value.size()*8+8) + 8
300 void ReadValue(unsigned char* source)
301 {
302 Read(source, serial);
303 Read(source, channel);
304 Read(source, value);
305 }
306 void WriteValue(unsigned char* destination)
307 {
308 Write(destination, serial);
309 Write(destination, channel);
310 Write(destination, value);
311 }
312};
313
315{
316 int32_t number;
317 double ls[3];
318
320 size_t GetStorageSize() { return 28; }
321 void ReadValue(unsigned char* source)
322 {
323 Read(source, number);
324 Read(source, ls, 3);
325 }
326 void WriteValue(unsigned char* destination)
327 {
328 Write(destination, number);
329 Write(destination, ls, 3);
330 }
331};
332
334{
335 uint8_t station;
336 uint8_t module;
337 double value[3];
338
340 size_t GetStorageSize() { return 26; }
341 void ReadValue(unsigned char* source)
342 {
343 Read(source, station);
344 Read(source, module);
345 Read(source, value, 3);
346 }
347 void WriteValue(unsigned char* destination)
348 {
349 Write(destination, station);
350 Write(destination, module);
351 Write(destination, value, 3);
352 }
353};
354
355struct TdcInlValue : public UniValue
356{
357 uint32_t serial;
358 double inl[72][1024];
359
361 size_t GetStorageSize() { return 589828; }
362 void ReadValue(unsigned char* source)
363 {
364 Read(source, serial);
365 Read(source, inl);
366 }
367 void WriteValue(unsigned char* destination)
368 {
369 Write(destination, serial);
370 Write(destination, inl);
371 }
372};
373
374struct JsonValue : public UniValue
375{
377
379 size_t GetStorageSize() { return json::to_cbor(value).size() + 8; }
380 void ReadValue(unsigned char* source) { Read(source, value); }
381 void WriteValue(unsigned char* destination) { Write(destination, value); }
382};
383
384/*struct AlignmentValue : public UniValue
385{
386 uint8_t n_stations;
387 uint8_t n_modules;
388 uint8_t n_space;
389 double*** value;
390
391 enumValueType GetType() { return AlignmentType; }
392 size_t GetStorageSize() { return n_stations*n_modules*n_space*8+3; }
393 void ReadValue(unsigned char* source) { Read(source, value, n_stations, n_modules, n_space); }
394 void WriteValue(unsigned char* destination) { Write(destination, value, n_stations, n_modules, n_space); }
395};*/
396
397#ifndef CREATE_PARAMETER_VALUE_H
398#define CREATE_PARAMETER_VALUE_H
399// global function for creating value according to a given type name (parameter_type)
401{
402 switch (parameter_type) {
403 case BoolType:
404 return new BoolValue;
405 case IntType:
406 return new IntValue;
407 case UIntType:
408 return new UIntValue;
409 case DoubleType:
410 return new DoubleValue;
411 case StringType:
412 return new StringValue;
413 case BinaryType:
414 return new BinaryValue;
415 case IIType:
416 return new IIValue;
417 case DchMapType:
418 return new DchMapValue;
419 case GemMapType:
420 return new GemMapValue;
421 case GemPedestalType:
422 return new GemPedestalValue;
423 case TriggerMapType:
424 return new TriggerMapValue;
425 case LorentzShiftType:
426 return new LorentzShiftValue;
427 case MapBoolType:
428 return new MapBoolValue;
429 case MapIntType:
430 return new MapIntValue;
431 case MapDVectorType:
432 return new MapDVectorValue;
433 case AlignmentType:
434 return new AlignmentValue;
435 case TdcInlType:
436 return new TdcInlValue;
437 case JsonType:
438 return new JsonValue;
439 default:
440 break;
441 }
442
443 cout << "ERROR: The given value type is not supported!" << endl;
444 return nullptr;
445}
446#endif
447
448#endif // DB_STRUCTURES_H
a class to store JSON values
Definition json.hpp:17282
static std::vector< std::uint8_t > to_cbor(const basic_json &j)
create a CBOR serialization of a given JSON value
Definition json.hpp:21010
enumValueType
@ DchMapType
@ GemMapType
@ GemPedestalType
@ AlignmentType
@ IntType
@ MapBoolType
@ BinaryType
@ TriggerMapType
@ MapDVectorType
@ StringType
@ LorentzShiftType
@ UndefinedType
@ TdcInlType
@ BoolType
@ DoubleType
@ IIType
@ UIntType
@ JsonType
@ MapIntType
UniValue * CreateParameterValue(enumValueType parameter_type)
enumValueType
@ DchMapType
@ GemMapType
@ GemPedestalType
@ AlignmentType
@ IntType
@ MapBoolType
@ BinaryType
@ TriggerMapType
@ MapDVectorType
@ StringType
@ LorentzShiftType
@ TdcInlType
@ BoolType
@ DoubleType
@ IIType
@ UIntType
@ JsonType
@ MapIntType
basic_json<> json
default specialization
Definition json.hpp:3337
STL namespace.
void WriteValue(unsigned char *destination)
uint8_t double value[3]
enumValueType GetType()
void ReadValue(unsigned char *source)
unsigned char * value
void WriteValue(unsigned char *destination)
size_t GetStorageSize()
void ReadValue(unsigned char *source)
enumValueType GetType()
void ReadValue(unsigned char *source)
void WriteValue(unsigned char *destination)
enumValueType GetType()
size_t GetStorageSize()
enumValueType GetType()
void WriteValue(unsigned char *destination)
void ReadValue(unsigned char *source)
size_t GetStorageSize()
void WriteValue(unsigned char *destination)
void ReadValue(unsigned char *source)
size_t GetStorageSize()
enumValueType GetType()
void WriteValue(unsigned char *destination)
void ReadValue(unsigned char *source)
size_t GetStorageSize()
enumValueType GetType()
void WriteValue(unsigned char *destination)
enumValueType GetType()
void ReadValue(unsigned char *source)
enumValueType GetType()
void WriteValue(unsigned char *destination)
void ReadValue(unsigned char *source)
size_t GetStorageSize()
void WriteValue(unsigned char *destination)
enumValueType GetType()
void ReadValue(unsigned char *source)
size_t GetStorageSize()
enumValueType GetType()
size_t GetStorageSize()
void ReadValue(unsigned char *source)
void WriteValue(unsigned char *destination)
enumValueType GetType()
void WriteValue(unsigned char *destination)
void ReadValue(unsigned char *source)
enumValueType GetType()
size_t GetStorageSize()
void ReadValue(unsigned char *source)
void WriteValue(unsigned char *destination)
enumValueType GetType()
void ReadValue(unsigned char *source)
void WriteValue(unsigned char *destination)
vector< double > value
enumValueType GetType()
void ReadValue(unsigned char *source)
void WriteValue(unsigned char *destination)
size_t GetStorageSize()
void ReadValue(unsigned char *source)
size_t GetStorageSize()
void WriteValue(unsigned char *destination)
enumValueType GetType()
void WriteValue(unsigned char *destination)
enumValueType GetType()
size_t GetStorageSize()
double inl[72][1024]
void ReadValue(unsigned char *source)
void WriteValue(unsigned char *destination)
void ReadValue(unsigned char *source)
enumValueType GetType()
void WriteValue(unsigned char *destination)
enumValueType GetType()
size_t GetStorageSize()
void ReadValue(unsigned char *source)
void Write(unsigned char *&destination, uint8_t &value)
Definition UniValue.h:42
void Read(unsigned char *&source, uint8_t &value)
Definition UniValue.h:37
UniqueRunNumber(int period_num, int run_num)