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
 
bool nearfull () const
 
const Tpeek () const
 
const Tread ()
 
void reset ()
 
unsigned int rptr () const
 
void store (T element)
 
unsigned int wptr () const
 
 ~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::CircularBuffer< trklet::ProjectionTemp >::store().

◆ nearfull()

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

Definition at line 32 of file CircularBuffer.h.

32  {
33  return (((wptr_ + 1) % size_) == rptr_) || (((wptr_ + 2) % size_) == rptr_) || (((wptr_ + 3) % size_) == rptr_);
34  }

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

◆ peek()

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

Definition at line 46 of file CircularBuffer.h.

46  {
47  assert(!empty());
48  return buffer_[rptr_];
49  }

◆ read()

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

Definition at line 39 of file CircularBuffer.h.

39  {
40  assert(!empty());
41  unsigned int oldrptr = rptr_;
42  rptr_ = (rptr_ + 1) % size_;
43  return buffer_[oldrptr];
44  }

Referenced by 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::CircularBuffer< trklet::ProjectionTemp >::CircularBuffer().

◆ rptr()

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

Definition at line 59 of file CircularBuffer.h.

59 { return rptr_; }

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

◆ store()

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

Definition at line 51 of file CircularBuffer.h.

51  {
52  assert(!full());
53  buffer_[wptr_++] = element;
54  wptr_ = wptr_ % size_;
55  assert(wptr_ != rptr_);
56  }

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

◆ wptr()

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

Definition at line 60 of file CircularBuffer.h.

60 { return wptr_; }

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:66
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:69
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