CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
evf::RawCache Class Reference

#include <RawCache.h>

Public Member Functions

RawMsgBufgetMsgToWrite ()
 
void initialise (unsigned int nMsgs, unsigned int cellSize)
 
void printUsage () const
 
void releaseMsg (unsigned int fuResourceId)
 
virtual ~RawCache ()
 

Static Public Member Functions

static RawCachegetInstance ()
 

Private Member Functions

int getFreeSlot () const
 
 RawCache ()
 
void setFree (RawMsgBuf *rawCell)
 

Private Attributes

unsigned int cellSize_
 
bool initialised_
 
RawMsgBuf ** msgs_
 
unsigned int nMsgs_
 
bool * slotUsage_
 

Static Private Attributes

static RawCacheinstance_ = 0
 

Detailed Description

Contains an array of RawMsgBuffer objects, as a backup for raw messages being sent over the message queue. In case event processors crash, these message buffers will be sent again.

Author:
aspataru

Definition at line 28 of file RawCache.h.

Constructor & Destructor Documentation

RawCache::~RawCache ( )
virtual

Definition at line 56 of file RawCache.cc.

References msgs_, and slotUsage_.

56  {
57  delete[] slotUsage_;
58  delete[] msgs_;
59 }
bool * slotUsage_
Definition: RawCache.h:69
RawMsgBuf ** msgs_
Definition: RawCache.h:67
RawCache::RawCache ( )
private

Definition at line 94 of file RawCache.cc.

Referenced by getInstance().

94  :
95  initialised_(false), nMsgs_(0) {
96 
97 }
bool initialised_
Definition: RawCache.h:66
unsigned int nMsgs_
Definition: RawCache.h:68

Member Function Documentation

int RawCache::getFreeSlot ( ) const
private

Definition at line 99 of file RawCache.cc.

References i, nMsgs_, and slotUsage_.

Referenced by getMsgToWrite().

99  {
100  for (unsigned int i = 0; i < nMsgs_; i++)
101  if (!slotUsage_[i])
102  return i;
103  return -1;
104 }
bool * slotUsage_
Definition: RawCache.h:69
int i
Definition: DBlmapReader.cc:9
unsigned int nMsgs_
Definition: RawCache.h:68
RawCache * RawCache::getInstance ( )
static

Returns the unique instance of this object.

Definition at line 25 of file RawCache.cc.

References instance_, and RawCache().

Referenced by evf::FUResourceQueue::discard(), evf::FUResourceQueue::discardWhileHalting(), and evf::FUResourceQueue::initialize().

25  {
26  if (instance_ == 0) {
27  instance_ = new RawCache();
28  }
29  return instance_;
30 }
static RawCache * instance_
Definition: RawCache.h:60
RawMsgBuf * RawCache::getMsgToWrite ( )

Returns a pointer to a message buffer ready to be written with raw data.

Definition at line 61 of file RawCache.cc.

References gather_cfg::cout, getFreeSlot(), msgs_, printUsage(), stor::utils::sleep(), and slotUsage_.

Referenced by evf::FUResourceQueue::buildResource().

61  {
62 
63  int freeSlot = getFreeSlot();
64 
65  while (freeSlot == -1) {
66  cout << "NO FREE SLOTS IN CACHE!" << endl;
67  //improve remove print usage
68  printUsage();
69  ::sleep(1);
70  }
71 
72  slotUsage_[freeSlot] = true;
73  return msgs_[freeSlot];
74 
75 }
bool * slotUsage_
Definition: RawCache.h:69
void sleep(Duration_t)
Definition: Utils.h:163
RawMsgBuf ** msgs_
Definition: RawCache.h:67
void printUsage() const
Definition: RawCache.cc:117
int getFreeSlot() const
Definition: RawCache.cc:99
tuple cout
Definition: gather_cfg.py:121
void RawCache::initialise ( unsigned int  nMsgs,
unsigned int  cellSize 
)

Initialize the cache with the given number of message buffers, and the given raw cell size for each one.

Definition at line 32 of file RawCache.cc.

References cellSize_, i, evf::RawMsgBuf::initialise(), initialised_, MAX_MSG_SIZE, msgs_, nMsgs_, evf::RAW_MESSAGE_TYPE, and slotUsage_.

