Public Types | Public Member Functions | Private Attributes | List of all members
novaddt::MessageBuffer Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-24/SuperNovaDDT/online/MessageBuffer.h"

Public Types

using TimeType = uint64_t
 
using DataType = uint64_t
 
using Point = std::pair< TimeType, DataType >
 
using PointAllocator = boost::interprocess::allocator< Point, boost::interprocess::managed_shared_memory::segment_manager >
 a point is pair (timestamp,nclusters) More...
 
using PointVector = boost::interprocess::vector< Point, PointAllocator >
 
using interprocess_mutex = boost::interprocess::interprocess_mutex
 
using scoped_lock = boost::interprocess::scoped_lock< interprocess_mutex >
 

Public Member Functions

 MessageBuffer (const char *shmemName, const char *bufName, size_t Capacity=10)
 
 ~MessageBuffer ()
 
void addPoint (Point p)
 
bool isFull ()
 
size_t size ()
 
size_t capacity ()
 
void clear ()
 
nsnmessages::NSNPackedMessage makeMessage ()
 
scoped_lock ScopedLock ()
 

Private Attributes

novaddt::sm_cleaner _sm_cleaner
 
boost::interprocess::managed_shared_memory _segment
 
const PointAllocator _allocator
 
PointVector_buffer
 
interprocess_mutex_mutex
 
unsigned * _counter
 
size_t _capacity
 

Detailed Description

Definition at line 33 of file MessageBuffer.h.

Member Typedef Documentation

Definition at line 38 of file MessageBuffer.h.

using novaddt::MessageBuffer::interprocess_mutex = boost::interprocess::interprocess_mutex

Definition at line 43 of file MessageBuffer.h.

Definition at line 39 of file MessageBuffer.h.

using novaddt::MessageBuffer::PointAllocator = boost::interprocess::allocator <Point,boost::interprocess::managed_shared_memory::segment_manager>

a point is pair (timestamp,nclusters)

Definition at line 41 of file MessageBuffer.h.

using novaddt::MessageBuffer::PointVector = boost::interprocess::vector<Point, PointAllocator>

Definition at line 42 of file MessageBuffer.h.

using novaddt::MessageBuffer::scoped_lock = boost::interprocess::scoped_lock<interprocess_mutex>

Definition at line 44 of file MessageBuffer.h.

a class to manage point buffer in shared memory When 10 points are accumulated, we can form an NSNPackedMessage

Definition at line 37 of file MessageBuffer.h.

Constructor & Destructor Documentation

novaddt::MessageBuffer::MessageBuffer ( const char *  shmemName,
const char *  bufName,
size_t  Capacity = 10 
)
inline

Definition at line 46 of file MessageBuffer.h.

References om::cout, and allTimeWatchdog::endl.

46  :
47  _sm_cleaner(shmemName),
48  _segment(boost::interprocess::open_or_create, shmemName, 65536),
49  _allocator(_segment.get_segment_manager()),
50  _buffer(_segment.find_or_construct<PointVector>(bufName)(_allocator)),
51  _mutex(_segment.find_or_construct<interprocess_mutex>("mtx")()),
52  _capacity(Capacity)
53  {
54  scoped_lock lock(*_mutex);
55  //set buffer length
56  _buffer->reserve(_capacity);
57  boost::interprocess::managed_shared_memory::shrink_to_fit(shmemName);
58  std::cout<<"Open messageBuffer \""<<bufName<<"\" of size= "<<_segment.get_size()<<std::endl;
59  }
novaddt::sm_cleaner _sm_cleaner
Definition: MessageBuffer.h:86
boost::interprocess::interprocess_mutex interprocess_mutex
Definition: MessageBuffer.h:43
interprocess_mutex * _mutex
Definition: MessageBuffer.h:90
boost::interprocess::vector< Point, PointAllocator > PointVector
Definition: MessageBuffer.h:42
boost::interprocess::managed_shared_memory _segment
Definition: MessageBuffer.h:87
PointVector * _buffer
Definition: MessageBuffer.h:89
OStream cout
Definition: OStream.cxx:6
boost::interprocess::scoped_lock< interprocess_mutex > scoped_lock
Definition: MessageBuffer.h:44
const PointAllocator _allocator
Definition: MessageBuffer.h:88
novaddt::MessageBuffer::~MessageBuffer ( )
inline

