CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes

edm::EventBuffer Class Reference

#include <EventBuffer.h>

List of all members.

Classes

struct  Buffer
struct  ConsumerType
class  OperateBuffer
struct  ProducerType

Public Types

typedef OperateBuffer
< ConsumerType
ConsumerBuffer
typedef OperateBuffer
< ProducerType
ProducerBuffer

Public Member Functions

void commitConsumerBuffer (void *, int)
void commitProducerBuffer (void *, int)
bool empty ()
 EventBuffer (int max_event_size, int max_queue_depth)
Buffer getConsumerBuffer ()
Buffer getProducerBuffer ()
int maxEventSize () const
int maxQueueDepth () const
void releaseConsumerBuffer (void *)
void releaseProducerBuffer (void *)
 ~EventBuffer ()

Private Types

typedef std::vector< char > ByteArray
typedef std::vector< void * > Pool
typedef std::vector< BufferQueue

Private Member Functions

 EventBuffer (const EventBuffer &)

Private Attributes

unsigned int bpos_
Pool buffer_pool_
unsigned int fpos_
int max_event_size_
int max_queue_depth_
ByteArray mem_
boost::condition pool_cond_
boost::mutex pool_lock_
boost::condition pop_cond_
int pos_
boost::condition push_cond_
Queue queue_
boost::mutex queue_lock_

Detailed Description

Definition at line 43 of file EventBuffer.h.


Member Typedef Documentation

typedef std::vector<char> edm::EventBuffer::ByteArray [private]

Definition at line 115 of file EventBuffer.h.

Definition at line 96 of file EventBuffer.h.

typedef std::vector<void*> edm::EventBuffer::Pool [private]

Definition at line 117 of file EventBuffer.h.

Definition at line 97 of file EventBuffer.h.

typedef std::vector<Buffer> edm::EventBuffer::Queue [private]

Definition at line 119 of file EventBuffer.h.


Constructor & Destructor Documentation

edm::EventBuffer::EventBuffer ( int  max_event_size,
int  max_queue_depth 
)

Definition at line 7 of file EventBuffer.cc.

References buffer_pool_, i, reco_skim_cfg_mod::max_event_size, and mem_.

                                                                 :
    max_event_size_(max_event_size),max_queue_depth_(max_queue_depth),
    pos_(max_queue_depth-1),mem_(max_event_size * max_queue_depth),
    queue_(max_queue_depth),
    fpos_(),bpos_()
  {
    // throw if event size 0 or queue depth 0

    for(char* i = &mem_[0]; i < &mem_[mem_.size()]; i += max_event_size)
      buffer_pool_.push_back(i);

  }
edm::EventBuffer::~EventBuffer ( )

Definition at line 20 of file EventBuffer.cc.

{ }
edm::EventBuffer::EventBuffer ( const EventBuffer ) [inline, private]

Definition at line 112 of file EventBuffer.h.

{ }

Member Function Documentation

void edm::EventBuffer::commitConsumerBuffer ( void *  v,
int   
)

Definition at line 90 of file EventBuffer.cc.

References releaseProducerBuffer().

Referenced by edm::EventBuffer::ConsumerType::commit().

void edm::EventBuffer::commitProducerBuffer ( void *  v,
int  len 
)

Definition at line 45 of file EventBuffer.cc.

References bpos_, fpos_, max_queue_depth_, pop_cond_, push_cond_, queue_, and queue_lock_.

Referenced by edm::EventBuffer::ProducerType::commit().

  {
    // get lock
    boost::mutex::scoped_lock sl(queue_lock_);
    // if full, wait for item to be removed
    while((bpos_+max_queue_depth_)==fpos_) {
        push_cond_.wait(sl);
    }
    
    // put buffer into queue
    queue_[fpos_ % max_queue_depth_]=Buffer(v,len);
    ++fpos_;
    // signal consumer
    pop_cond_.notify_one();
    // pop_cond_.notify_all();
  }
bool edm::EventBuffer::empty ( void  ) [inline]

Definition at line 136 of file EventBuffer.h.

References bpos_, fpos_, and queue_lock_.

{ boost::mutex::scoped_lock sl(queue_lock_); return (bpos_==fpos_); }
EventBuffer::Buffer edm::EventBuffer::getConsumerBuffer ( )

