Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-07 08:15:51

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