32  {
33  if (!initialised_) {
34  // set the desired size of the cache
35  nMsgs_ = nMsgs;
36  //set the cell size of all cells
37  cellSize_ = cellSize;
38 
39  msgs_ = new RawMsgBuf*[nMsgs_];
40  // initialise array with flags regarding cache slot usage
41  slotUsage_ = new bool[nMsgs_];
42 
43  // set all slots free and initialise
44  for (unsigned int i = 0; i < nMsgs_; i++) {
45  // not contiguous memory!!
48 
49  slotUsage_[i] = false;
50  }
51  initialised_ = true;
52  }
53 
54 }
bool * slotUsage_
Definition: RawCache.h:69
int i
Definition: DBlmapReader.cc:9
#define MAX_MSG_SIZE
Definition: queue_defs.h:10
bool initialised_
Definition: RawCache.h:66
RawMsgBuf ** msgs_
Definition: RawCache.h:67
static const unsigned int RAW_MESSAGE_TYPE
Definition: msq_constants.h:14
void initialise(unsigned int rawCellSize)
Definition: RawMsgBuf.cc:18
unsigned int cellSize_
Definition: RawCache.h:68
unsigned int nMsgs_
Definition: RawCache.h:68
void RawCache::printUsage ( ) const

Prints the current slot usage in the cache.

Definition at line 117 of file RawCache.cc.

References gather_cfg::cout, i, nMsgs_, and slotUsage_.

Referenced by getMsgToWrite().

117  {
118  cout << "Raw Cache usage: ";
119  for (unsigned int i = 0; i < nMsgs_; i++)
120  cout << slotUsage_[i] << " ";
121  cout << endl;
122 }
bool * slotUsage_
Definition: RawCache.h:69
int i
Definition: DBlmapReader.cc:9
tuple cout
Definition: gather_cfg.py:121
unsigned int nMsgs_
Definition: RawCache.h:68
void RawCache::releaseMsg ( unsigned int  fuResourceId)

Releases a message buffer in the cache.

Definition at line 77 of file RawCache.cc.

References evf::FUShmRawCell::clear(), gather_cfg::cout, newFWLiteAna::found, i, msgs_, nMsgs_, evf::RawMsgBuf::rawCell(), setFree(), and slotUsage_.

Referenced by evf::FUResourceQueue::discard(), and evf::FUResourceQueue::discardWhileHalting().

77  {
78  RawMsgBuf* found = 0;
79 
80  for (unsigned int i = 0; i < nMsgs_; i++)
81  if (slotUsage_[i])
82  if (msgs_[i]->rawCell()->fuResourceId() == fuResourceId)
83  found = msgs_[i];
84 
85  if (found != 0) {
86  found->rawCell()->clear();
87  setFree(found);
88  //printUsage();
89  } else
90  cout << "RAW MSG BUF corresponding to fuResourceId = " << fuResourceId
91  << "not found in internal allocation list!" << endl;
92 }
bool * slotUsage_
Definition: RawCache.h:69
int i
Definition: DBlmapReader.cc:9
FUShmRawCell * rawCell()
Definition: RawMsgBuf.h:35
RawMsgBuf ** msgs_
Definition: RawCache.h:67
void setFree(RawMsgBuf *rawCell)
Definition: RawCache.cc:106
tuple cout
Definition: gather_cfg.py:121
unsigned int nMsgs_
Definition: RawCache.h:68
void RawCache::setFree ( RawMsgBuf rawCell)
private

Definition at line 106 of file RawCache.cc.

References gather_cfg::cout, i, msgs_, nMsgs_, and slotUsage_.

Referenced by releaseMsg().

106  {
107  for (unsigned int i = 0; i < nMsgs_; i++)
108  if (slotUsage_[i])
109  if (msgs_[i] == rmb) {
110  slotUsage_[i] = false;
111  return;
112  }
113  cout << "ERROR: Raw Message Buffer to free at address: " << rmb
114  << " not found in internal allocation list!" << endl;
115 }
bool * slotUsage_
Definition: RawCache.h:69
int i
Definition: DBlmapReader.cc:9
RawMsgBuf ** msgs_
Definition: RawCache.h:67
tuple cout
Definition: gather_cfg.py:121
unsigned int nMsgs_
Definition: RawCache.h:68

Member Data Documentation

unsigned int evf::RawCache::cellSize_
private

Definition at line 68 of file RawCache.h.

Referenced by initialise().

bool evf::RawCache::initialised_
private

Definition at line 66 of file RawCache.h.

Referenced by initialise().

RawCache * RawCache::instance_ = 0
staticprivate

Definition at line 60 of file RawCache.h.

Referenced by getInstance().

RawMsgBuf** evf::RawCache::msgs_
private

Definition at line 67 of file RawCache.h.

Referenced by getMsgToWrite(), initialise(), releaseMsg(), setFree(), and ~RawCache().

unsigned int evf::RawCache::nMsgs_
private

Definition at line 68 of file RawCache.h.

Referenced by getFreeSlot(), initialise(), printUsage(), releaseMsg(), and setFree().

bool* evf::RawCache::slotUsage_
private