File indexing completed on 2025-08-06 08:17:21
0001 #ifndef FUN4ALLRAW_MICROMEGASBCOMATCHINGINFORMATION_V2_H
0002 #define FUN4ALLRAW_MICROMEGASBCOMATCHINGINFORMATION_V2_H
0003
0004
0005
0006
0007
0008
0009
0010 #include <cstdint>
0011 #include <list>
0012 #include <optional>
0013 #include <set>
0014 #include <vector>
0015 #include <utility>
0016
0017 class MicromegasBcoMatchingInformation_v2
0018 {
0019 public:
0020
0021
0022 MicromegasBcoMatchingInformation_v2() = default;
0023
0024
0025 class gtm_payload
0026 {
0027 public:
0028
0029 uint16_t pkt_type = 0;
0030 bool is_endat = false;
0031 bool is_lvl1 = false;
0032 bool is_modebit = false;
0033 uint64_t bco = 0;
0034 uint32_t lvl1_count = 0;
0035 uint32_t endat_count = 0;
0036 uint64_t last_bco = 0;
0037 uint8_t modebits = 0;
0038 uint8_t userbits = 0;
0039
0040 };
0041
0042
0043 class fee_payload
0044 {
0045 public:
0046 uint16_t adc_length = 0;
0047 uint16_t data_parity = 0;
0048 uint16_t sampa_address = 0;
0049 uint16_t sampa_channel = 0;
0050 uint16_t channel = 0;
0051 uint16_t type = 0;
0052 uint16_t user_word = 0;
0053 uint32_t bx_timestamp = 0;
0054 uint16_t data_crc = 0;
0055 uint16_t calc_crc = 0;
0056
0057 std::vector< std::pair< uint16_t , std::vector<uint16_t> > > waveforms;
0058 };
0059
0060
0061
0062
0063
0064 int verbosity() const
0065 {
0066 return m_verbosity;
0067 }
0068
0069
0070
0071
0072
0073
0074 bool is_verified() const
0075 {
0076 return m_verified_from_modebits || m_verified_from_data;
0077 }
0078
0079
0080 std::optional<uint32_t> get_predicted_fee_bco(uint64_t) const;
0081
0082
0083 static bool gtm_clock_multiplier_is_set()
0084 {
0085 return m_multiplier_is_set;
0086 }
0087
0088
0089 static double get_gtm_clock_multiplier()
0090 {
0091 return m_multiplier;
0092 }
0093
0094
0095 double get_adjusted_multiplier() const;
0096
0097
0098 void print_gtm_bco_information() const;
0099
0100
0101 unsigned int get_fee_bco_first() const
0102 { return m_fee_bco_first; }
0103
0104
0105 uint64_t get_gtm_bco_first() const
0106 { return m_gtm_bco_first; }
0107
0108
0109 uint64_t get_gtm_bco_last() const
0110 { return m_gtm_bco_list.empty() ? 0:*m_gtm_bco_list.rbegin(); }
0111
0112
0113
0114
0115
0116
0117
0118 void set_verbosity(int value)
0119 {
0120 m_verbosity = value;
0121 }
0122
0123
0124 static void set_gtm_clock_multiplier(double value)
0125 {
0126 m_multiplier_is_set = true;
0127 m_multiplier = value;
0128 }
0129
0130
0131 static void set_enable_multiplier_adjustment( bool value )
0132 { m_multiplier_adjustment_enabled = value; }
0133
0134
0135
0136 static void set_max_multiplier_adjustment_count( unsigned int value )
0137 {
0138 m_max_multiplier_adjustment_count = value;
0139 }
0140
0141
0142 static void set_gtm_bco_diff( unsigned int value )
0143 {
0144 m_max_gtm_bco_diff = value;
0145 }
0146
0147
0148 bool find_reference_from_modebits(const gtm_payload&);
0149
0150
0151 bool find_reference_from_data(const fee_payload&);
0152
0153
0154 void save_gtm_bco_information(int , const gtm_payload&);
0155
0156
0157
0158
0159
0160
0161 std::optional<uint64_t> find_gtm_bco(int , unsigned int , uint32_t );
0162
0163
0164 void cleanup();
0165
0166
0167 void cleanup(uint64_t );
0168
0169
0170
0171 private:
0172
0173
0174 void update_multiplier_adjustment(uint64_t , uint32_t );
0175
0176
0177 unsigned int m_verbosity = 0;
0178
0179
0180 bool m_verified_from_modebits = false;
0181
0182 bool m_verified_from_data = false;
0183
0184
0185 uint64_t m_gtm_bco_first = 0;
0186
0187
0188 uint32_t m_fee_bco_first = 0;
0189
0190
0191
0192 uint32_t m_fee_bco_prev = 0;
0193 bool m_has_fee_bco_prev = false;
0194
0195
0196 std::list<uint64_t> m_gtm_bco_list;
0197
0198
0199 using m_bco_matching_pair_t = std::pair<unsigned int, uint64_t>;
0200 std::list<m_bco_matching_pair_t> m_bco_matching_list;
0201
0202
0203 std::set<uint32_t> m_orphans;
0204
0205
0206 static bool m_multiplier_is_set;
0207
0208
0209 static double m_multiplier;
0210
0211
0212 static bool m_multiplier_adjustment_enabled;
0213
0214
0215
0216 static unsigned int m_max_multiplier_adjustment_count;
0217
0218
0219 static unsigned int m_max_gtm_bco_diff;
0220
0221
0222 double m_multiplier_adjustment = 0;
0223
0224
0225 double m_multiplier_adjustment_numerator = 0;
0226
0227
0228 double m_multiplier_adjustment_denominator = 0;
0229
0230
0231 unsigned int m_multiplier_adjustment_count = 0;
0232 };
0233
0234 #endif