Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:16:09

0001 #ifndef FUN4ALLRAW_TPCRAWTHITV1_H
0002 #define FUN4ALLRAW_TPCRAWTHITV1_H
0003 
0004 #include "TpcRawHit.h"
0005 
0006 #include <phool/PHObject.h>
0007 
0008 #include <cassert>
0009 #include <limits>
0010 
0011 class TpcRawHitv1 : public TpcRawHit
0012 {
0013  public:
0014   TpcRawHitv1() = default;
0015   TpcRawHitv1(TpcRawHit* tpchit);
0016   ~TpcRawHitv1() override = default;
0017 
0018   /** identify Function from PHObject
0019       @param os Output Stream
0020    */
0021   void identify(std::ostream& os = std::cout) const override;
0022 
0023   void Clear(Option_t*) override;
0024 
0025   uint64_t get_bco() const override { return bco; }
0026 
0027   void set_bco(const uint64_t val) override { bco = val; }
0028 
0029   uint64_t get_gtm_bco() const override { return gtm_bco; }
0030   void set_gtm_bco(const uint64_t val) override { gtm_bco = val; }
0031 
0032   int32_t get_packetid() const override { return packetid; }
0033   void set_packetid(const int32_t val) override { packetid = val; }
0034 
0035   uint16_t get_fee() const override { return fee; }
0036   void set_fee(const uint16_t val) override { fee = val; }
0037 
0038   uint16_t get_channel() const override { return channel; }
0039   void set_channel(const uint16_t val) override { channel = val; }
0040 
0041   uint16_t get_sampaaddress() const override { return sampaaddress; }
0042   void set_sampaaddress(const uint16_t val) override { sampaaddress = val; }
0043 
0044   uint16_t get_sampachannel() const override { return sampachannel; }
0045   void set_sampachannel(const uint16_t val) override { sampachannel = val; }
0046 
0047   uint16_t get_samples() const override { return samples; }
0048   void set_samples(const uint16_t val) override
0049   {
0050     // assign
0051     samples = val;
0052 
0053     // resize adc vector
0054     adc.resize(val, 0);
0055   }
0056 
0057   uint16_t get_adc(uint16_t sample) const override
0058   {
0059     assert(sample < adc.size());
0060     return adc[sample];
0061   }
0062 
0063   // cppcheck-suppress virtualCallInConstructor
0064   void set_adc(uint16_t sample, uint16_t val) override
0065   {
0066     assert(sample < adc.size());
0067     adc[sample] = val;
0068   }
0069 
0070   class AdcIteratorv1 : public AdcIterator
0071   {
0072    private:
0073     const std::vector<uint16_t>& m_adc;
0074     uint16_t m_index = 0;
0075 
0076    public:
0077     explicit AdcIteratorv1(const std::vector<uint16_t>& adc)
0078       : m_adc(adc)
0079     {
0080     }
0081 
0082     void First() override { m_index = 0; }
0083 
0084     void Next() override { ++m_index; }
0085 
0086     bool IsDone() const override { return m_index >= m_adc.size(); }
0087 
0088     uint16_t CurrentTimeBin() const override
0089     {
0090       return m_index;
0091     }
0092     uint16_t CurrentAdc() const override
0093     {
0094       if (!IsDone())
0095       {
0096         return m_adc[m_index];
0097       }
0098       return std::numeric_limits<uint16_t>::max();  // Or throw an exception
0099     }
0100   };
0101 
0102   AdcIterator* CreateAdcIterator() const override { return new AdcIteratorv1(adc); }
0103 
0104  private:
0105   uint64_t bco = std::numeric_limits<uint64_t>::max();
0106   uint64_t gtm_bco = std::numeric_limits<uint64_t>::max();
0107   int32_t packetid = std::numeric_limits<int32_t>::max();
0108   uint16_t fee = std::numeric_limits<uint16_t>::max();
0109   uint16_t channel = std::numeric_limits<uint16_t>::max();
0110   uint16_t sampaaddress = std::numeric_limits<uint16_t>::max();
0111   uint16_t sampachannel = std::numeric_limits<uint16_t>::max();
0112   uint16_t samples = std::numeric_limits<uint16_t>::max();
0113 
0114   //! adc value for each sample
0115   std::vector<uint16_t> adc;
0116 
0117   ClassDefOverride(TpcRawHitv1, 1)
0118 };
0119 
0120 #endif