L1Trigger
TrackFindingTracklet
interface
CircularBuffer.h
Go to the documentation of this file.
1
#ifndef L1Trigger_TrackFindingTracklet_interface_CircularBuffer_h
2
#define L1Trigger_TrackFindingTracklet_interface_CircularBuffer_h
3
4
#include <cassert>
5
#include <vector>
6
7
namespace
trklet
{
8
9
template
<
class
T>
10
class
CircularBuffer
{
11
public
:
12
CircularBuffer
(
unsigned
int
nbits) {
13
size_
= 1 << nbits;
14
buffer_
.resize(
size_
);
15
reset
();
16
}
17
18
~CircularBuffer
() =
default
;
19
20
void
reset
() {
21
rptr_
= 0;
22
wptr_
= 0;
23
}
24
25
//Full if writer ptr incremented is same as read ptr
26
bool
full
()
const
{
return
((
wptr_
+ 1) %
size_
) ==
rptr_
; }
27
28
//Almost full if writer ptr incremented by 1 or 2 is same as read ptr
29
bool
almostfull
()
const
{
return
(((
wptr_
+ 1) %
size_
) ==
rptr_
) || (((
wptr_
+ 2) %
size_
) ==
rptr_
); }
30
31
//near full if writer ptr incremented by 1, 2, or 3 is same as read ptr
32
bool
nearfull
()
const
{
33
return
(((
wptr_
+ 1) %
size_
) ==
rptr_
) || (((
wptr_
+ 2) %
size_
) ==
rptr_
) || (((
wptr_
+ 3) %
size_
) ==
rptr_
);
34
}
35
36
//Empty buffer is write ptr is same as read ptr
37
bool
empty
()
const
{
return
wptr_
==
rptr_
; }
38
39
const
T
&
read
() {
40
assert
(!
empty
());
41
unsigned
int
oldrptr =
rptr_
;
42
rptr_
= (
rptr_
+ 1) %
size_
;
43
return
buffer_
[oldrptr];
44
}
45
46
const
T
&
peek
()
const
{
47
assert
(!
empty
());
48
return
buffer_
[
rptr_
];
49
}
50
51
void
store
(
T
element) {
52
assert
(!
full
());
53
buffer_
[
wptr_
++] = element;
54
wptr_
=
wptr_
%
size_
;
55
assert
(
wptr_
!=
rptr_
);
56
}
57
58
//these are needed for comparison of emulation with HLS FW
59
unsigned
int
rptr
()
const
{
return
rptr_
; }
60
unsigned
int
wptr
()
const
{
return
wptr_
; }
61
62
private
:
63
std::vector<T>
buffer_
;
64
65
//buffer size
66
unsigned
int
size_
;
67
68
//read and write poiters into buffer
69
unsigned
int
rptr_
;
70
unsigned
int
wptr_
;
71
};
72
};
// namespace trklet
73
#endif
trklet::CircularBuffer::size_
unsigned int size_
Definition:
CircularBuffer.h:66
trklet::CircularBuffer::peek
const T & peek() const
Definition:
CircularBuffer.h:46
trklet::CircularBuffer::reset
void reset()
Definition:
CircularBuffer.h:20
trklet::CircularBuffer::full
bool full() const
Definition:
CircularBuffer.h:26
trklet::CircularBuffer::read
const T & read()
Definition:
CircularBuffer.h:39
trklet::CircularBuffer::~CircularBuffer
~CircularBuffer()=default
cms::cuda::assert
assert(be >=bs)
trklet::CircularBuffer::nearfull
bool nearfull() const
Definition:
CircularBuffer.h:32
trklet::CircularBuffer::CircularBuffer
CircularBuffer(unsigned int nbits)
Definition:
CircularBuffer.h:12
trklet::CircularBuffer
Definition:
CircularBuffer.h:10
trklet::CircularBuffer::wptr
unsigned int wptr() const
Definition:
CircularBuffer.h:60
trklet::CircularBuffer::almostfull
bool almostfull() const
Definition:
CircularBuffer.h:29
trklet::CircularBuffer::store
void store(T element)
Definition:
CircularBuffer.h:51
trklet::CircularBuffer::rptr_
unsigned int rptr_
Definition:
CircularBuffer.h:69
trklet
Definition:
AllInnerStubsMemory.h:10
trklet::CircularBuffer::rptr
unsigned int rptr() const
Definition:
CircularBuffer.h:59
T
long double T
Definition:
Basic3DVectorLD.h:48
trklet::CircularBuffer::wptr_
unsigned int wptr_
Definition:
CircularBuffer.h:70
trklet::CircularBuffer::buffer_
std::vector< T > buffer_
Definition:
CircularBuffer.h:63
trklet::CircularBuffer::empty
bool empty() const
Definition:
CircularBuffer.h:37
Generated for CMSSW Reference Manual by
1.8.16