Definition at line 61 of file MessageBuffer.h.

61  {
62  }

Member Function Documentation

void novaddt::MessageBuffer::addPoint ( Point  p)
inline

Definition at line 64 of file MessageBuffer.h.

Referenced by novaddt::SNMessageService::PushPoint().

64  {
65  if(isFull())
66  throw std::logic_error("Trying to fill full buffer");
67  _buffer->push_back(p);
68  }
const char * p
Definition: xmltok.h:285
PointVector * _buffer
Definition: MessageBuffer.h:89
size_t novaddt::MessageBuffer::capacity ( )
inline

Definition at line 71 of file MessageBuffer.h.

71 {return _capacity;}
void novaddt::MessageBuffer::clear ( )
inline

Definition at line 72 of file MessageBuffer.h.

Referenced by novaddt::SNMessageService::PushPoint().

72 {_buffer->clear();}
PointVector * _buffer
Definition: MessageBuffer.h:89
bool novaddt::MessageBuffer::isFull ( )
inline

Definition at line 69 of file MessageBuffer.h.

Referenced by novaddt::SNMessageService::PushPoint().

69 {return (_buffer->size()>=_capacity);}
PointVector * _buffer
Definition: MessageBuffer.h:89
nsnmessages::NSNPackedMessage novaddt::MessageBuffer::makeMessage ( )
inline

Definition at line 74 of file MessageBuffer.h.

References MECModelEnuComparisons::i, and m.

Referenced by novaddt::SNMessageService::PushPoint().

74  {
75  //prepare a message to be sent
76  nsnmessages::NSNPackedMessage m;
77  for(size_t i=0;i<_capacity;++i){
78  Point p=_buffer->at(i);
79  m.time[i]=p.first;
80  m.hits[i]=p.second;
81  }
82  return m;
83  }
const char * p
Definition: xmltok.h:285
std::pair< TimeType, DataType > Point
Definition: MessageBuffer.h:39
PointVector * _buffer
Definition: MessageBuffer.h:89
scoped_lock novaddt::MessageBuffer::ScopedLock ( )
inline

Definition at line 84 of file MessageBuffer.h.

Referenced by novaddt::SNMessageService::PushPoint().

84 {return scoped_lock(*_mutex);}
interprocess_mutex * _mutex
Definition: MessageBuffer.h:90
boost::interprocess::scoped_lock< interprocess_mutex > scoped_lock
Definition: MessageBuffer.h:44
size_t novaddt::MessageBuffer::size ( )
inline

Definition at line 70 of file MessageBuffer.h.

70 {return _buffer->size();}
PointVector * _buffer
Definition: MessageBuffer.h:89

Member Data Documentation

const PointAllocator novaddt::MessageBuffer::_allocator
private

Definition at line 88 of file MessageBuffer.h.

PointVector* novaddt::MessageBuffer::_buffer
private
size_t novaddt::MessageBuffer::_capacity
private

Definition at line 92 of file MessageBuffer.h.

unsigned* novaddt::MessageBuffer::_counter
private

Definition at line 91 of file MessageBuffer.h.

interprocess_mutex* novaddt::MessageBuffer::_mutex
private

Definition at line 90 of file MessageBuffer.h.

boost::interprocess::managed_shared_memory novaddt::MessageBuffer::_segment
private

Definition at line 87 of file MessageBuffer.h.

novaddt::sm_cleaner novaddt::MessageBuffer::_sm_cleaner
private

Definition at line 86 of file MessageBuffer.h.


The documentation for this class was generated from the following file: