Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 #include "TpcRawHitv3.h"
0002 
0003 #include <cassert>
0004 #include <iostream>
0005 
0006 TpcRawHitv3::TpcRawHitv3(TpcRawHit *tpchit)
0007 {
0008   static bool once = true;
0009   if (once)
0010   {
0011     once = false;
0012     std::cout << "TpcRawHitv3::TpcRawHitv3(TpcRawHit *tpchit) - "
0013               << "WARNING: This moethod is slow and should be avoided as much as possible! Please use the move constructor."
0014               << std::endl;
0015   }
0016 
0017   TpcRawHitv3::set_bco(tpchit->get_bco());
0018   TpcRawHitv3::set_gtm_bco(tpchit->get_gtm_bco());
0019   TpcRawHitv3::set_packetid(tpchit->get_packetid());
0020   TpcRawHitv3::set_fee(tpchit->get_fee());
0021   TpcRawHitv3::set_channel(tpchit->get_channel());
0022   TpcRawHitv3::set_sampaaddress(tpchit->get_sampaaddress());
0023   TpcRawHitv3::set_sampachannel(tpchit->get_sampachannel());
0024   TpcRawHitv3::set_type(tpchit->get_type());
0025   TpcRawHitv3::set_userword(tpchit->get_userword());
0026   // TpcRawHitv3::set_checksum(tpchit->get_checksum());
0027   // TpcRawHitv3::set_parity(tpchit->get_parity());
0028   TpcRawHitv3::set_checksumerror(tpchit->get_checksumerror());
0029   TpcRawHitv3::set_parityerror(tpchit->get_parityerror());
0030   TpcRawHitv3::set_samples(tpchit->get_samples());
0031 
0032   for (size_t i = 0; i < tpchit->get_samples(); ++i)
0033   {
0034     uint16_t adcval = tpchit->get_adc(i);
0035     if (adcval > 0)
0036     {
0037       TpcRawHitv3::set_adc(i, tpchit->get_adc(i));
0038     }
0039   }
0040 }
0041 
0042 // cppcheck-suppress accessMoved
0043 TpcRawHitv3::TpcRawHitv3(TpcRawHitv3 &&other) noexcept
0044   : TpcRawHit(other)
0045   , bco(other.bco)
0046   , packetid(other.packetid)
0047   , fee(other.fee)
0048   , channel(other.channel)
0049   , type(other.type)
0050   // , userword(other.userword)
0051   // , checksum(other.checksum)
0052   // , data_parity(other.data_parity)
0053   , checksumerror(other.checksumerror)
0054   , parityerror(other.parityerror)
0055   , m_adcData(std::move(other.m_adcData))
0056 {
0057   //   other.bco = std::numeric_limits<uint64_t>::max();
0058   //   other.packetid = std::numeric_limits<int32_t>::max();
0059   other.fee = std::numeric_limits<uint16_t>::max();
0060   other.channel = std::numeric_limits<uint16_t>::max();
0061   //   other.type = std::numeric_limits<uint16_t>::max();
0062   //   other.userword = std::numeric_limits<uint16_t>::max();
0063   //   other.checksum = std::numeric_limits<uint16_t>::max();
0064   //   other.data_parity = std::numeric_limits<uint16_t>::max();
0065   other.checksumerror = true;
0066   other.parityerror = true;
0067 }
0068 
0069 void TpcRawHitv3::identify(std::ostream &os) const
0070 {
0071   os << "BCO: 0x" << std::hex << bco << std::dec << std::endl;
0072   os << " packet id: " << packetid << std::endl;
0073 
0074   for (const auto &waveform : m_adcData)
0075   {
0076     os << " start time: " << waveform.first << " | ADCs: ";
0077     for (const auto &adc : waveform.second)
0078     {
0079       os << adc << " ";
0080     }
0081     os << std::endl;
0082   }
0083 }
0084 
0085 uint16_t TpcRawHitv3::get_adc(const uint16_t /*sample*/) const
0086 {
0087   std::cout << __PRETTY_FUNCTION__
0088             << " Error: This moethod is slow and should be avoided as much as possible!"
0089             << std::endl;
0090   assert(0);
0091   //   auto adc = adcmap.find(sample);
0092   //   if (adc != adcmap.end())
0093   //   {
0094   //     return adc->second;
0095   //   }
0096   return 0;
0097 }
0098 
0099 void TpcRawHitv3::Clear(Option_t * /*unused*/)
0100 {
0101   // quick reset
0102   fee = std::numeric_limits<uint16_t>::max();
0103   channel = std::numeric_limits<uint16_t>::max();
0104   checksumerror = true;
0105   parityerror = true;
0106 
0107   for (auto &waveform : m_adcData)
0108   {
0109     waveform.second.clear();
0110     waveform.second.shrink_to_fit();
0111   }
0112   m_adcData.clear();
0113   m_adcData.shrink_to_fit();
0114 
0115   // std::cout << __PRETTY_FUNCTION__ << " - m_adcData.capacity = "<<m_adcData.capacity() << std::endl;
0116 }
0117 
0118 void TpcRawHitv3::move_adc_waveform(const uint16_t start_time, std::vector<uint16_t> &&adc)
0119 {
0120   m_adcData.emplace_back(start_time, adc);
0121 }