Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mvtx_utils.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file mvtx_utils.h
1 // @file mvtx_utils.h
2 // @brief Declarations of helper classes for the MVTX
3 
4 #ifndef MVTXDECODER_UTILS_H
5 #define MVTXDECODER_UTILS_H
6 
7 #include <cstdint>
8 #include <cassert>
9 
10 namespace mvtx_utils
11 {
12 
13 #define clean_errno() (errno == 0 ? "None" : strerror(errno))
14 #define log_error std::cerr << "[ERROR] (" << __FILE__ << ":" << __LINE__ << ":errno: " << clean_errno()
15 
16  constexpr uint8_t FLXWordLength = 32;
17 
18  struct RdhExt_t
19  {
20  // FLX header
21  uint8_t flxId; // [23]
22  uint16_t pageSize; // [25]
23  uint16_t gbtLink;
24  uint16_t flxHdrSize;
25  uint16_t flxHdrVersion;
26  // RU header
27  uint8_t rdhVersion;
28  uint8_t rdhSize;
29  uint16_t feeId;
30  uint8_t sourceId;
31  uint32_t detectorField;
32  uint16_t bc;
33  uint64_t orbit;
34  uint32_t trgType;
35  uint16_t packetCounter;
36  uint8_t stopBit;
37  uint8_t priority;
38  uint16_t rdhGBTcounter; // 10 bits
39 
40  RdhExt_t() = default;
41  ~RdhExt_t() = default;
42 
43  void decode(const uint8_t* rdh_ptr)
44  {
45  // FELIX header
46  flxId = *(reinterpret_cast<const uint8_t*>(rdh_ptr + 23) ) & 0xFF;
47  pageSize = *(reinterpret_cast<const uint16_t*>(rdh_ptr + 25) ) & 0x7FF;
48  gbtLink = *(reinterpret_cast<const uint16_t*>(rdh_ptr + 28) ) & 0x7FF;
49  flxHdrSize = *(reinterpret_cast<const uint16_t*>(rdh_ptr + 29) ) & 0x7FF;
50  flxHdrVersion = *(reinterpret_cast<const uint16_t*>(rdh_ptr + 30) ) & 0xFFFF;
51  // RU header
52  rdhVersion = *(reinterpret_cast<const uint8_t*>(rdh_ptr + 32) ) & 0xFF;
53  rdhSize = *(reinterpret_cast<const uint8_t*>(rdh_ptr + 33) ) & 0xFF;
54  feeId = *(reinterpret_cast<const uint16_t*>(rdh_ptr + 34) ) & 0xFFFF;
55  sourceId = *(reinterpret_cast<const uint8_t*>(rdh_ptr + 36) ) & 0xFF;
56  detectorField = *(reinterpret_cast<const uint32_t*>(rdh_ptr + 37) ) & 0xFFFFFFFF;
57  bc = *(reinterpret_cast<const uint16_t*>(rdh_ptr + 42) ) & 0xFFF;
58  orbit = *(reinterpret_cast<const uint64_t*>(rdh_ptr + 46) ) & 0xFFFFFFFFFF;
59  trgType = *(reinterpret_cast<const uint32_t*>(rdh_ptr + 52) ) & 0xFFFFFFFF;
60  packetCounter = *(reinterpret_cast<const uint16_t*>(rdh_ptr + 56) ) & 0xFFFF;
61  stopBit = *(reinterpret_cast<const uint8_t*>(rdh_ptr + 58) ) & 0xFF;
62  priority = *(reinterpret_cast<const uint8_t*>(rdh_ptr + 59) ) & 0xFF;
63  rdhGBTcounter = *(reinterpret_cast<const uint16_t*>(rdh_ptr + 62) ) & 0xFFFF;
64  }
65  };
66 
67  template < typename A, typename B >
68  bool comp(A a, B b)
69  {
70  return a.second < b.second;
71  }
72 
73 } //namespace mvtx_utils
74 
75 #endif