File indexing completed on 2025-08-05 08:16:09
0001 #ifndef FUN4ALLRAW_TPCRAWTHITv3_H
0002 #define FUN4ALLRAW_TPCRAWTHITv3_H
0003
0004 #include "TpcRawHit.h"
0005
0006 #include <phool/PHObject.h>
0007
0008 #include <cassert>
0009 #include <limits>
0010 #include <utility>
0011 #include <vector>
0012
0013
0014 class TpcRawHitv3 : public TpcRawHit
0015 {
0016 public:
0017 TpcRawHitv3() = default;
0018 explicit TpcRawHitv3(TpcRawHit *tpchit);
0019 TpcRawHitv3(TpcRawHitv3 &&other) noexcept;
0020
0021 ~TpcRawHitv3() override = default;
0022
0023
0024
0025
0026 void identify(std::ostream &os = std::cout) const override;
0027
0028 void Clear(Option_t * ) override;
0029
0030 uint64_t get_bco() const override { return bco; }
0031
0032 void set_bco(const uint64_t val) override { bco = val; }
0033
0034
0035
0036
0037
0038 int32_t get_packetid() const override { return packetid; }
0039
0040 void set_packetid(const int32_t val) override { packetid = val; }
0041
0042 uint16_t get_fee() const override { return fee; }
0043
0044 void set_fee(const uint16_t val) override { fee = val; }
0045
0046 uint16_t get_channel() const override { return channel; }
0047
0048 void set_channel(const uint16_t val) override { channel = val; }
0049
0050 uint16_t get_sampaaddress() const override
0051 {
0052 return static_cast<uint16_t>(channel >> 5U) & 0xfU;
0053 }
0054
0055
0056
0057 uint16_t get_sampachannel() const override { return channel & 0x1fU; }
0058
0059
0060
0061 uint16_t get_samples() const override { return 1024U; }
0062
0063
0064
0065
0066
0067
0068
0069 uint16_t get_adc(const uint16_t sample) const override;
0070
0071
0072
0073
0074
0075
0076 void move_adc_waveform(const uint16_t start_time, std::vector<uint16_t> &&adc);
0077
0078 uint16_t get_type() const override { return type; }
0079 void set_type(const uint16_t i) override { type = i; }
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090 bool get_checksumerror() const override { return checksumerror; }
0091 void set_checksumerror(const bool b) override { checksumerror = b; }
0092
0093 bool get_parityerror() const override { return parityerror; }
0094 void set_parityerror(const bool b) override { parityerror = b; }
0095
0096 class AdcIteratorv3 : public AdcIterator
0097 {
0098 private:
0099 const std::vector<std::pair<uint16_t, std::vector<uint16_t> > > &m_adc;
0100 uint16_t m_waveform_index = 0;
0101 uint16_t m_adc_position_in_waveform_index = 0;
0102
0103 public:
0104
0105 explicit AdcIteratorv3(const std::vector<std::pair<uint16_t, std::vector<uint16_t> > > &adc)
0106 : m_adc(adc)
0107 {
0108 }
0109
0110 void First() override
0111 {
0112 m_waveform_index = 0;
0113 m_adc_position_in_waveform_index = 0;
0114 }
0115
0116 void Next() override
0117 {
0118 if (IsDone()) return;
0119
0120
0121 if (m_adc_position_in_waveform_index + 1U < m_adc[m_waveform_index].second.size())
0122 {
0123 ++m_adc_position_in_waveform_index;
0124 }
0125 else
0126 {
0127
0128 m_adc_position_in_waveform_index = 0;
0129
0130 while (true)
0131 {
0132 ++m_waveform_index;
0133
0134 if (m_waveform_index >= m_adc.size())
0135 {
0136 break;
0137 }
0138 if (not m_adc[m_waveform_index].second.empty())
0139 {
0140 break;
0141 }
0142 }
0143 }
0144 }
0145
0146 bool IsDone() const override { return m_waveform_index >= m_adc.size(); }
0147
0148 uint16_t CurrentTimeBin() const override
0149 {
0150 if (!IsDone())
0151 {
0152 return m_adc[m_waveform_index].first + m_adc_position_in_waveform_index;
0153 }
0154 return std::numeric_limits<uint16_t>::max();
0155 }
0156 uint16_t CurrentAdc() const override
0157 {
0158 if (!IsDone())
0159 {
0160
0161 if (m_adc_position_in_waveform_index < m_adc[m_waveform_index].second.size())
0162 {
0163 return m_adc[m_waveform_index].second[m_adc_position_in_waveform_index];
0164 }
0165 else
0166 {
0167 return std::numeric_limits<uint16_t>::max();
0168 }
0169 }
0170 return std::numeric_limits<uint16_t>::max();
0171 }
0172 };
0173
0174 AdcIterator *CreateAdcIterator() const override { return new AdcIteratorv3(m_adcData); }
0175
0176 private:
0177 uint64_t bco{std::numeric_limits<uint64_t>::max()};
0178 int32_t packetid{std::numeric_limits<int32_t>::max()};
0179 uint16_t fee{std::numeric_limits<uint16_t>::max()};
0180 uint16_t channel{std::numeric_limits<uint16_t>::max()};
0181 uint16_t type{std::numeric_limits<uint16_t>::max()};
0182
0183
0184
0185 bool checksumerror{true};
0186 bool parityerror{true};
0187
0188
0189 std::vector<std::pair<uint16_t, std::vector<uint16_t> > > m_adcData;
0190
0191 ClassDefOverride(TpcRawHitv3, 2)
0192 };
0193
0194 #endif