PennMicroSlice.hh
Go to the documentation of this file.
1 #ifndef dune_artdaq_Overlays_PennMicroSlice_hh
2 #define dune_artdaq_Overlays_PennMicroSlice_hh
3 
4 #include <cstdint>
5 //#include <stddef.h>
6 #include <string>
7 //#define PENN_OLD_STRUCTS
8 
9 namespace dune {
10  class PennMicroSlice;
11 }
12 
14 
15 public:
16 
17 #ifdef PENN_OLD_STRUCTS
18  struct Header {
19 
20  typedef uint32_t data_t;
21 
22  typedef uint8_t format_version_t;
23  typedef uint8_t sequence_id_t;
24  typedef uint16_t block_size_t;
25 
26  // JCF, Jul-28-15
27 
28  // The order of these variables have been reversed to reflect that
29  // the block size takes up the two least significant bytes, the
30  // sequence ID the second most significant byte, and the format
31  // version the most significant byte, of the four-byte microslice header
32 
33  block_size_t block_size : 16;
34  sequence_id_t sequence_id : 8;
35  format_version_t format_version : 8;
36 
37 
38 
39  static size_t const size_words = sizeof(data_t);
40 
41  //static constexpr size_t raw_header_words = 1;
42  //data_t raw_header_data[raw_header_words];
43  };
44 
45  // Nanoslice
46  struct Payload_Header {
47 
48  typedef uint32_t data_t;
49 
50  typedef uint8_t data_packet_type_t;
51  typedef uint32_t short_nova_timestamp_t;
52 
53  // JCF, Jul-28-15
54 
55  // The order of the data packet type and the timestamp have been
56  // swapped to reflect that it's the MOST significant three bits in
57  // the payload header which contain the type. I've also added a
58  // 1-bit pad to reflect that the least significant bit is unused.
59 
60  uint8_t padding : 2;
61  short_nova_timestamp_t short_nova_timestamp : 27;
62  data_packet_type_t data_packet_type : 3;
63 
64  static size_t const size_words = sizeof(data_t);
65  };
66 
67  struct Warning_Header {
68  typedef uint32_t data_t;
69  typedef uint16_t data_size_t;
70 
71  typedef uint8_t warning_type_t;
72  typedef uint8_t data_packet_type_t;
73  typedef uint32_t short_nova_timestamp_t;
74 
75  // The order of the data packet type and the timestamp have been
76  // swapped to reflect that it's the MOST significant three bits in
77  // the payload header which contain the type. I've also added a
78  // 1-bit pad to reflect that the least significant bit is unused.
79 
80  uint32_t padding : 24;
81  warning_type_t warning_type : 5;
82  data_packet_type_t data_packet_type : 3;
83 
84  static size_t const size_words = sizeof(data_t);
85  static data_size_t const num_bits_padding = 24;
86  static data_size_t const num_bits_warning = 5;
87  static data_size_t const num_bits_packet_type = 3;
88  };
89 
90 #else
91  /// Header of ethernet packet
92  struct Header {
93 
94  typedef uint32_t data_t;
95  typedef uint16_t data_size_t;
96 
97  typedef uint8_t format_version_t;
98  typedef uint8_t sequence_id_t;
99  typedef uint16_t block_size_t;
100 
101  block_size_t block_size : 16;
102  sequence_id_t sequence_id : 8;
103  format_version_t format_version : 8;
104 
105  static size_t const size_words = sizeof(data_t);
106 
107  static data_size_t const num_bits_size = 16;
108  static data_size_t const num_bits_sequence_id = 8;
109  static data_size_t const num_bits_format = 8;
110 };
111 
112 /// Internal warning word
113 struct Warning_Word {
114  typedef uint32_t data_t;
115  typedef uint16_t data_size_t;
116 
117  typedef uint8_t warning_type_t;
118  typedef uint8_t data_packet_type_t;
119 
120  uint32_t padding : 24;
121  warning_type_t warning_type : 5;
122  data_packet_type_t data_packet_type : 3;
123 
124  static size_t const size_words = sizeof(data_t);
125  static data_size_t const num_bits_padding = 24;
126  static data_size_t const num_bits_warning = 5;
127  static data_size_t const num_bits_packet_type = 3;
128 };
129 
130 /// Frame header : Common header to everything except warning words
132  typedef uint32_t data_t;
133  typedef uint16_t data_size_t;
134 
135  typedef uint8_t data_packet_type_t;
136  typedef uint32_t short_nova_timestamp_t;
137 
138  // The order of the data packet type and the timestamp have been
139  // swapped to reflect that it's the MOST significant three bits in
140  // the payload header which contain the type. I've also added a
141  // 2-bit pad to reflect that the 2 least significant bits are unused.
142 
143  uint8_t padding : 2;
144  short_nova_timestamp_t short_nova_timestamp : 27;
145  data_packet_type_t data_packet_type : 3;
146 
147  static size_t const size_bytes = sizeof(data_t);
148  static size_t const size_u32 = sizeof(data_t)/sizeof(uint32_t);
149 
150  static data_size_t const num_bits_padding = 2;
151  static data_size_t const num_bits_short_tstamp = 27;
152  static data_size_t const num_bits_packet_type = 3;
153 
154  // This function converts the TS rollover into a full TS
155  // it takes the payload of the timestamp word that came after this word
156  // (the microslice border)
157  // and calculates the offset
158  // to use the full timestamp received before use the other method (pre)
159  uint64_t get_full_timestamp_pre(uint64_t ts_ref) {
160  if ((ts_ref & 0x7FFFFFF) == short_nova_timestamp) {
161  // they are equal. This word is right on the border of the microslice
162  return ts_ref;
163  } else if ((ts_ref & 0x7FFFFFF) > short_nova_timestamp) {
164  // there was no bit rollover in between
165  return ts_ref - ((ts_ref & 0x7FFFFFF) - short_nova_timestamp);
166  } else {
167  // it rolled over.
168  // Be sure of the values being set
169  return ts_ref - ((ts_ref & 0x7FFFFFF) + (0x7FFFFFF - short_nova_timestamp));
170  }
171  }
172  // Does the same as the previous but with the timestamp that came before
173  // They should be equivalent but need to check to confirm
174  uint64_t get_full_timestamp_post(uint64_t ts_ref) {
175  if ((ts_ref & 0x7FFFFFF) == short_nova_timestamp) {
176  // they are equal. This word is right on the border of the microslice
177  return ts_ref;
178  } else if ((ts_ref & 0x7FFFFFF) > short_nova_timestamp) {
179  // it rolled over. Has to sum the short and the difference
180  // that takes for the reference to roll over
181  return ts_ref + (0x7FFFFFF - ((ts_ref & 0x7FFFFFF))) + short_nova_timestamp;
182  } else {
183  // it didn't roll over. Just add the difference of the rollovers
184  return ts_ref + (short_nova_timestamp - (ts_ref & 0x7FFFFFF));
185  }
186  }
187 
188 
189 };
190 
191 /// Counter payload description
193  typedef uint64_t counter_set_t;
194  typedef uint16_t data_size_t;
195  // -- Must be careful to follow the right order
196  // from lsb to msb it is
197  // -- TSU mappings
198  counter_set_t tsu_wu : 10;
199  counter_set_t tsu_el : 10;
200  counter_set_t tsu_extra : 4;
201  counter_set_t tsu_nu : 6;
202  counter_set_t tsu_sl : 6;
203  counter_set_t tsu_nl : 6;
204  counter_set_t tsu_su : 6;
205  // -- BSU mappings
206  counter_set_t bsu_rm : 16;//end of first counter_set_t==uint64_t
207  counter_set_t bsu_cu : 10;
208  //FIXME: The panels should be remapped so that bsu_cl would be all together
209  counter_set_t bsu_cl1 : 6;
210  counter_set_t bsu_extra : 1;
211  counter_set_t bsu_cl2 : 7;
212  counter_set_t bsu_rl : 10;
213  // Just ignore the rest of the word
214  counter_set_t padding : 30;
215 
216  static data_size_t const num_bits_tsu_wu = 10;
217  static data_size_t const num_bits_tsu_el = 10;
218  static data_size_t const num_bits_tsu_extra = 4;
219  static data_size_t const num_bits_tsu_nu = 6;
220  static data_size_t const num_bits_tsu_sl = 6;
221  static data_size_t const num_bits_tsu_nl = 6;
222  static data_size_t const num_bits_tsu_su = 6;
223  static data_size_t const num_bits_bsu_rm = 16;
224  static data_size_t const num_bits_bsu_cu = 10;
225  static data_size_t const num_bits_bsu_cl1 = 6;
226  static data_size_t const num_bits_bsu_extra = 1; // -- unused channel (32)
227  static data_size_t const num_bits_bsu_cl2 = 7;
228  static data_size_t const num_bits_bsu_rl = 10;
229  static data_size_t const num_bits_padding = 30;
230  static data_size_t const num_bits_bsu_cl = 13;
231 
232  // position boundaries for the different counter types
233  // it also works as a sort of enumerator for the different counter types
234  // so that they can be uniquely identified
235  // the value is the first element outside the type
236  static data_size_t const counter_type_tsu_wu = 10;
237  static data_size_t const counter_type_tsu_el = 20;
238  static data_size_t const counter_type_tsu_extra = 24;
239  static data_size_t const counter_type_tsu_nu = 30;
240  static data_size_t const counter_type_tsu_sl = 36;
241  static data_size_t const counter_type_tsu_nl = 42;
242  static data_size_t const counter_type_tsu_su = 48;
243  static data_size_t const counter_type_bsu_rm = 64;
244  static data_size_t const counter_type_bsu_cu = 74;
245  static data_size_t const counter_type_bsu_cl1 = 80;
246  static data_size_t const counter_type_bsu_extra = 81; // -- unused channel (32)
247  static data_size_t const counter_type_bsu_cl2 = 88;
248  static data_size_t const counter_type_bsu_rl = 98;
249  static data_size_t const counter_type_padding = 128;
250  // special types that are only used in the enum
251  static data_size_t const counter_type_unknown = 129;
252  static data_size_t const counter_type_bsu_cl = 130;
253 
254  static size_t const size_bytes = 2*sizeof(uint64_t);
255  static size_t const size_u32 = size_bytes/sizeof(uint32_t);
256 
257  // The size that arrives from the PTB
258  static size_t const size_words_ptb_u32 = 3;
259  static size_t const size_words_ptb_bytes = size_words_ptb_u32*sizeof(uint32_t);
260  // The offset to grab the data
261  static size_t const ptb_offset_u32 = 0;
262  static size_t const ptb_offset_bytes = ptb_offset_u32*sizeof(uint32_t);
263 
264  // The payload position offset from the top of the frame (header + discard)
265  static size_t const payload_offset_u32 = 1+ptb_offset_u32;
266  static size_t const payload_offset_bytes = payload_offset_u32*sizeof(uint32_t);
267 
268  counter_set_t get_bsu_cl() {return ((bsu_cl2 << 10) | (bsu_cl1));};
269 
270  bool get_tsu_wu(uint32_t idx) {
271  return ((tsu_wu & (1 << idx)) != 0x0);
272  }
273  bool get_tsu_el(uint32_t idx) {
274  return ((tsu_el & (1 << idx)) != 0x0);
275  }
276  bool get_tsu_extra(uint32_t idx) {
277  return ((tsu_extra & (1 << idx)) != 0x0);
278  }
279  bool get_tsu_nu(uint32_t idx) {
280  return ((tsu_nu & (1 << idx)) != 0x0);
281  }
282  bool get_tsu_sl(uint32_t idx) {
283  return ((tsu_sl & (1 << idx)) != 0x0);
284  }
285  bool get_tsu_nl(uint32_t idx) {
286  return ((tsu_nl & (1 << idx)) != 0x0);
287  }
288  bool get_tsu_su(uint32_t idx) {
289  return ((tsu_su & (1 << idx)) != 0x0);
290  }
291  // BSU getters
292  bool get_bsu_rm(uint32_t idx) {
293  return ((bsu_rm & (1 << idx)) != 0x0);
294  }
295  bool get_bsu_cu(uint32_t idx) {
296  return ((bsu_cu & (1 << idx)) != 0x0);
297  }
298  // The CL is a bit special due to the crazy mapping
299  bool get_bsu_cl(uint32_t idx) {
300  if (idx < num_bits_bsu_cl1) {
301  return ((bsu_cl1 & (1 << idx)) != 0x0);
302  } else {
303  return ((bsu_cl2 & (1 << (idx-num_bits_bsu_cl1))) != 0x0);
304  }
305  }
306  bool get_bsu_rl(uint32_t idx) {
307  return ((bsu_rl & (1 << idx)) != 0x0);
308  }
309 
310  bool get_counter_status(uint32_t idx) const {
311  // This was tested to return the right bits in the right order in a standalone test
312  // However, it is up to the user to know what type this bit corresponds to
313  return (((reinterpret_cast<const uint8_t*>(this)[idx/8]) & (1 << (idx%8))) != 0x0);
314  }
315 
316  static data_size_t get_counter_type(uint32_t bit_idx) {
317  // NFB: By construction bit_idx cannot be negative
318  // if (bit_idx < 0) return counter_type_unknown; else
319  if (bit_idx < counter_type_tsu_wu) return counter_type_tsu_wu;
320  else if (bit_idx < counter_type_tsu_el) return counter_type_tsu_el;
321  else if (bit_idx < counter_type_tsu_extra) return counter_type_tsu_extra;
322  else if (bit_idx < counter_type_tsu_nu) return counter_type_tsu_nu;
323  else if (bit_idx < counter_type_tsu_sl) return counter_type_tsu_sl;
324  else if (bit_idx < counter_type_tsu_nl) return counter_type_tsu_nl;
325  else if (bit_idx < counter_type_tsu_su) return counter_type_tsu_su;
326  else if (bit_idx < counter_type_bsu_rm) return counter_type_bsu_rm;
327  else if (bit_idx < counter_type_bsu_cu) return counter_type_bsu_cu;
328  else if (bit_idx == (counter_type_bsu_extra-1)) return counter_type_bsu_extra;
329  else if (bit_idx < counter_type_bsu_cl2) return counter_type_bsu_cl;
330  else if (bit_idx < counter_type_bsu_rl) return counter_type_bsu_rl;
331  else if (bit_idx < counter_type_padding) return counter_type_padding;
332  else return counter_type_unknown;
333  }
334  // returns the index of the counter within its own group
335  // for instance get_counter_type_pos(10) should return 0 as this is
336  // the first counter in the tsu_el group
337 static uint32_t get_counter_type_pos(uint32_t bit_idx) {
338  if (bit_idx < counter_type_tsu_wu) return bit_idx;
339  else if (bit_idx < counter_type_tsu_el) return (bit_idx - counter_type_tsu_wu);
340  else if (bit_idx < counter_type_tsu_extra) return (bit_idx - counter_type_tsu_el);
341  else if (bit_idx < counter_type_tsu_nu) return (bit_idx - counter_type_tsu_extra);
342  else if (bit_idx < counter_type_tsu_sl) return (bit_idx - counter_type_tsu_nu);
343  else if (bit_idx < counter_type_tsu_nl) return (bit_idx - counter_type_tsu_sl);
344  else if (bit_idx < counter_type_tsu_su) return (bit_idx - counter_type_tsu_nl);
345  else if (bit_idx < counter_type_bsu_rm) return (bit_idx - counter_type_tsu_su);
346  else if (bit_idx < counter_type_bsu_cu) return (bit_idx - counter_type_bsu_rm);
347  else if (bit_idx == (counter_type_bsu_extra-1)) return 0;
348  else if (bit_idx < counter_type_bsu_cl1) return (bit_idx - counter_type_bsu_cu);
349  // -- offset the extra position that is unused in between
350  else if (bit_idx < counter_type_bsu_cl2) return (bit_idx - counter_type_bsu_cu -1);
351  else if (bit_idx < counter_type_bsu_rl) return (bit_idx - counter_type_bsu_cl2);
352  else if (bit_idx < counter_type_padding) return (bit_idx - counter_type_bsu_rl);
353  else return counter_type_unknown;
354 
355 }
356 
357 };
358 
359 /// Trigger description
361  typedef uint32_t trigger_type_t;
362  typedef uint16_t data_size_t;
363 
364  // The 16 lsb are padding. No information is passed there
365  trigger_type_t padding_low : 8;
366 
367  // This is to be remapped so that calib words can be OR-ed with
368  // calibration words
369  // [8 : t_type][4 : muon_type][4 : calib type]
370  trigger_type_t trigger_id_ext : 4;
371  trigger_type_t trigger_id_calib: 4; // which of the calibration channels
372  trigger_type_t trigger_id_muon : 8; // which of the muon triggers
373  trigger_type_t trigger_type : 5; // the 5 msb are the trigger type
374  trigger_type_t padding_high : 3; // this makes the information byte aligned
375 
376  static data_size_t const num_bits_padding_low = 8;
377  static data_size_t const num_bits_trigger_id_ext = 4;
378  static data_size_t const num_bits_trigger_id_calib= 4;
379  static data_size_t const num_bits_trigger_id_muon = 8;
380  static data_size_t const num_bits_trigger_type = 5;
381  static data_size_t const num_bits_padding_high = 3;
382 
383  // The logic below this point is a bit different since now multiple
384  // triggers can be ID-ed in the same word
385  // Better to ask for specific types
386 
387 
388  // ID the trigger types for figure reference
389  // The logic is flawed. Need to look at this otherwise
390  /** Old map
391  static trigger_type_t const calibration = 0x00; //00000
392  static trigger_type_t const muon = 0x10; //10000
393  static trigger_type_t const ssp = 0x08; //01000
394  // -- This should probably be split into RCE and then RCE types
395  static trigger_type_t const rce_1 = 0x01; //00001
396  static trigger_type_t const rce_2 = 0x02; //00010
397  static trigger_type_t const rce_12 = 0x03; //00011
398  static trigger_type_t const rce_3 = 0x04; //00100
399  static trigger_type_t const rce_13 = 0x05; //00101
400  static trigger_type_t const rce_23 = 0x06; //00110
401  static trigger_type_t const rce_123 = 0x07; //00111
402  **/
403  static trigger_type_t const muon = 0x10; //10000
404  static trigger_type_t const external = 0x08; //01000
405  static trigger_type_t const calibration = 0x04; //00100
406 
407  // -- This should probably be split into RCE and then RCE types
408  // External trigger types
409  static trigger_type_t const I01_08 = 0x8; //1000
410  static trigger_type_t const ssp = 0x8; //1000
411  static trigger_type_t const I09 = 0x4; //0100
412  static trigger_type_t const I10 = 0x2; //0010
413  static trigger_type_t const I12 = 0x1; //0001
414  // NOTE: There is no I11. It is a adead channel.
415 
416  // C1 : 1000 : 0x8
417  // C2 : 0100 : 0x4
418  // C3 : 0010 : 0x2
419  // C4 : 0001 : 0x1
420  static trigger_type_t const C1 = 0x8;
421  static trigger_type_t const C2 = 0x4;
422  static trigger_type_t const C3 = 0x2;
423  static trigger_type_t const C4 = 0x1;
424 
425  // TA : BSU RM/CL : 10000000
426  // TB : TSU SL/NU : 01000000
427  // TC : TSU SU/NL : 00100000
428  // TD : TSU EL/WU : 00010000
429  // TE : ????????? : 00001000 <-- Not implemented in FW
430  // TF : ????????? : 00000100 <-- Not implemented in FW
431  // TG : ????????? : 00000010 <-- Not implemented in FW
432  // TH : ????????? : 00000001 <-- Not implemented in FW
433  static trigger_type_t const TA = 0x80;
434  static trigger_type_t const TB = 0x40;
435  static trigger_type_t const TC = 0x20;
436  static trigger_type_t const TD = 0x10;
437  static trigger_type_t const TE = 0x08;
438  static trigger_type_t const TF = 0x04;
439  static trigger_type_t const TG = 0x02;
440  static trigger_type_t const TH = 0x01;
441 
442  static trigger_type_t const bsu_rm_cl = 0x80;
443  static trigger_type_t const tsu_sl_nu = 0x40;
444  static trigger_type_t const tsu_su_nl = 0x20;
445  static trigger_type_t const tsu_el_wu = 0x10;
446 
447  static size_t const size_bytes = sizeof(uint32_t);
448  static size_t const size_u32 = size_bytes/sizeof(uint32_t);
449 
450  // The number of u32 that have to offset from the PTB packet to grab the data that matters
451  // In this case the two lsInts are empty and can be offset
452  static size_t const ptb_offset_u32 = 2;
453  static size_t const ptb_offset_bytes = ptb_offset_u32*sizeof(uint32_t);
454 
455  // The payload position offset from the top of the frame (header + discard)
456  static size_t const payload_offset_u32 = 1+ptb_offset_u32;
457  static size_t const payload_offset_bytes = payload_offset_u32*sizeof(uint32_t);
458 
459 
460 
461  ///Bunch of auxiliary functions to help parse the word
462  ///
464  return ((trigger_type & muon) != 0x0);
465  }
467  return ((trigger_type & external) != 0x0);
468  }
470  return ((trigger_type & calibration) != 0x0);
471  }
472 
473  // -- External trigger types
474 
475  bool has_external_trigger(trigger_type_t t) {
476  return ((trigger_id_ext & t) != 0x0);
477  }
478 
480  return ((trigger_id_ext & ssp) != 0x0);
481  }
482  bool has_I09() {
483  return ((trigger_id_ext & I09) != 0x0);
484  }
485  bool has_I10() {
486  return ((trigger_id_ext & I10) != 0x0);
487  }
488  bool has_I12() {
489  return ((trigger_id_ext & I12) != 0x0);
490  }
491 
492  // calibration trigger types
493  /// Test for the different calibration types
494  ///
495 
496  bool has_calibration(trigger_type_t t) {
497  return ((trigger_id_calib & t) != 0x0);
498  }
499 
500  bool has_C1() {
501  return ((trigger_id_calib & C1) != 0);
502  }
503  bool has_C2() {
504  return ((trigger_id_calib & C2) != 0);
505  }
506  bool has_C3() {
507  return ((trigger_id_calib & C3) != 0);
508  }
509  bool has_C4() {
510  return ((trigger_id_calib & C4) != 0);
511  }
512 
513  /// Test the different muon trigger types
514  ///
515  bool has_muon_trigger(trigger_type_t t) {
516  return ((trigger_id_muon & t) != 0x0);
517  }
518  ///
519  bool has_muon_TA() {
520  return ((trigger_id_muon & TA) != 0);
521  }
522  bool has_muon_TB() {
523  return ((trigger_id_muon & TB) != 0);
524  }
525  bool has_muon_TC() {
526  return ((trigger_id_muon & TC) != 0);
527  }
528  bool has_muon_TD() {
529  return ((trigger_id_muon & TD) != 0);
530  }
531  bool has_muon_TE() {
532  return ((trigger_id_muon & TE) != 0);
533  }
534  bool has_muon_TF() {
535  return ((trigger_id_muon & TF) != 0);
536  }
537  bool has_muon_TG() {
538  return ((trigger_id_muon & TG) != 0);
539  }
540  bool has_muon_TH() {
541  return ((trigger_id_muon & TH) != 0);
542  }
543 
544  /// Test the different muon trigger types
545  ///
547  return ((trigger_id_muon & bsu_rm_cl) != 0);
548  }
550  return ((trigger_id_muon & tsu_sl_nu) != 0);
551  }
553  return ((trigger_id_muon & tsu_su_nl) != 0);
554  }
556  return ((trigger_id_muon & tsu_el_wu) != 0);
557  }
558 
559 
560  // Add a function that can be used to parse the trigger payload
561  //FIXME: This should be considered obsolete and removed
562  // in a near future
563 
564  static std::string getTriggerTypeName(trigger_type_t trigger_type) {
565  switch (trigger_type) {
566  case calibration:
567  return "calibration";
568  break;
569  case external:
570  return "external";
571  break;
572  case muon :
573  return "muon";
574  break;
575  default:
576  return "unknown";
577  break;
578  }
579  return "";
580  }
581 };
582 
584  typedef uint64_t timestamp_t;
585  typedef uint16_t data_size_t;
586  timestamp_t nova_timestamp : 64;
587 
588  static data_size_t const num_bits_timestamp = 64;
589  static size_t const size_bytes = sizeof(uint64_t);
590  static size_t const size_u32 = size_bytes/sizeof(uint32_t);
591  // drop 1 int
592  static size_t const ptb_offset_u32 = 1;
593  static size_t const ptb_offset_bytes = ptb_offset_u32*sizeof(uint32_t);
594  // The payload position offset from the top of the frame (header + discard)
595 
596  static size_t const payload_offset_u32 = 1+ptb_offset_u32;
597  static size_t const payload_offset_bytes = payload_offset_u32*sizeof(uint32_t);
598 
599 };
600 
601 #endif /*PENN_OLD_STRUCTS*/
602 
604 
605  //the size of the payloads (neglecting the Payload_Header)
606 
607  static microslice_size_t const payload_size_counter = 4 * sizeof(uint32_t); //128-bit payload
608  static microslice_size_t const payload_size_trigger = 1 * sizeof(uint32_t); //32-bit payload
609  static microslice_size_t const payload_size_timestamp = 2 * sizeof(uint32_t); //64-bit payload
610  static microslice_size_t const payload_size_warning = 0 * sizeof(uint32_t); //0-bit payload (just header)
611  static microslice_size_t const payload_size_checksum = 0 * sizeof(uint32_t); //0-bit payload (just header)
612 
613 
614  //The types of data words
620 
621 
622  //The types of data words
623  static const Warning_Word::warning_type_t WarnUnknownDataType = 0x02; //0b00010
624  static const Warning_Word::warning_type_t WarnTimeout = 0x04; //0b00100
625  static const Warning_Word::warning_type_t WarnFIFOHalfFull = 0x08; //0b01000
626  static const Warning_Word::warning_type_t WarnFIFOFull = 0x10; //0b10000
627 
628 
629  // This constructor accepts a memory buffer that contains an existing
630  // microSlice and allows the the data inside it to be accessed
631  PennMicroSlice(uint8_t* address);
632 
633  // Get the contents of a payload
634  // Why is everything worked in bytes and not 32 bit units?
635  uint8_t* get_payload(uint32_t word_id, Payload_Header::data_packet_type_t& data_packet_type, Payload_Header::short_nova_timestamp_t& short_nova_timestamp, size_t& size, bool swap_payload_header_bytes, size_t override_uslice_size = 0) const;
636  // Get the contents of the next payload
637  //JPD -- get_payload is inefficient for user code use - it has to loop through (i) payloads to get the (ith) payload. This function increments the current_payload_ pointer to the next payload, and returns nullptr when off the end
638  uint8_t* get_next_payload(uint32_t &word_id, Payload_Header::data_packet_type_t& data_packet_type, Payload_Header::short_nova_timestamp_t& short_nova_timestamp, size_t& size, bool swap_payload_header_bytes, size_t override_uslice_size = 0);
639 
640  // Returns the format version field from the header
642 
643  // Returns the sequence ID field from the header
645 
646  // Returns the block size field from the header
648 
649  // Returns the size of the PennMicroSlice
651 
652  // Returns the number of samples in the microslice
653 
654  typedef uint32_t sample_count_t;
655 
656  sample_count_t sampleCount(sample_count_t &n_counter_words, sample_count_t &n_trigger_words,
657  sample_count_t &n_timestamp_words,
658  sample_count_t &n_selftest_words, sample_count_t &n_checksum_words,
659  bool swap_payload_header_bytes, size_t override_uslice_size = 0) const;
660 
661  // Returns a pointer to the first payload_header in data that has a
662  // time after boundary_time (returns 0 if that doesn't exist) also
663  // sets remaining_size - the size of data that is after
664  // boundary_time
665 
666  uint8_t* sampleTimeSplit(uint64_t boundary_time, size_t& remaining_size, bool swap_payload_header_bytes,
667  size_t override_uslice_size = 0) const;
668 
669  // Returns a pointer to the first payload_header in data that has a
670  // time after boundary_time (returns 0 if that doesn't exist) also
671  // sets remaining_size - the size of data that is after
672  // boundary_time and counts payloads before & after the time NOTE
673  // this is prefered to calling sampleCount() and sampleTimeSplit()
674  // separately, as it loops through the data exactly once (instead of
675  // between once & exactly twice)
676 
677  uint8_t* sampleTimeSplitAndCount(uint64_t boundary_time, size_t& remaining_size,
678  sample_count_t &n_words_b, sample_count_t &n_counter_words_b,
679  sample_count_t &n_trigger_words_b,
680  sample_count_t &n_timestamp_words_b, sample_count_t &n_selftest_words_b,
681  sample_count_t &n_checksum_words_b,
682  sample_count_t &n_words_a, sample_count_t &n_counter_words_a,
683  sample_count_t &n_trigger_words_a,
684  sample_count_t &n_timestamp_words_a, sample_count_t &n_selftest_words_a,
685  sample_count_t &n_checksum_words_a,
686  bool swap_payload_header_bytes,
687  size_t override_uslice_size = 0) const;
688 
689  // As sampleTimeSplitAndCount, but also gets information for a second time (overlap_time), in the same loop
690 
691  uint8_t* sampleTimeSplitAndCountTwice(uint64_t boundary_time, size_t& remaining_size,
692  uint64_t overlap_time, size_t& overlap_size, uint8_t*& overlap_data_ptr,
693  sample_count_t &n_words_b, sample_count_t &n_counter_words_b,
694  sample_count_t &n_trigger_words_b,
695  sample_count_t &n_timestamp_words_b, sample_count_t &n_selftest_words_b,
696  sample_count_t &n_checksum_words_b,
697  sample_count_t &n_words_a, sample_count_t &n_counter_words_a,
698  sample_count_t &n_trigger_words_a,
699  sample_count_t &n_timestamp_words_a, sample_count_t &n_selftest_words_a,
700  sample_count_t &n_checksum_words_a,
701  sample_count_t &n_words_o, sample_count_t &n_counter_words_o,
702  sample_count_t &n_trigger_words_o,
703  sample_count_t &n_timestamp_words_o, sample_count_t &n_selftest_words_o,
704  sample_count_t &n_checksum_words_o,
705  uint32_t &checksum,
706  bool swap_payload_header_bytes, size_t override_uslice_size = 0) const;
707 
708  //Values used to handle the rollover.
709  //The width of the millislice should be:
710  // LESS than the ROLLOVER_LOW_VALUE
711  // LESS than (max of a uint28_t - ROLLOVER_HIGH_VALUE)
712  // NFB : Not sure I understand this logic
713  static const uint32_t ROLLOVER_LOW_VALUE = 1 << 13; //8192 ticks = 0.128ms
714  //static const uint32_t ROLLOVER_HIGH_VALUE = 1 << 26;
715  static const uint64_t ROLLOVER_HIGH_VALUE = (1 << 27) -1;
716 
717 
718 
719  static uint64_t getMask(int param){
720  uint64_t mask=0;
721  mask = (1 << param) - 1;//sets the mask to 0000...11111...11
722  return mask;
723  };
724 
725  uint32_t* raw() const;
726 
727 protected:
728 
729  // returns a pointer to the header
730  Header const* header_() const;
731 
732  // returns a pointer to the first sample word
733  uint32_t const* data_() const;
734 
735  uint8_t* buffer_;
738 };
739 
740 #endif /* dune_artdaq_Overlays_PennMicroSlice_hh */
static microslice_size_t const payload_size_trigger
static uint64_t getMask(int param)
static microslice_size_t const payload_size_timestamp
static const Warning_Word::warning_type_t WarnFIFOHalfFull
class C3 in group 2
Definition: group.cpp:35
static const Payload_Header::data_packet_type_t DataTypeWarning
std::string string
Definition: nybbler.cc:12
bool has_calibration(trigger_type_t t)
static microslice_size_t const payload_size_checksum
Counter payload description.
uint8_t * get_payload(uint32_t word_id, Payload_Header::data_packet_type_t &data_packet_type, Payload_Header::short_nova_timestamp_t &short_nova_timestamp, size_t &size, bool swap_payload_header_bytes, size_t override_uslice_size=0) const
static const uint64_t ROLLOVER_HIGH_VALUE
bool get_counter_status(uint32_t idx) const
static data_size_t const num_bits_format
static const Payload_Header::data_packet_type_t DataTypeTimestamp
static data_size_t const num_bits_sequence_id
static size_t const size_words
sample_count_t sampleCount(sample_count_t &n_counter_words, sample_count_t &n_trigger_words, sample_count_t &n_timestamp_words, sample_count_t &n_selftest_words, sample_count_t &n_checksum_words, bool swap_payload_header_bytes, size_t override_uslice_size=0) const
uint64_t get_full_timestamp_post(uint64_t ts_ref)
static microslice_size_t const payload_size_counter
Header const * header_() const
bool has_external_trigger(trigger_type_t t)
bool has_muon_trigger(trigger_type_t t)
static const Warning_Word::warning_type_t WarnUnknownDataType
PennMicroSlice(uint8_t *address)
Header::block_size_t microslice_size_t
dune::PennMicroSlice::microslice_size_t size() const
static const Payload_Header::data_packet_type_t DataTypeChecksum
uint8_t * sampleTimeSplitAndCountTwice(uint64_t boundary_time, size_t &remaining_size, uint64_t overlap_time, size_t &overlap_size, uint8_t *&overlap_data_ptr, sample_count_t &n_words_b, sample_count_t &n_counter_words_b, sample_count_t &n_trigger_words_b, sample_count_t &n_timestamp_words_b, sample_count_t &n_selftest_words_b, sample_count_t &n_checksum_words_b, sample_count_t &n_words_a, sample_count_t &n_counter_words_a, sample_count_t &n_trigger_words_a, sample_count_t &n_timestamp_words_a, sample_count_t &n_selftest_words_a, sample_count_t &n_checksum_words_a, sample_count_t &n_words_o, sample_count_t &n_counter_words_o, sample_count_t &n_trigger_words_o, sample_count_t &n_timestamp_words_o, sample_count_t &n_selftest_words_o, sample_count_t &n_checksum_words_o, uint32_t &checksum, bool swap_payload_header_bytes, size_t override_uslice_size=0) const
static const Payload_Header::data_packet_type_t DataTypeTrigger
class C2 in group 1
Definition: group.cpp:10
static data_size_t get_counter_type(uint32_t bit_idx)
Frame header : Common header to everything except warning words.
static std::string getTriggerTypeName(trigger_type_t trigger_type)
uint32_t * raw() const
uint32_t const * data_() const
static const Warning_Word::warning_type_t WarnTimeout
Header of ethernet packet.
static uint32_t get_counter_type_pos(uint32_t bit_idx)
class C4 in group 2
Definition: group.cpp:40
static const Warning_Word::warning_type_t WarnFIFOFull
uint8_t * get_next_payload(uint32_t &word_id, Payload_Header::data_packet_type_t &data_packet_type, Payload_Header::short_nova_timestamp_t &short_nova_timestamp, size_t &size, bool swap_payload_header_bytes, size_t override_uslice_size=0)
static const uint32_t ROLLOVER_LOW_VALUE
static data_size_t const num_bits_size
uint64_t get_full_timestamp_pre(uint64_t ts_ref)
class C1 in group 1
Definition: group.cpp:7
static microslice_size_t const payload_size_warning
static const Payload_Header::data_packet_type_t DataTypeCounter
uint8_t * sampleTimeSplit(uint64_t boundary_time, size_t &remaining_size, bool swap_payload_header_bytes, size_t override_uslice_size=0) const
uint8_t * sampleTimeSplitAndCount(uint64_t boundary_time, size_t &remaining_size, sample_count_t &n_words_b, sample_count_t &n_counter_words_b, sample_count_t &n_trigger_words_b, sample_count_t &n_timestamp_words_b, sample_count_t &n_selftest_words_b, sample_count_t &n_checksum_words_b, sample_count_t &n_words_a, sample_count_t &n_counter_words_a, sample_count_t &n_trigger_words_a, sample_count_t &n_timestamp_words_a, sample_count_t &n_selftest_words_a, sample_count_t &n_checksum_words_a, bool swap_payload_header_bytes, size_t override_uslice_size=0) const