Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
PayLoadCont.h
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file PayLoadCont.h
1
// @file PayLoadCont.h
2
// @brief Declaration of class for continuos buffer of ALPIDE data
3
// @author ruben.shahoyan@cern.ch
4
// @sa <O2/Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/PayLoadCont.h>
5
// <03608ff89>
6
7
#ifndef MVTXDECODER_PAYLOADCONT_H
8
#define MVTXDECODER_PAYLOADCONT_H
9
10
#include <cstring>
11
#include <vector>
12
#include <functional>
13
#include <cstdint>
14
15
namespace
mvtx
16
{
17
18
class
PayLoadCont
19
{
22
23
public
:
24
static
constexpr
size_t
MinCapacity
= 16;
25
27
PayLoadCont
() =
default
;
28
PayLoadCont
(
size_t
sz) {
expand
(sz); }
29
~PayLoadCont
() =
default
;
30
31
PayLoadCont
(
const
PayLoadCont
& src);
32
33
PayLoadCont
&
operator=
(
const
PayLoadCont
& src);
34
35
const
uint8_t*
data
()
const
{
return
mBuffer
.data(); }
36
38
void
expand
(
size_t
sz);
39
40
bool
isEmpty
()
const
{
return
mPtr
>=
mEnd
; }
41
43
void
clear
()
44
{
45
mPtr
=
mBuffer
.data();
46
mEnd
=
mPtr
;
47
}
48
50
size_t
getUnusedSize
()
const
{
return
mEnd
>
mPtr
?
mEnd
-
mPtr
: 0; }
51
53
size_t
getSize
()
const
{
return
mEnd
-
mBuffer
.data(); }
54
56
size_t
getOffset
()
const
{
return
mPtr
-
mBuffer
.data(); }
57
59
size_t
getCapacity
()
const
{
return
mBuffer
.size(); }
60
62
size_t
getFreeCapacity
()
const
{
return
mBuffer
.size() -
getSize
(); }
63
65
void
ensureFreeCapacity
(
size_t
n
)
66
{
67
if
(
getFreeCapacity
() < n) {
68
expand
(
getCapacity
() + 2 * n);
69
}
70
}
71
73
void
fillFast
(
const
uint8_t
c
,
size_t
n
)
74
{
75
std::memset(
mEnd
, c, n);
76
mEnd
+=
n
;
77
}
78
80
void
addFast
(
const
uint8_t* ptr,
size_t
n
)
81
{
82
std::memcpy(
mEnd
, ptr, n);
83
mEnd
+=
n
;
84
}
85
87
void
addFast
(uint8_t val) { *
mEnd
++ = val; }
88
90
void
addFast
(uint16_t val)
91
{
92
*
mEnd
++ = val >> 8;
93
*
mEnd
++ = 0xff & val;
94
}
95
97
void
eraseFast
(
size_t
n
) {
mEnd
-=
n
; }
98
100
void
erase
(
size_t
n
)
101
{
102
if
(n >
getSize
()) {
103
clear
();
104
}
else
{
105
eraseFast
(n);
106
}
107
}
108
110
void
fill
(
const
uint8_t
c
,
size_t
n
)
111
{
112
ensureFreeCapacity
(n);
113
fillFast
(c, n);
114
}
115
117
void
add
(
const
uint8_t* ptr,
size_t
n
)
118
{
119
ensureFreeCapacity
(n);
120
addFast
(ptr, n);
121
}
122
124
void
add
(uint8_t val)
125
{
126
ensureFreeCapacity
(
sizeof
(val));
127
addFast
(val);
128
}
129
131
void
add
(uint16_t val)
132
{
133
ensureFreeCapacity
(
sizeof
(val));
134
addFast
(val);
135
}
136
138
void
shrinkToSize
(
size_t
sz)
139
{
140
mEnd
=
mPtr
+ sz;
141
}
142
144
uint8_t
operator[]
(
size_t
i
)
const
{
return
mBuffer
[
i
]; }
145
147
uint8_t&
operator[]
(
size_t
i
) {
return
mBuffer
[
i
]; }
148
150
bool
current
(uint8_t&
v
)
const
151
{
152
if
(
mPtr
<
mEnd
) {
153
v = *
mPtr
;
154
return
true
;
155
}
156
return
false
;
157
}
158
160
bool
next
(uint8_t&
v
)
161
{
162
if
(
mPtr
<
mEnd
) {
163
v = *
mPtr
++;
164
return
true
;
165
}
166
return
false
;
167
}
168
170
bool
next
(uint16_t&
v
)
171
{
172
if
(
mPtr
<
mEnd
- (
sizeof
(uint16_t) - 1)) {
173
v = (*
mPtr
++) << 8;
174
v |= (*
mPtr
++);
175
return
true
;
176
}
177
return
false
;
178
}
179
181
void
rewind
() {
mPtr
=
mBuffer
.data(); }
182
184
void
moveUnusedToHead
()
185
{
186
auto
left
=
getUnusedSize
();
187
if
(
left
<
getOffset
()) {
188
std::memcpy(
mBuffer
.data(),
mPtr
,
left
);
// there is no overlap
189
}
else
{
190
std::memmove(
mBuffer
.data(),
mPtr
,
left
);
// there is an overlap
191
}
192
mPtr
=
mBuffer
.data();
193
mEnd
=
mPtr
+
left
;
194
}
195
197
// (attemtint to use all free capacity) using the method provided via getNext
198
size_t
append
(std::function<
size_t
(uint8_t*,
size_t
)> getNext)
199
{
200
moveUnusedToHead
();
201
auto
nRead = getNext(
mEnd
,
getFreeCapacity
());
202
mEnd
+= nRead;
203
return
nRead;
204
}
205
207
uint8_t*
getPtr
() {
return
mPtr
; }
208
void
setPtr
(uint8_t* ptr) {
mPtr
= ptr; }
209
void
movePtr
(
size_t
step
) {
mPtr
+=
step
; }
210
211
uint8_t*
getEnd
() {
return
mEnd
; }
212
void
setEnd
(uint8_t* ptr) {
mEnd
= ptr; }
213
214
private
:
215
std::vector<uint8_t>
mBuffer
;
216
uint8_t*
mPtr
=
nullptr
;
217
uint8_t*
mEnd
=
nullptr
;
218
219
// ClassDefNV(PayLoadCont, 1);
220
};
221
222
}
// namespace mvtx
223
224
#endif
online_distribution
blob
master
newbasic
mvtx_decoder
PayLoadCont.h
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:27
using
1.8.2 with
sPHENIX GitHub integration