LCOV - code coverage report
Current view: top level - ctbmodules/src - CTBPacketContent.hpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 4 0
Test Date: 2026-10-11 15:05:20 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /*
       2              :  * CTBPacketContent.hpp
       3              :  *
       4              :  * Ported from
       5              :  * https://cdcvs.fnal.gov/redmine/projects/dune-raw-data/repository/revisions/develop/entry/dune-raw-data/Overlays/CTB_content.h
       6              :  *
       7              :  * Developer: willpvazquez (27 July 2022)
       8              :  *
       9              :  *  Originally Created on: Oct 8, 2017
      10              :  *      Author: nbarros
      11              :  */
      12              : 
      13              : #ifndef CTBMODULES_SRC_CTBPACKETCONTENT_HPP_
      14              : #define CTBMODULES_SRC_CTBPACKETCONTENT_HPP_
      15              : 
      16              : #include <cstdint>
      17              : 
      18              : namespace dunedaq {
      19              : namespace ctbmodules {
      20              : namespace content {
      21              : 
      22              : // NFB: Note that order denotes bit order in the word:
      23              : //      Upper fields are in the lsb and lower field is in the msb
      24              : /// Internal buffer definition
      25              : ///
      26              : // static uint8_t format_version = 0x2;
      27              : 
      28              : typedef struct buffer_t
      29              : {
      30              :   int handle;
      31              :   size_t len;
      32              : } buffer_t;
      33              : 
      34              : ///
      35              : /// -- TCP header
      36              : ///
      37              : 
      38              : typedef struct tcp_header_t
      39              : {
      40              :   typedef uint16_t pkt_size_t;
      41              :   typedef uint8_t seq_size_t;
      42              :   typedef uint8_t ver_size_t;
      43              :   uint16_t packet_size : 16; // Size of the data content in bytes
      44              :   uint8_t sequence_id : 8;   // packet order...rotates every 256
      45              :   uint8_t format_version : 8;
      46              :   static size_t const size_bytes = sizeof(uint32_t);
      47              :   static size_t const n_bits_size = 16;
      48              :   static size_t const n_bits_sequence_id = 8;
      49              :   static size_t const n_bits_version = 8;
      50              : } tcp_header_t;
      51              : 
      52              : // NFB: Careful with unions. Setting one member and then accessing another
      53              : // is undefined behavior in C++.
      54              : // However, I have tested that they work on gcc on the PTB
      55              : 
      56              : typedef union tcp_header
      57              : {
      58              :   tcp_header_t word;
      59              :   uint32_t value;
      60              : } tcp_header;
      61              : 
      62              : namespace word {
      63              : enum word_type
      64              : {
      65              :   t_fback = 0x0,
      66              :   t_lt = 0x1,
      67              :   t_gt = 0x2,
      68              :   t_ch = 0x3,
      69              :   t_chksum = 0x4,
      70              :   t_ts = 0x7
      71              : };
      72              : ///
      73              : /// -- payload
      74              : ///
      75              : // -- The body of a word is composed of 12 bytes
      76              : typedef uint16_t trigger_code_t;
      77              : ///
      78              : /// N. Barros - May 7, 2018 : Changed the structure of the parsing
      79              : ///
      80              : /// Now all structures cast into 16 bytes, but declare different
      81              : /// bit fields to interpret each frame in the context of its respective type
      82              : ///
      83              : /// Also, to move into a format where the full timestamp is stored, the full timestamp
      84              : /// is now placed in the 64 lsb, instead of the msb. Does complies with the memory alignment
      85              : /// and simplifies the parsing of the structures
      86              : ///
      87              : 
      88              : typedef struct word_t
      89              : {
      90              :   typedef uint64_t ts_size_t;
      91              :   typedef uint64_t pad_size_t;
      92              :   typedef uint64_t word_type_t;
      93              :   ts_size_t timestamp;
      94              :   pad_size_t payload : 61;
      95              :   word_type_t word_type : 3;
      96              :   static size_t const size_bytes = 4 * sizeof(uint32_t);
      97              :   static size_t const size_u32 = 4 * sizeof(uint32_t) / sizeof(uint32_t);
      98              :   static size_t const n_bits_timestamp = 64;
      99              :   static size_t const n_bits_payload = 61;
     100              :   static size_t const n_bits_type = 3;
     101              : } word_t;
     102              : 
     103              : typedef union word
     104              : {
     105              :   word_t frame;
     106              :   uint8_t* get_bytes() { return reinterpret_cast<uint8_t*>(&frame); }
     107              : } word;
     108              : 
     109              : /// -- Several different structures that can be used to reinterpret the payload depending on
     110              : /// the word type. All these structures map into the full 16 bytes of the CTB words
     111              : ///
     112              : 
     113              : typedef struct feedback_t
     114              : {
     115              :   typedef uint64_t ts_size_t;
     116              :   typedef uint16_t code_size_t;
     117              :   typedef uint16_t source_size_t;
     118              :   typedef uint32_t wtype_size_t;
     119              :   typedef uint32_t pad_size_t;
     120              :   ts_size_t timestamp;
     121              :   code_size_t code : 16;
     122              :   source_size_t source : 16;
     123              :   pad_size_t padding : 29;
     124              :   wtype_size_t word_type : 3;
     125              :   static size_t const size_bytes = 2 * sizeof(uint64_t);
     126              :   static size_t const size_u32 = size_bytes / sizeof(uint32_t);
     127              :   static size_t const n_bits_timestamp = 64;
     128              :   static size_t const n_bits_payload = 32;
     129              :   static size_t const n_bits_type = 3;
     130              : } feedback_t;
     131              : 
     132              : typedef struct ch_status_t
     133              : {
     134              :   typedef uint64_t ts_size_t;
     135              :   typedef uint64_t pds_size_t;
     136              :   typedef uint64_t crt_size_t;
     137              :   typedef uint64_t beam_size_t;
     138              :   typedef uint64_t wtype_size_t;
     139              :   ts_size_t timestamp : 60;
     140              :   beam_size_t beam_lo : 4;
     141              :   beam_size_t beam_hi : 12;
     142              :   crt_size_t crt : 32;
     143              :   pds_size_t pds : 17;
     144              :   wtype_size_t word_type : 3;
     145              :   static size_t const size_bytes = 2 * sizeof(uint64_t);
     146              :   static size_t const size_u32 = size_bytes / sizeof(uint32_t);
     147              :   static size_t const n_bits_timestamp = 60;
     148              :   static size_t const n_bits_payload = 32;
     149              :   static size_t const n_bits_type = 3;
     150              : 
     151              :   // aux_functions
     152            0 :   beam_size_t get_beam() const { return (beam_hi << 4 | beam_lo); }
     153            0 :   crt_size_t get_crt() const { return (crt & 0xFFFFFFFF); }
     154            0 :   pds_size_t get_pds() const { return (pds & 0x1FFFF); }
     155              : 
     156              :   bool get_state_crt(const uint16_t channel) { return ((crt & (0x1 << channel)) != 0x0); }
     157              : 
     158              :   bool get_state_pds(const uint16_t channel) { return ((pds & (0x1 << channel)) != 0x0); }
     159              : 
     160              :   bool get_state_beam(const uint16_t channel) { return (((beam_hi << 4 | beam_lo) & (0x1 << channel)) != 0x0); }
     161              : } ch_status_t;
     162              : 
     163              : typedef struct timestamp_t
     164              : {
     165              :   typedef uint64_t ts_size_t;
     166              :   typedef uint64_t pad_size_t;
     167              :   typedef uint64_t wtype_size_t;
     168              :   ts_size_t timestamp;
     169              :   pad_size_t padding : 61;
     170              :   wtype_size_t word_type : 3;
     171              :   static size_t const size_bytes = 2 * sizeof(uint64_t);
     172              :   static size_t const size_u32 = size_bytes / sizeof(uint32_t);
     173              :   static size_t const n_bits_timestamp = 64;
     174              :   static size_t const n_bits_unused = 61;
     175              :   static size_t const n_bits_type = 3;
     176              : } timestamp_t;
     177              : 
     178              : typedef struct trigger_t
     179              : {
     180              :   typedef uint64_t ts_size_t;
     181              :   typedef uint64_t mask_size_t;
     182              :   typedef uint64_t wtype_size_t;
     183              :   ts_size_t timestamp;
     184              :   mask_size_t trigger_word : 61;
     185              :   wtype_size_t word_type : 3;
     186              :   static size_t const size_bytes = 2 * sizeof(uint64_t);
     187              :   static size_t const size_u32 = size_bytes / sizeof(uint32_t);
     188              :   static size_t const n_bits_timestamp = 64;
     189              :   static size_t const n_bits_tmask = 61;
     190              :   static size_t const n_bits_type = 3;
     191              : 
     192            0 :   bool IsHLT() const { return word_type == word_type::t_gt; }
     193              :   bool IsLLT() const { return word_type == word_type::t_lt; }
     194              :   bool IsTrigger(const unsigned int i) const
     195              :   {
     196              :     if (IsHLT())
     197              :       return trigger_word & (0x1 << i);
     198              :     if (IsLLT())
     199              :       return i == 0 ? false : trigger_word & (0x1 << (i - 1));
     200              :     return false;
     201              :   }
     202              : } trigger_t;
     203              : 
     204              : } // -- namespace word
     205              : } // -- namespace content
     206              : } // -- namespace ctbmodules
     207              : } // -- namespace dunedaq
     208              : 
     209              : #endif /* CTBMODULES_SRC_CTBPACKETCONTENT_HPP_  */
        

Generated by: LCOV version 2.0-1