EUDAQ
 All Classes Namespaces Files Functions Variables Pages
ATLASFE4IInterpreter.hh
1 #ifndef ATLASFE4IINTERPRETER_H
2 #define ATLASFE4IINTERPRETER_H
3 
4 #include <bitset>
5 typedef unsigned int uint;
6 
7 /*FEI4A
8  * DATA_HEADER_LV1ID_MASK 0x00007F00
9  * DATA_HEADER_BCID_MASK 0x000000FF
10  *
11  *FEI4B
12  * DATA_HEADER_LV1ID_MASK 0x00007C00
13  * DATA_HEADER_BCID_MASK 0x000003FF
14  */
15 
16 namespace eudaq {
17 
18  template <uint dh_lv1id_msk, uint dh_bcid_msk> class ATLASFEI4Interpreter {
19  protected:
20  //-----------------
21  // Data Header (dh)
22  //-----------------
23  static const uint dh_wrd = 0x00E90000;
24  static const uint dh_msk = 0xFFFF0000;
25  static const uint dh_flag_msk = 0x00008000;
26 
27  inline bool is_dh(uint X) const { return (dh_msk & X) == dh_wrd; }
28  inline uint get_dh_flag(uint X) const { return (dh_flag_msk & X) >> 15; }
29  inline bool is_dh_flag_set(uint X) const {
30  return (dh_flag_msk & X) == dh_flag_msk;
31  }
32  // inline uint get_dh_lv1id(uint X) const {return (dh_lv1id_msk & X) >>
33  //determineShift(dh_lv1id_msk);}
34  inline uint get_dh_lv1id(uint X) const {
35  return (dh_lv1id_msk & X) >> myBitMask<dh_lv1id_msk>::shiftValue;
36  }
37  inline uint get_dh_bcid(uint X) const { return (dh_bcid_msk & X); }
38 
39  //-----------------
40  // Data Record (dr)
41  //-----------------
42  static const uint dr_col_msk = 0x00FE0000;
43  static const uint dr_row_msk = 0x0001FF00;
44  static const uint dr_tot1_msk = 0x000000F0;
45  static const uint dr_tot2_msk = 0x0000000F;
46 
47  // limits of FE-size
48  static const uint rd_min_col = 1;
49  static const uint rd_max_col = 80;
50  static const uint rd_min_row = 1;
51  static const uint rd_max_row = 336;
52 
53  // the limits shifted for easy verification with a dr
54  static const uint dr_min_col = rd_min_col << 17;
55  static const uint dr_max_col = rd_max_col << 17;
56  static const uint dr_min_row = rd_min_row << 8;
57  static const uint dr_max_row = rd_max_row << 8;
58 
59  inline bool is_dr(uint X) const {
60  // check if hit is within limits of FE size
61  return (((dr_col_msk & X) <= dr_max_col) &&
62  ((dr_col_msk & X) >= dr_min_col) &&
63  ((dr_row_msk & X) <= dr_max_row) &&
64  ((dr_row_msk & X) >= dr_min_row));
65  }
66 
67  inline uint get_dr_col1(uint X) const { return (dr_col_msk & X) >> 17; }
68  inline uint get_dr_row1(uint X) const { return (dr_row_msk & X) >> 8; }
69  inline uint get_dr_tot1(uint X) const { return (dr_tot1_msk & X) >> 4; }
70  inline uint get_dr_col2(uint X) const { return (dr_col_msk & X) >> 17; }
71  inline uint get_dr_row2(uint X) const {
72  return ((dr_row_msk & X) >> 8) + 1;
73  }
74  inline uint get_dr_tot2(uint X) const { return (dr_tot2_msk & X); }
75 
76  //-----------------
77  // Trigger Data (tr)
78  //-----------------
79  static const uint tr_wrd_hdr_v10 = 0x00FFFF00;
80  static const uint tr_wrd_hdr_msk_v10 = 0xFFFFFF00;
81  static const uint tr_wrd_hdr = 0x00F80000; // tolerant to 1-bit flips and
82  // not equal to control/comma
83  // symbols
84  static const uint tr_wrd_hdr_msk = 0xFFFF0000;
85 
86  static const uint tr_no_31_24_msk = 0x000000FF;
87  static const uint tr_no_23_0_msk = 0x00FFFFFF;
88 
89  static const uint tr_data_msk = 0x0000FF00; // trigger error + trigger mode
90  static const uint tr_mode_msk = 0x0000E000; // trigger mode
91  static const uint tr_err_msk = 0x00001F00; // error code: bit 0: wrong
92  // number of dh, bit 1 service
93  // record recieved
94 
95  inline bool is_tr(uint X) const {
96  return ((tr_wrd_hdr_msk & X) == tr_wrd_hdr) ||
97  ((tr_wrd_hdr_msk_v10 & X) == tr_wrd_hdr_v10);
98  }
99 
100  inline uint get_tr_no_2(uint X, uint Y) const {
101  return ((tr_no_31_24_msk & X) << 24) | (tr_no_23_0_msk & Y);
102  }
103  inline bool get_tr_err_occurred(uint X) const {
104  return (((tr_err_msk & X) >> 8) == 0x0) ||
105  ((tr_wrd_hdr_msk_v10 & X) == tr_wrd_hdr_v10);
106  }
107 
108  inline uint get_tr_data(uint X) const { return (tr_data_msk & X) >> 8; }
109  inline uint get_tr_err(uint X) const { return (tr_err_msk & X) >> 8; }
110  inline uint get_tr_mode(uint X) const { return (tr_mode_msk & X) >> 13; }
111 
112  // determine necessary bitshift from a bitmask
113  /* constexpr uint determineShift(uint mask) const
114  {
115  uint count = 0;
116  std::bitset<32> maskField(mask);
117 
118  while(maskField[count] != true)
119  {
120  count++;
121  }
122  return count;
123  }
124  */
125  template <uint bitmask> struct myBitMask {
126  static uint getShift() {
127  uint count = 0;
128  std::bitset<32> maskField(bitmask);
129 
130  while (maskField[count] != true) {
131  count++;
132  }
133  return count;
134  }
135 
136  enum { shiftValue = getShift() };
137  };
138 
139  }; // class ATLASFEI4Interpreter
140 
141 } // namespace eudaq
142 
143 #endif // ATLASFE4IINTERPRETER_H
Definition: ATLASFE4IInterpreter.hh:125
Definition: ATLASFE4IInterpreter.hh:18