Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:15

0001 #include "TpcRawHitContainerv3.h"
0002 #include "TpcRawHitv3.h"
0003 
0004 #include <TClonesArray.h>
0005 
0006 #include <iostream>
0007 
0008 static const int NTPCHITS = 10000;
0009 
0010 TpcRawHitContainerv3::TpcRawHitContainerv3()
0011   : TpcRawHitsTCArray(new TClonesArray("TpcRawHitv3", NTPCHITS))
0012 {
0013 }
0014 
0015 TpcRawHitContainerv3::~TpcRawHitContainerv3()
0016 {
0017   TpcRawHitsTCArray->Clear("C");
0018   delete TpcRawHitsTCArray;
0019 }
0020 
0021 void TpcRawHitContainerv3::Reset()
0022 {
0023   TpcRawHitsTCArray->Clear("C");
0024   TpcRawHitsTCArray->Expand(NTPCHITS);
0025 }
0026 
0027 void TpcRawHitContainerv3::identify(std::ostream &os) const
0028 {
0029   os << "TpcRawHitContainerv3" << std::endl;
0030   os << "containing " << TpcRawHitsTCArray->GetEntriesFast() << " Tpc hits" << std::endl;
0031   // NOLINTNEXTLINE(cppcoreguidelines-pro-type-static-cast-downcast)
0032   TpcRawHit *tpchit = static_cast<TpcRawHit *>(TpcRawHitsTCArray->At(0));
0033   if (tpchit)
0034   {
0035     os << "for beam clock: " << std::hex << tpchit->get_bco() << std::dec << std::endl;
0036   }
0037 }
0038 
0039 int TpcRawHitContainerv3::isValid() const
0040 {
0041   return TpcRawHitsTCArray->GetSize();
0042 }
0043 
0044 unsigned int TpcRawHitContainerv3::get_nhits()
0045 {
0046   return TpcRawHitsTCArray->GetEntriesFast();
0047 }
0048 
0049 TpcRawHit *TpcRawHitContainerv3::AddHit()
0050 {
0051   TpcRawHit *newhit = new ((*TpcRawHitsTCArray)[TpcRawHitsTCArray->GetLast() + 1]) TpcRawHitv3();
0052   return newhit;
0053 }
0054 
0055 TpcRawHit *TpcRawHitContainerv3::AddHit(TpcRawHit *tpchit)
0056 {
0057   if (tpchit->IsA() == TpcRawHitv3::Class())
0058   {
0059     // fast add with move constructor to avoid ADC data copying
0060 
0061     TpcRawHit *newhit = new ((*TpcRawHitsTCArray)[TpcRawHitsTCArray->GetLast() + 1])
0062         TpcRawHitv3(std::move(*(static_cast<TpcRawHitv3 *>(tpchit))));  // NOLINT(cppcoreguidelines-pro-type-static-cast-downcast)
0063     return newhit;
0064   }
0065 
0066   std::cout << __PRETTY_FUNCTION__ << "WARNING: input hit is not of type TpcRawHitv3. This is slow, please avoid." << std::endl;
0067   TpcRawHit *newhit = new ((*TpcRawHitsTCArray)[TpcRawHitsTCArray->GetLast() + 1]) TpcRawHitv3(tpchit);
0068   return newhit;
0069 }
0070 
0071 TpcRawHit *TpcRawHitContainerv3::get_hit(unsigned int index)
0072 {
0073   return (TpcRawHit *) TpcRawHitsTCArray->At(index);
0074 }