Pottu
dataitem.hpp
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #include <cstdint>
11 #include <cinttypes>
12 #include <cstdio>
13 #include <cstring>
14 
15 namespace pottu
16 {
17 
23  enum class itemtype_e : uint32_t
24  {
25  tracedata = 0,
26  tracehead = 1,
27  info = 2,
28  data = 3
29  };
30 
37  inline const char *rectypeToString(uint64_t type)
38  {
39  static const char *tbl[] = {"tracedata", "tracehead", "info", "data", "INVALID"};
40  return tbl[type < 4 ? type : 4];
41  }
42 
47  enum class infocode_e : uint32_t
48  {
49  undef = 0,
50  pileup = 1,
51  pausets = 2,
52  resumets = 3,
53  sync100ts = 4,
54  undef2 = 5,
55  discrdata = 6,
56  extendedts = 7,
57  st_mbs_info = 8,
58  adc_overrange = 9,
59  adc_underrange = 10,
60  adc_overflow = 11,
61  adc_underflow = 12,
62  trigger_seq = 13,
63  data_link_stat = 14,
64  sharc_link_num = 15
65  };
66 
72  {
73 
75  uint64_t res0 : 62;
76 
78  uint32_t itemtype : 2;
79  };
80 
87  {
88 
90  uint32_t timestamp : 28;
91 
93  uint32_t res0 : 4;
94 
96  uint32_t adc : 16;
97 
99  uint32_t chi : 12;
100  // uint32_t chi_adc : 4;
101  // uint32_t chi_flag : 1;
102  // uint32_t chi_module : 7;
103 
105  uint32_t veto : 1;
106 
108  uint32_t fail : 1;
109 
111  uint32_t itemtype : 2;
112 
114  uint32_t getChannelIdent_adc() const { return chi & 0xFUL; }
115 
121  uint32_t getChannelIdent_flag() const { return (chi >> 4) & 0x1UL; }
122 
124  uint32_t getChannelIdent_module() const { return (chi >> 5) & 0x7FUL; }
125 
130  inline void set(uint64_t timestamp_, uint32_t adc_, uint32_t chi_,
131  bool veto_, bool fail_)
132  {
133  timestamp = timestamp_;
134  res0 = 0;
135  adc = adc_;
136  chi = chi_;
137  veto = veto_ ? 1 : 0;
138  fail = fail_ ? 1 : 0;
139  itemtype = static_cast<uint32_t>(itemtype_e::data);
140  }
141 
146  void toCStringFull(char *s, uint32_t len) const
147  {
148  std::snprintf(s, len, "%2" PRIu32 " %09" PRIu32 " %02" PRIu32 " %05" PRIu32
149  " %02" PRIu32 " %01" PRIu32 " %03" PRIu32 " %01" PRIu32 " %01" PRIu32,
152  veto, fail);
153  }
154  };
155 
162  {
163 
165  uint32_t timestamp : 28;
166 
168  uint32_t res0 : 4;
169 
171  uint32_t info : 20;
172 
177  uint32_t code : 4;
178 
180  uint32_t module : 6;
181 
183  uint32_t itemtype : 2;
184 
189  infocode_e getCode() const { return static_cast<infocode_e>(code); }
190 
195  uint32_t getChannelIdent() const
196  {
197  return (module << 5) + info;
198  }
199 
204  inline void set(uint64_t timestamp_, uint32_t code_, uint32_t info_, uint32_t module_)
205  {
206  timestamp = timestamp_;
207  res0 = 0;
208  info = info_;
209  code = code_;
210  module = module_;
211  itemtype = static_cast<uint32_t>(itemtype_e::info);
212  }
213 
218  void toCStringFull(char *s, uint32_t len) const
219  {
220  std::snprintf(s, len, "%2" PRIu32 " %09" PRIu32 " %02" PRIu32 " %07" PRIu32 " %02" PRIu32 " %02" PRIu32,
222  }
223  };
224 
231  {
232 
234  uint32_t timestamp : 28;
235 
237  uint32_t res0 : 4;
238 
244  uint32_t samplelength : 16;
245 
247  uint32_t chi : 12;
248 
250  uint32_t getChannelIdent_adc() const { return chi & 0xFUL; }
251 
253  uint32_t res1 : 2;
254 
256  uint32_t itemtype : 2;
257 
263  uint32_t getChannelIdent_flag() const { return (chi >> 4) & 0x1UL; }
264 
266  uint32_t getChannelIdent_module() const { return (chi >> 5) & 0x7FUL; }
267 
272  void toCStringFull(char *s, uint32_t len) const
273  {
274  std::snprintf(s, len, "%2" PRIu32 " %09" PRIu32 " %02" PRIu32 " %05" PRIu32
275  " %02" PRIu32 " %01" PRIu32 " %03" PRIu32 " %01" PRIu32,
278  res1);
279  }
280  };
281 
288  {
289 
291  uint16_t sample3 : 14;
293  uint16_t res3 : 2;
294 
296  uint16_t sample2 : 14;
298  uint16_t res2 : 2;
299 
301  uint16_t sample1 : 14;
303  uint16_t res1 : 2;
304 
306  uint16_t sample0 : 14;
308  uint16_t res0 : 2;
309 
316  inline void set(const uint16_t *samples)
317  {
318  sample0 = samples[0];
319  sample1 = samples[1];
320  sample2 = samples[2];
321  sample3 = samples[3];
322  }
323 
328  void toCStringFull(char *s, uint32_t len) const
329  {
330  uint32_t rectype = static_cast<uint32_t>(itemtype_e::tracedata);
331  std::snprintf(s, len, "%2" PRIu32 " %05" PRIu16 " %05" PRIu16 " %05" PRIu16 " %05" PRIu16,
332  rectype, sample0, sample1, sample2, sample3);
333  }
334  };
335 
343  {
344 
348 
351 
354 
357 
360 
362  uint64_t rawdata;
363 
365  inline static dataitem_t create(uint64_t v)
366  {
367  dataitem_t ret;
368  ret.rawdata = v;
369  return ret;
370  }
371 
376  itemtype_e getType() const { return static_cast<itemtype_e>(type.itemtype); }
377 
382  inline dataitem_t asSwapped() const
383  {
384  return (dataitem_t::create(((rawdata & 0xFFFFFFFF) << 32ULL) | (rawdata >> 32ULL)));
385  }
386 
388  inline void clear() { rawdata = 0; }
389 
395  void toCStringFull(char *s, uint32_t len) const
396  {
397  switch (getType())
398  {
399  case itemtype_e::tracedata:
400  tracedata.toCStringFull(s, len);
401  break;
402  case itemtype_e::tracehead:
403  tracehead.toCStringFull(s, len);
404  break;
405  case itemtype_e::info:
406  info.toCStringFull(s, len);
407  break;
408  case itemtype_e::data:
409  data.toCStringFull(s, len);
410  break;
411  }
412  }
413  };
414 
415 
419  struct dataitem_ts_t {
420  dataitem_t item;
421  int64_t ts;
422  };
423 
424 }
Definition: mainpage.dox:6
const char * rectypeToString(uint64_t type)
Function to get a static string corresponding to dataitemtypes.
Definition: dataitem.hpp:37
infocode_e
Enum to describe all possible types of infovalue.
Definition: dataitem.hpp:48
itemtype_e
Enum to describe all possible types of a raw dataitem.
Definition: dataitem.hpp:24
Dataitem used to read the dataitem of type itemtype_e::DATA.
Definition: dataitem.hpp:87
uint32_t itemtype
Type of the item. One of itemtype_e enum.
Definition: dataitem.hpp:111
uint32_t getChannelIdent_adc() const
ADC number in a module. Calculated from the field chi.
Definition: dataitem.hpp:114
uint32_t timestamp
Lowest 28 bits of the timestamp.
Definition: dataitem.hpp:90
uint32_t fail
Flag to mark that the event is fail.
Definition: dataitem.hpp:108
void toCStringFull(char *s, uint32_t len) const
Get the content as a c string.
Definition: dataitem.hpp:146
uint32_t getChannelIdent_flag() const
Flag in the field chi.
Definition: dataitem.hpp:121
uint32_t getChannelIdent_module() const
Module number. Calculated from the field chi.
Definition: dataitem.hpp:124
void set(uint64_t timestamp_, uint32_t adc_, uint32_t chi_, bool veto_, bool fail_)
Sets the fields.
Definition: dataitem.hpp:130
uint32_t res0
Empty 4 bits. Can be used for word order guessing.
Definition: dataitem.hpp:93
uint32_t chi
Channel ident. Can be used as a DAQ channel number.
Definition: dataitem.hpp:99
uint32_t adc
ADC value. Maximum 16 bits, typically 14 bits.
Definition: dataitem.hpp:96
uint32_t veto
Flag to mark that the event is vetoed.
Definition: dataitem.hpp:105
Dataitem used to read the dataitem of type itemtype_e::INFO.
Definition: dataitem.hpp:162
uint32_t getChannelIdent() const
Returns channel ident for pileup and adc over/under range/flow.
Definition: dataitem.hpp:195
void set(uint64_t timestamp_, uint32_t code_, uint32_t info_, uint32_t module_)
Sets the fields.
Definition: dataitem.hpp:204
infocode_e getCode() const
Returns the infocode as class enum.
Definition: dataitem.hpp:189
uint32_t timestamp
Lowest 28 bits of the timestamp.
Definition: dataitem.hpp:165
uint32_t code
infocode, one of enum infocode_e.
Definition: dataitem.hpp:177
uint32_t res0
Empty 4 bits. Can be used for word order guessing.
Definition: dataitem.hpp:168
uint32_t module
Module number who has sent this info.
Definition: dataitem.hpp:180
void toCStringFull(char *s, uint32_t len) const
Get the content as a c string.
Definition: dataitem.hpp:218
uint32_t itemtype
Type of the item. One of itemtype_e.
Definition: dataitem.hpp:183
uint32_t info
Value of the info. TODO describe the types of value possible...
Definition: dataitem.hpp:171
Dataitem used to read the dataitem of type itemtype_e::tracedata.
Definition: dataitem.hpp:288
uint16_t sample1
Definition: dataitem.hpp:301
void set(const uint16_t *samples)
Sets the fields.
Definition: dataitem.hpp:316
uint16_t sample3
Definition: dataitem.hpp:291
void toCStringFull(char *s, uint32_t len) const
Get the content as a c string.
Definition: dataitem.hpp:328
uint16_t sample0
Definition: dataitem.hpp:306
uint16_t res0
Definition: dataitem.hpp:308
uint16_t res2
Definition: dataitem.hpp:298
uint16_t res1
Definition: dataitem.hpp:303
uint16_t sample2
Definition: dataitem.hpp:296
uint16_t res3
Definition: dataitem.hpp:293
Dataitem used to read the dataitem of type itemtype_e::TRACEHEAD.
Definition: dataitem.hpp:231
uint32_t chi
Channel ident. Can be used as a DAQ channel number.
Definition: dataitem.hpp:247
uint32_t itemtype
Type of the item. One of itemtype_e.
Definition: dataitem.hpp:256
uint32_t res0
Empty 4 bits. Can be used for word order guessing.
Definition: dataitem.hpp:237
void toCStringFull(char *s, uint32_t len) const
Get the content as a c string.
Definition: dataitem.hpp:272
uint32_t getChannelIdent_adc() const
ADC number in a module. Calculated from the field chi.
Definition: dataitem.hpp:250
uint32_t getChannelIdent_flag() const
Flag in the field chi.
Definition: dataitem.hpp:263
uint32_t samplelength
Number of samples following.
Definition: dataitem.hpp:244
uint32_t res1
Not used by this struct.
Definition: dataitem.hpp:253
uint32_t getChannelIdent_module() const
Module number. Calculated from the field chi.
Definition: dataitem.hpp:266
uint32_t timestamp
Lowest 28 bits of the timestamp.
Definition: dataitem.hpp:234
Raw dataitem with full timestamp.
Definition: dataitem.hpp:419
Dataitem used to read the itemtype_e.
Definition: dataitem.hpp:72
uint32_t itemtype
Type of the item. One of itemtype_e.
Definition: dataitem.hpp:78
uint64_t res0
Not used by this struct.
Definition: dataitem.hpp:75
Raw dataitem in tdr binary data.
Definition: dataitem.hpp:343
dataitem_t asSwapped() const
Returns a new dataitem having 16 bit words swapped.
Definition: dataitem.hpp:382
itemtype_e getType() const
Returns the type of the item.
Definition: dataitem.hpp:376
dataitem_tracehead_t tracehead
Field to access the content of datatype DATATYPE_TRACEHEAD.
Definition: dataitem.hpp:356
dataitem_type_t type
Field to access the type. One can use also method getType().
Definition: dataitem.hpp:347
dataitem_info_t info
Field to access the content of datatype DATATYPE_INFO.
Definition: dataitem.hpp:353
uint64_t rawdata
Field to access the raw memory at once.
Definition: dataitem.hpp:362
void toCStringFull(char *s, uint32_t len) const
Get the content as a c string.
Definition: dataitem.hpp:395
dataitem_data_t data
Field to access the content of datatype DATATYPE_DATA.
Definition: dataitem.hpp:350
static dataitem_t create(uint64_t v)
Creates and returns a new dataitem from a raw data.
Definition: dataitem.hpp:365
void clear()
Sets the all bits to zero.
Definition: dataitem.hpp:388
dataitem_tracedata_t tracedata
Field to access the content of datatype DATATYPE_tracedata.
Definition: dataitem.hpp:359