Back to home page

sPhenix code displayed by LXR

 
 

    


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 // NOLINTNEXTLINE(hicpp-special-member-functions)
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   /** identify Function from PHObject
0024       @param os Output Stream
0025    */
0026   void identify(std::ostream &os = std::cout) const override;
0027 
0028   void Clear(Option_t * /*unused*/) override;
0029 
0030   uint64_t get_bco() const override { return bco; }
0031   // cppcheck-suppress virtualCallInConstructor
0032   void set_bco(const uint64_t val) override { bco = val; }
0033 
0034   //   uint64_t get_gtm_bco() const override { return gtm_bco; }
0035   //   // cppcheck-suppress virtualCallInConstructor
0036   //   void set_gtm_bco(const uint64_t val) override { gtm_bco = val; }
0037 
0038   int32_t get_packetid() const override { return packetid; }
0039   // cppcheck-suppress virtualCallInConstructor
0040   void set_packetid(const int32_t val) override { packetid = val; }
0041 
0042   uint16_t get_fee() const override { return fee; }
0043   // cppcheck-suppress virtualCallInConstructor
0044   void set_fee(const uint16_t val) override { fee = val; }
0045 
0046   uint16_t get_channel() const override { return channel; }
0047   // cppcheck-suppress virtualCallInConstructor
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   //   // cppcheck-suppress virtualCallInConstructor
0055   //   void set_sampaaddress(const uint16_t val) override { sampaaddress = val; }
0056 
0057   uint16_t get_sampachannel() const override { return channel & 0x1fU; }
0058   //   // cppcheck-suppress virtualCallInConstructor
0059   //   void set_sampachannel(const uint16_t val) override { sampachannel = val; }
0060 
0061   uint16_t get_samples() const override { return 1024U; }
0062   // cppcheck-suppress virtualCallInConstructor
0063   //   void set_samples(const uint16_t val) override
0064   //   {
0065   //     // assign
0066   //     samples = val;
0067   //   }
0068 
0069   uint16_t get_adc(const uint16_t sample) const override;
0070 
0071   // cppcheck-suppress virtualCallInConstructor
0072   //   void set_adc(const uint16_t sample, const uint16_t val) override
0073   //   {
0074   //     adcmap[sample] = val;
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   // uint16_t get_userword() const override { return userword; }
0082   // void set_userword(const uint16_t i) override { userword = i; }
0083 
0084   // uint16_t get_checksum() const override { return checksum; }
0085   // void set_checksum(const uint16_t i) override { checksum = i; }
0086 
0087   // uint16_t get_parity() const override { return data_parity; }
0088   // void set_parity(const uint16_t i) override { data_parity = i; }
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     // NOLINTNEXTLINE(hicpp-named-parameter)
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       // NOLINTNEXTLINE(bugprone-branch-clone)
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         // advance to the next valid waveform
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();  // Or throw an exception
0155     }
0156     uint16_t CurrentAdc() const override
0157     {
0158       if (!IsDone())
0159       {
0160         // NOLINTNEXTLINE(bugprone-branch-clone)
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();  // Or throw an exception
0168         }
0169       }
0170       return std::numeric_limits<uint16_t>::max();  // Or throw an exception
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   // uint16_t checksum{std::numeric_limits<uint16_t>::max()};
0183   // uint16_t data_parity{std::numeric_limits<uint16_t>::max()};
0184 
0185   bool checksumerror{true};
0186   bool parityerror{true};
0187 
0188   //! adc waveform std::vector< uint16_t > for each start time uint16_t
0189   std::vector<std::pair<uint16_t, std::vector<uint16_t> > > m_adcData;
0190 
0191   ClassDefOverride(TpcRawHitv3, 2)
0192 };
0193 
0194 #endif