Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // @file PayLoadSG.h
0002 // @brief Declaration of class for scatter-gather buffer
0003 // @author ruben.shahoyan@cern.ch
0004 // @sa <O2/Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/PayLoadSG.h>
0005 //     <1c31a8d52>
0006 
0007 #ifndef MVTXDECODER_PAYLOADSG_H
0008 #define MVTXDECODER_PAYLOADSG_H
0009 
0010 #include <Rtypes.h>
0011 
0012 #include <cstdint>
0013 #include <vector>
0014 
0015 namespace mvtx {
0016 
0017 // scatter-gather buffer for the payload: base pointer + vector of references for pieces to collect
0018 class PayLoadSG {
0019  public:
0020   PayLoadSG() = default;
0021   ~PayLoadSG() = default;
0022 
0023   enum HBF_ERRORS : uint8_t {
0024     NoError = 0x0,
0025     Incomplete = 0x1,
0026     PacketWithError = 0x2
0027   };
0028 
0029   ///< add n bytes to the buffer
0030   void add(size_t n, uint8_t err)
0031   {
0032     if (n)
0033     {
0034       mBuffer.emplace_back(n, err);
0035     }
0036   }
0037 
0038   ///< move current pointer to the head
0039   void rewind()
0040   {
0041     mCurrentPieceId = 0;
0042   }
0043 
0044   ///< make buffer empty
0045   void clear()
0046   {
0047     //mBuffer.clear();
0048     std::vector<SGPiece>().swap(mBuffer);
0049     mBuffer.shrink_to_fit();
0050     mCurrentPieceId = 0;
0051   }
0052 
0053   struct SGPiece
0054   {
0055     uint32_t size = 0;   //size of the piece
0056     uint8_t hasError = 0;
0057     SGPiece() = default;
0058     SGPiece(int n, uint8_t err) : size(n), hasError(err) {}
0059   };
0060 
0061   void setDone() { mCurrentPieceId = mBuffer.size(); }
0062 
0063   size_t& currentPieceId() { return mCurrentPieceId; }
0064   size_t currentPieceId() const { return mCurrentPieceId; }
0065 
0066   const SGPiece* currentPiece() const
0067   {
0068     return mCurrentPieceId < mBuffer.size() ? &mBuffer[mCurrentPieceId] : nullptr;
0069   }
0070 
0071   const SGPiece* nextPiece()
0072   {
0073     // move to the next piece
0074     mCurrentPieceId++;
0075     return currentPiece();
0076   }
0077 
0078   const SGPiece* getPiece(int i) const { return &mBuffer[i]; }
0079 
0080   size_t getNPieces() const { return mBuffer.size(); }
0081 
0082  private:
0083   std::vector<SGPiece> mBuffer;   // list of pieces to fetch
0084   size_t mCurrentPieceId = 0;     // current piece
0085 
0086   ClassDefNV(PayLoadSG, 1);
0087 };
0088 
0089 } // namespace mvtx
0090 
0091 #endif