Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:55

0001 // @file mvtx_utils.h
0002 // @brief Declarations of helper classes for the MVTX
0003 
0004 #ifndef MVTXDECODER_UTILS_H
0005 #define MVTXDECODER_UTILS_H
0006 
0007 #include <cassert>
0008 #include <cstdint>
0009 #include <iostream>
0010 
0011 namespace mvtx_utils
0012 {
0013 
0014 #define clean_errno() (errno == 0 ? "None" : strerror(errno))
0015 #define log_error                                         \
0016   std::cerr << "[ERROR] (" << __FILE__ << ":" << __LINE__ \
0017             << ":errno: " << clean_errno()
0018 
0019   constexpr uint8_t FLXWordLength = 32;
0020 
0021   struct RdhExt_t
0022   {
0023     // FLX header
0024     uint8_t flxId{};      // [23]
0025     uint16_t pageSize{};  // [25]
0026     uint16_t gbtLink{};
0027     uint8_t flxHdrSize{};
0028     uint16_t flxHdrVersion{};
0029     // RU header
0030     uint8_t rdhVersion{};
0031     uint8_t rdhSize{};
0032     uint16_t feeId{};
0033     uint8_t sourceId{};
0034     uint32_t detectorField{};
0035     uint16_t bc{};
0036     uint64_t orbit{};
0037     uint32_t trgType{};
0038     uint16_t packetCounter{};
0039     uint8_t stopBit{};
0040     uint8_t priority{};
0041     uint16_t rdhGBTcounter{};  // 10 bits
0042 
0043     RdhExt_t() = default;
0044     ~RdhExt_t() = default;
0045 
0046     void decode(const uint8_t *rdh_ptr)
0047     {
0048       // FELIX header
0049       flxId = *(reinterpret_cast<const uint8_t *>(rdh_ptr + 23)) & 0xFF;
0050       pageSize = *(reinterpret_cast<const uint16_t *>(rdh_ptr + 25)) & 0x7FF;
0051       gbtLink = *(reinterpret_cast<const uint16_t *>(rdh_ptr + 28)) & 0x7FF;
0052       flxHdrSize = *(reinterpret_cast<const uint8_t *>(rdh_ptr + 29)) & 0xFF;
0053       flxHdrVersion =
0054           *(reinterpret_cast<const uint16_t *>(rdh_ptr + 30)) & 0xFFFF;
0055       // RU header
0056       rdhVersion = *(reinterpret_cast<const uint8_t *>(rdh_ptr + 32)) & 0xFF;
0057       rdhSize = *(reinterpret_cast<const uint8_t *>(rdh_ptr + 33)) & 0xFF;
0058       feeId = *(reinterpret_cast<const uint16_t *>(rdh_ptr + 34)) & 0xFFFF;
0059       sourceId = *(reinterpret_cast<const uint8_t *>(rdh_ptr + 36)) & 0xFF;
0060       detectorField =
0061           *(reinterpret_cast<const uint32_t *>(rdh_ptr + 37)) & 0xFFFFFFFF;
0062       bc = *(reinterpret_cast<const uint16_t *>(rdh_ptr + 42)) & 0xFFF;
0063       orbit = *(reinterpret_cast<const uint64_t *>(rdh_ptr + 46)) & 0xFFFFFFFFFF;
0064       trgType = *(reinterpret_cast<const uint32_t *>(rdh_ptr + 52)) & 0xFFFFFFFF;
0065       packetCounter =
0066           *(reinterpret_cast<const uint16_t *>(rdh_ptr + 56)) & 0xFFFF;
0067       stopBit = *(reinterpret_cast<const uint8_t *>(rdh_ptr + 58)) & 0xFF;
0068       priority = *(reinterpret_cast<const uint8_t *>(rdh_ptr + 59)) & 0xFF;
0069       rdhGBTcounter =
0070           *(reinterpret_cast<const uint16_t *>(rdh_ptr + 62)) & 0xFFFF;
0071     }
0072 
0073     bool checkRDH(const bool verbose)
0074     {
0075       // check if rdh conform with RDH8 fields
0076       bool ok = true;
0077       if (flxHdrSize != 0x20)
0078       {
0079         if (verbose)
0080         {
0081           std::cout << "RDH FLX Header Size 0x20 is expected instead of "
0082                     << int(flxHdrSize) << std::endl;
0083         }
0084         ok = false;
0085       }
0086 
0087       if (flxHdrVersion != 0xAB01)
0088       {
0089         if (verbose)
0090         {
0091           std::cout << "RDH FLX Header version 0x01AB is expected instead of "
0092                     << int(flxHdrVersion) << std::endl;
0093         }
0094         ok = false;
0095       }
0096 
0097       if (rdhVersion != 0x08)
0098       {
0099         if (verbose)
0100         {
0101           std::cout << "RDH version 8 is expected instead of " << int(rdhVersion)
0102                     << std::endl;
0103         }
0104         ok = false;
0105       }
0106 
0107       if (rdhSize != 32)
0108       {
0109         if (verbose)
0110         {
0111           std::cout << "RDH with header size of 64 B is expected instead of "
0112                     << int(rdhSize) << std::endl;
0113         }
0114         ok = false;
0115       }
0116 
0117       return ok;
0118     }
0119   };
0120 
0121   template <typename A, typename B>
0122   bool comp(A a, B b)
0123   {
0124     return a.second < b.second;
0125   }
0126 
0127 }  // namespace mvtx_utils
0128 
0129 #endif