Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:55

0001 // @file PayLoadCont.cxx
0002 // @brief Implementation of class for continuos buffer of ALPIDE data
0003 // @sa <O2/Detectors/ITSMFT/common/reconstruction/src/PayLoadCont.cxx>
0004 //     <03608ff89>
0005 
0006 #include "PayLoadCont.h"
0007 
0008 using namespace mvtx;
0009 
0010 constexpr size_t PayLoadCont::MinCapacity;
0011 
0012 //________________________________________________________________________________
0013 PayLoadCont::PayLoadCont(const PayLoadCont &src)
0014   : mBuffer(src.mBuffer)
0015 {
0016   if (src.mPtr)
0017   {
0018     mPtr = mBuffer.data() + (src.mPtr - src.mBuffer.data());
0019   }
0020   if (src.mEnd)
0021   {
0022     mEnd = mBuffer.data() + (src.mEnd - src.mBuffer.data());
0023   }
0024 }
0025 
0026 //________________________________________________________________________________
0027 PayLoadCont &PayLoadCont::operator=(const PayLoadCont &src)
0028 {
0029   if (&src != this)
0030   {
0031     mBuffer = src.mBuffer;
0032     if (src.mPtr)
0033     {
0034       mPtr = mBuffer.data() + (src.mPtr - src.mBuffer.data());
0035     }
0036     if (src.mEnd)
0037     {
0038       mEnd = mBuffer.data() + (src.mEnd - src.mBuffer.data());
0039     }
0040   }
0041   return *this;
0042 }
0043 
0044 //________________________________________________________________________________
0045 void PayLoadCont::expand(size_t sz)
0046 {
0047   ///< increase the buffer size
0048   auto *oldHead = mBuffer.data();
0049   if (sz < MinCapacity)
0050   {
0051     sz = MinCapacity;
0052   }
0053   if (sz < mBuffer.size())
0054   {  // never decrease the size
0055     return;
0056   }
0057   mBuffer.resize(sz);
0058   if (oldHead)
0059   {  // fix the pointers to account for the reallocation
0060     int64_t diff = mBuffer.data() - oldHead;
0061     mPtr += diff;
0062     mEnd += diff;
0063   }
0064   else
0065   {  // new buffer
0066     clear();
0067   }
0068 }