Project
Loading...
Searching...
No Matches
PayLoadSG.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef ALICEO2_ITSMFT_PAYLOADSG_H
13#define ALICEO2_ITSMFT_PAYLOADSG_H
14
15#include <cstdint>
16#include <vector>
17#include <Rtypes.h>
18
22
23namespace o2
24{
25namespace itsmft
26{
27
29{
30 // scatter-gather buffer for the payload: base pointer + vector of references for pieces to collect
31 public:
32 using DataType = unsigned char;
33
34 PayLoadSG() = default;
35 ~PayLoadSG() = default;
36
38 void add(const DataType* ptr, size_t n)
39 {
40 if (n) {
41 mBuffer.emplace_back(ptr, n);
42 }
43 }
44
46 bool current(char& v)
47 {
48 if (mCurrentPieceID < mBuffer.size()) {
49 const auto& piece = mBuffer[mCurrentPieceID];
50 if (mCurrentEntryInPiece < piece.size) {
51 v = piece.data[mCurrentEntryInPiece];
52 return true;
53 } else {
54 nextPiece();
55 return current(v);
56 }
57 }
58 return false;
59 }
60
62 bool next(char& v)
63 {
64 if (mCurrentPieceID < mBuffer.size()) {
65 const auto& piece = mBuffer[mCurrentPieceID];
66 if (mCurrentEntryInPiece < piece.size) {
67 v = piece.data[mCurrentEntryInPiece++];
68 return true;
69 } else {
70 nextPiece();
71 return next(v);
72 }
73 }
74 return false;
75 }
76
78 bool next(uint16_t& v)
79 {
80 char b0, b1;
81 if (next(b0) && next(b1)) {
82 v = (b0 << 8) | b1;
83 return true;
84 }
85 return false;
86 }
87
89 void rewind()
90 {
91 mCurrentPieceID = mCurrentEntryInPiece = 0;
92 }
93
95 void clear()
96 {
97 mBuffer.clear();
98 mCurrentPieceID = mCurrentEntryInPiece = 0;
99 }
100
101 struct SGPiece {
102 const DataType* data = nullptr; // data of the piece
103 uint32_t size = 0; // size of the piece
104 SGPiece() = default;
105 SGPiece(const DataType* st, int n) : data(st), size(n) {}
106 };
107
108 void setDone() { mCurrentPieceID = mBuffer.size(); }
109
110 size_t& currentPieceID() { return mCurrentPieceID; }
111 size_t currentPieceID() const { return mCurrentPieceID; }
112
113 size_t& currentEntryInPiece() { return mCurrentEntryInPiece; }
114 size_t currentEntryInPiece() const { return mCurrentEntryInPiece; }
115
116 const SGPiece* currentPiece() const { return mCurrentPieceID < mBuffer.size() ? &mBuffer[mCurrentPieceID] : nullptr; }
117
119 {
120 // move to the next piece
121 mCurrentEntryInPiece = 0;
122 mCurrentPieceID++;
123 return currentPiece();
124 }
125
126 const SGPiece* getPiece(int i) const { return &mBuffer[i]; }
127
128 size_t getNPieces() const { return mBuffer.size(); }
129
130 private:
131 std::vector<SGPiece> mBuffer; // list of pieces to fetch
132 size_t mCurrentPieceID = 0; // current piece
133 size_t mCurrentEntryInPiece = 0; // offset within current piece
134
135 ClassDefNV(PayLoadSG, 1);
136};
137} // namespace itsmft
138} // namespace o2
139
140#endif
int32_t i
const GPUTPCGMMerger::trackCluster & b1
TBranch * ptr
benchmark::State & st
size_t getNPieces() const
Definition PayLoadSG.h:128
size_t & currentEntryInPiece()
Definition PayLoadSG.h:113
const SGPiece * currentPiece() const
Definition PayLoadSG.h:116
~PayLoadSG()=default
add n bytes to the buffer
size_t currentEntryInPiece() const
Definition PayLoadSG.h:114
const SGPiece * nextPiece()
Definition PayLoadSG.h:118
size_t currentPieceID() const
Definition PayLoadSG.h:111
size_t & currentPieceID()
Definition PayLoadSG.h:110
bool next(char &v)
read short value from buffer
Definition PayLoadSG.h:62
void rewind()
make buffer empty
Definition PayLoadSG.h:89
const SGPiece * getPiece(int i) const
Definition PayLoadSG.h:126
bool current(char &v)
read character value from buffer
Definition PayLoadSG.h:46
unsigned char DataType
Definition PayLoadSG.h:32
void add(const DataType *ptr, size_t n)
read current character value from buffer w/o stepping forward
Definition PayLoadSG.h:38
bool next(uint16_t &v)
move current pointer to the head
Definition PayLoadSG.h:78
GLdouble n
Definition glcorearb.h:1982
GLsizeiptr size
Definition glcorearb.h:659
const GLdouble * v
Definition glcorearb.h:832
GLboolean * data
Definition glcorearb.h:298
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
SGPiece(const DataType *st, int n)
Definition PayLoadSG.h:105