#include <RawCache.h>
Public Member Functions | |
RawMsgBuf * | getMsgToWrite () |
void | initialise (unsigned int nMsgs, unsigned int cellSize) |
void | printUsage () const |
void | releaseMsg (unsigned int fuResourceId) |
virtual | ~RawCache () |
Static Public Member Functions | |
static RawCache * | getInstance () |
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 RawCache * | instance_ = 0 |
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.
Definition at line 28 of file RawCache.h.
RawCache::~RawCache | ( | ) | [virtual] |
Definition at line 56 of file RawCache.cc.
References msgs_, and slotUsage_.
{ delete[] slotUsage_; delete[] msgs_; }
RawCache::RawCache | ( | ) | [private] |
Definition at line 94 of file RawCache.cc.
Referenced by getInstance().
: initialised_(false), nMsgs_(0) { }
int RawCache::getFreeSlot | ( | ) | const [private] |
Definition at line 99 of file RawCache.cc.
References i, nMsgs_, and slotUsage_.
Referenced by getMsgToWrite().
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().
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().
{ int freeSlot = getFreeSlot(); while (freeSlot == -1) { cout << "NO FREE SLOTS IN CACHE!" << endl; //improve remove print usage printUsage(); ::sleep(1); } slotUsage_[freeSlot] = true; return msgs_[freeSlot]; }
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_.
{ if (!initialised_) { // set the desired size of the cache nMsgs_ = nMsgs; //set the cell size of all cells cellSize_ = cellSize; msgs_ = new RawMsgBuf*[nMsgs_]; // initialise array with flags regarding cache slot usage slotUsage_ = new bool[nMsgs_]; // set all slots free and initialise for (unsigned int i = 0; i < nMsgs_; i++) { // not contiguous memory!! msgs_[i] = new RawMsgBuf(MAX_MSG_SIZE, RAW_MESSAGE_TYPE); msgs_[i]->initialise(cellSize_); slotUsage_[i] = false; } initialised_ = true; } }
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().
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().
{ RawMsgBuf* found = 0; for (unsigned int i = 0; i < nMsgs_; i++) if (slotUsage_[i]) if (msgs_[i]->rawCell()->fuResourceId() == fuResourceId) found = msgs_[i]; if (found != 0) { found->rawCell()->clear(); setFree(found); //printUsage(); } else cout << "RAW MSG BUF corresponding to fuResourceId = " << fuResourceId << "not found in internal allocation list!" << endl; }
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().
{ for (unsigned int i = 0; i < nMsgs_; i++) if (slotUsage_[i]) if (msgs_[i] == rmb) { slotUsage_[i] = false; return; } cout << "ERROR: Raw Message Buffer to free at address: " << rmb << " not found in internal allocation list!" << endl; }
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 [static, private] |
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] |
Definition at line 69 of file RawCache.h.
Referenced by getFreeSlot(), getMsgToWrite(), initialise(), printUsage(), releaseMsg(), setFree(), and ~RawCache().