CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
trklet::CircularBuffer< T > Class Template Reference

#include <CircularBuffer.h>

Public Member Functions

bool almostfull () const
 
 CircularBuffer (unsigned int nbits)
 
bool empty () const
 
bool full () const
 
const Tpeek () const
 
const Tread ()
 
void reset ()
 
void store (T element)
 
 ~CircularBuffer ()=default
 

Private Attributes

std::vector< Tbuffer_
 
unsigned int rptr_
 
unsigned int size_
 
unsigned int wptr_
 

Detailed Description

template<class T>
class trklet::CircularBuffer< T >

Definition at line 10 of file CircularBuffer.h.

Constructor & Destructor Documentation

◆ CircularBuffer()

template<class T>
trklet::CircularBuffer< T >::CircularBuffer ( unsigned int  nbits)
inline

Definition at line 12 of file CircularBuffer.h.

12  {
13  size_ = 1 << nbits;
14  buffer_.resize(size_);
15  reset();
16  }

◆ ~CircularBuffer()

template<class T>
trklet::CircularBuffer< T >::~CircularBuffer ( )
default

Member Function Documentation

◆ almostfull()

template<class T>
bool trklet::CircularBuffer< T >::almostfull ( ) const
inline

Definition at line 29 of file CircularBuffer.h.

29 { return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_); }

◆ empty()

template<class T>
bool trklet::CircularBuffer< T >::empty ( void  ) const
inline

◆ full()

template<class T>
bool trklet::CircularBuffer< T >::full ( ) const
inline

Definition at line 26 of file CircularBuffer.h.

26 { return ((wptr_ + 1) % size_) == rptr_; }

Referenced by trklet::TrackletProcessor::execute(), and trklet::CircularBuffer< trklet::ProjectionTemp >::store().

◆ peek()

template<class T>
const T& trklet::CircularBuffer< T >::peek ( ) const
inline

Definition at line 41 of file CircularBuffer.h.

41  {
42  assert(!empty());
43  return buffer_[rptr_];
44  }

◆ read()

template<class T>
const T& trklet::CircularBuffer< T >::read ( )
inline

Definition at line 34 of file CircularBuffer.h.

34  {
35  assert(!empty());
36  unsigned int oldrptr = rptr_;
37  rptr_ = (rptr_ + 1) % size_;
38  return buffer_[oldrptr];
39  }

Referenced by trklet::TrackletProcessor::execute(), and edmIntegrityCheck.PublishToFileSystem::get().

◆ reset()

template<class T>
void trklet::CircularBuffer< T >::reset ( void  )
inline

Definition at line 20 of file CircularBuffer.h.

20  {
21  rptr_ = 0;
22  wptr_ = 0;
23  }

Referenced by trklet::TrackletProcessor::addInput(), and trklet::CircularBuffer< trklet::ProjectionTemp >::CircularBuffer().

◆ store()

template<class T>
void trklet::CircularBuffer< T >::store ( T  element)
inline

Definition at line 46 of file CircularBuffer.h.

46  {
47  assert(!full());
48  buffer_[wptr_++] = element;
49  wptr_ = wptr_ % size_;
50  }

Referenced by trklet::TrackletProcessor::execute().

Member Data Documentation

◆ buffer_

template<class T>
std::vector<T> trklet::CircularBuffer< T >::buffer_
private

◆ rptr_

template<class T>
unsigned int trklet::CircularBuffer< T >::rptr_
private

◆ size_

template<class T>
unsigned int trklet::CircularBuffer< T >::size_
private

◆ wptr_

template<class T>
unsigned int trklet::CircularBuffer< T >::wptr_
private
trklet::CircularBuffer::size_
unsigned int size_
Definition: CircularBuffer.h:56
trklet::CircularBuffer::reset
void reset()
Definition: CircularBuffer.h:20
trklet::CircularBuffer::full
bool full() const
Definition: CircularBuffer.h:26
cms::cuda::assert
assert(be >=bs)
trklet::CircularBuffer::rptr_
unsigned int rptr_
Definition: CircularBuffer.h:59
trklet::CircularBuffer::wptr_
unsigned int wptr_
Definition: CircularBuffer.h:60
trklet::CircularBuffer::buffer_
std::vector< T > buffer_
Definition: CircularBuffer.h:53
trklet::CircularBuffer::empty
bool empty() const
Definition: CircularBuffer.h:32