Definition at line 62 of file EventBuffer.cc.

References bpos_, fpos_, max_queue_depth_, pop_cond_, push_cond_, queue_, queue_lock_, and v.

  {
    // get lock
    boost::mutex::scoped_lock sl(queue_lock_);
    // if empty, wait for item to appear
    while(bpos_==fpos_) {
        pop_cond_.wait(sl);
    }
    // get a buffer from the queue and return it
    Buffer v = queue_[bpos_ % max_queue_depth_];
    ++bpos_;
    // note that these operations cannot throw
    // signal producer
    push_cond_.notify_one();
    // push_cond_.notify_all();
    return v;
  }
EventBuffer::Buffer edm::EventBuffer::getProducerBuffer ( )

Definition at line 22 of file EventBuffer.cc.

References buffer_pool_, max_event_size_, pool_cond_, pool_lock_, pos_, and v.

  {
    // get lock
    boost::mutex::scoped_lock sl(pool_lock_);
    // wait for buffer to appear
    while(pos_ < 0) {
        pool_cond_.wait(sl);
    }
    void* v = buffer_pool_[pos_];
    --pos_;
    return Buffer(v,max_event_size_);
  }
int edm::EventBuffer::maxEventSize ( ) const [inline]

Definition at line 107 of file EventBuffer.h.

References max_event_size_.

{ return max_event_size_; }
int edm::EventBuffer::maxQueueDepth ( ) const [inline]

Definition at line 108 of file EventBuffer.h.

References max_queue_depth_.

{ return max_queue_depth_; }
void edm::EventBuffer::releaseConsumerBuffer ( void *  v)

Definition at line 80 of file EventBuffer.cc.

References releaseProducerBuffer().

Referenced by edm::EventBuffer::ConsumerType::release().

  {
    // should the buffer be placed back onto the queue and not released?
    // we got here because a commit did to occur in the consumer.
    // we will allow consumers to call or not call commit for now, meaning
    // that we cannot distinguish between exception conditions and normal
    // return.  The buffer will always be released
    releaseProducerBuffer(v);
  }
void edm::EventBuffer::releaseProducerBuffer ( void *  v)

Definition at line 35 of file EventBuffer.cc.

References buffer_pool_, pool_cond_, pool_lock_, pos_, and v.

Referenced by commitConsumerBuffer(), edm::EventBuffer::ProducerType::release(), and releaseConsumerBuffer().

  {
    // get lock
    boost::mutex::scoped_lock sl(pool_lock_);
    ++pos_;
    buffer_pool_[pos_] = v;
    pool_cond_.notify_one();
    // pool_cond_.notify_all();
  }

Member Data Documentation

unsigned int edm::EventBuffer::bpos_ [private]

Definition at line 127 of file EventBuffer.h.

Referenced by commitProducerBuffer(), empty(), and getConsumerBuffer().

Definition at line 125 of file EventBuffer.h.

Referenced by EventBuffer(), getProducerBuffer(), and releaseProducerBuffer().

unsigned int edm::EventBuffer::fpos_ [private]

Definition at line 127 of file EventBuffer.h.

Referenced by commitProducerBuffer(), empty(), and getConsumerBuffer().

Definition at line 121 of file EventBuffer.h.

Referenced by getProducerBuffer(), and maxEventSize().

Definition at line 122 of file EventBuffer.h.

Referenced by commitProducerBuffer(), getConsumerBuffer(), and maxQueueDepth().

Definition at line 124 of file EventBuffer.h.

Referenced by EventBuffer().

boost::condition edm::EventBuffer::pool_cond_ [private]

Definition at line 131 of file EventBuffer.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

Definition at line 129 of file EventBuffer.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

boost::condition edm::EventBuffer::pop_cond_ [private]

Definition at line 132 of file EventBuffer.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

int edm::EventBuffer::pos_ [private]

Definition at line 123 of file EventBuffer.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

boost::condition edm::EventBuffer::push_cond_ [private]

Definition at line 133 of file EventBuffer.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

Definition at line 126 of file EventBuffer.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

Definition at line 130 of file EventBuffer.h.

Referenced by commitProducerBuffer(), empty(), and getConsumerBuffer().