Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:20:06

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 
0017   class PayLoadSG
0018   {
0019     // scatter-gather buffer for the payload: base pointer + vector of references
0020     // for pieces to collect
0021    public:
0022     PayLoadSG() = default;
0023     ~PayLoadSG() = default;
0024 
0025     ///< add n bytes to the buffer
0026     void add(size_t n, bool err)
0027     {
0028       if (n)
0029       {
0030         mBuffer.emplace_back(n, err);
0031       }
0032     }
0033 
0034     ///< move current pointer to the head
0035     void rewind() { mCurrentPieceId = 0; }
0036 
0037     ///< make buffer empty
0038     void clear()
0039     {
0040       mBuffer.clear();
0041       mCurrentPieceId = 0;
0042     }
0043 
0044     struct SGPiece
0045     {
0046       uint32_t size = 0;  // size of the piece
0047       bool hasError = false;
0048       SGPiece() = default;
0049       SGPiece(int n, bool err)
0050         : size(n)
0051         , hasError(err)
0052       {
0053       }
0054     };
0055 
0056     void setDone() { mCurrentPieceId = mBuffer.size(); }
0057 
0058     size_t &currentPieceId() { return mCurrentPieceId; }
0059     size_t currentPieceId() const { return mCurrentPieceId; }
0060 
0061     const SGPiece *currentPiece() const
0062     {
0063       return mCurrentPieceId < mBuffer.size() ? &mBuffer[mCurrentPieceId]
0064                                               : nullptr;
0065     }
0066 
0067     const SGPiece *nextPiece()
0068     {
0069       // move to the next piece
0070       mCurrentPieceId++;
0071       return currentPiece();
0072     }
0073 
0074     const SGPiece *getPiece(int i) const { return &mBuffer[i]; }
0075 
0076     size_t getNPieces() const { return mBuffer.size(); }
0077 
0078    private:
0079     std::vector<SGPiece> mBuffer;  // list of pieces to fetch
0080     size_t mCurrentPieceId = 0;    // current piece
0081 
0082     // ClassDefNV(PayLoadSG, 1);
0083   };
0084 
0085 }  // namespace mvtx
0086 
0087 #endif