CMS 3D CMS Logo

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

stor::FragmentStore Class Reference

#include <FragmentStore.h>

List of all members.

Public Member Functions

const bool addFragment (I2OChain &)
void addToStaleEventTimes (const utils::Duration_t)
void clear ()
bool empty () const
 FragmentStore (size_t maxMemoryUsageMB)
bool full () const
const bool getStaleEvent (I2OChain &, utils::Duration_t timeout)
size_t memoryUsed () const
void resetStaleEventTimes ()
unsigned int size () const

Private Types

typedef std::map< FragKey,
I2OChain
fragmentMap

Private Member Functions

 FragmentStore (FragmentStore const &)
FragmentStoreoperator= (FragmentStore const &)

Private Attributes

const size_t maxMemoryUsage_
size_t memoryUsed_
fragmentMap store_

Detailed Description

Stores incomplete events

Uses a map of I2OChains to store incomplete events.

Author:
wmtan
Revision:
1.11
Date:
2011/08/31 20:11:59

Definition at line 26 of file FragmentStore.h.


Member Typedef Documentation

typedef std::map<FragKey, I2OChain> stor::FragmentStore::fragmentMap [private]

Definition at line 105 of file FragmentStore.h.


Constructor & Destructor Documentation

FragmentStore::FragmentStore ( size_t  maxMemoryUsageMB) [explicit]

Definition at line 10 of file FragmentStore.cc.

References clear().

  : maxMemoryUsage_(maxMemoryUsageMB*1024*1024)
{
  clear();
}
stor::FragmentStore::FragmentStore ( FragmentStore const &  ) [private]

Member Function Documentation

const bool FragmentStore::addFragment ( I2OChain chain)

Adds fragments of the I2OChain to the fragment store. If the passed fragments completes an event, it returns true. In this case, the passed I2OChain contains the completed event. Otherwise, it returns false and the I2OChain is empty.

Definition at line 16 of file FragmentStore.cc.

References stor::I2OChain::complete(), stor::I2OChain::fragmentKey(), stor::I2OChain::memoryUsed(), memoryUsed_, pos, stor::I2OChain::release(), stor::I2OChain::resetStaleWindowStartTime(), and store_.

Referenced by stor::Processing::do_processI2OFragment().

{
  // the trivial case that the chain is already complete
  if ( chain.complete() ) return true;

  memoryUsed_ += chain.memoryUsed();
  const FragKey newKey = chain.fragmentKey();

  // Use efficientAddOrUpdates pattern suggested by Item 24 of 
  // 'Effective STL' by Scott Meyers
  fragmentMap::iterator pos = store_.lower_bound(newKey);

  if(pos != store_.end() && !(store_.key_comp()(newKey, pos->first)))
  {
    // key already exists
    pos->second.addToChain(chain);

    if ( pos->second.complete() )
    {
      chain = pos->second;
      store_.erase(pos);
      memoryUsed_ -= chain.memoryUsed();
      return true;
    }
  }
  else
  {
    chain.resetStaleWindowStartTime();

    // The key does not exist in the map, add it to the map
    // Use pos as a hint to insert, so it can avoid another lookup
    store_.insert(pos, fragmentMap::value_type(newKey, chain));
    chain.release();

    // We already handled the trivial case that the chain is complete.
    // Thus, store_ will not have a complete event.
  }

  return false;
}
void FragmentStore::addToStaleEventTimes ( const utils::Duration_t  duration)

Add the duration to the stale window start time for all I2OChains hold by the store.

Definition at line 57 of file FragmentStore.cc.

References store_.

Referenced by stor::FragmentProcessor::processOneFragmentIfPossible().

{
  for (
    fragmentMap::iterator it = store_.begin(), itEnd = store_.end();
    it != itEnd;
    ++it
  )
  {
    it->second.addToStaleWindowStartTime(duration);
  }
}
void stor::FragmentStore::clear ( void  ) [inline]

Clears all fragments hold by the fragment store

Definition at line 67 of file FragmentStore.h.

References memoryUsed_, and store_.

Referenced by stor::DrainingQueues::allQueuesAndWorkersAreEmpty(), and FragmentStore().

    { store_.clear(); memoryUsed_ = 0; }
bool stor::FragmentStore::empty ( void  ) const [inline]

Checks if the fragment store is empty

Definition at line 74 of file FragmentStore.h.

References store_.

Referenced by stor::DrainingQueues::allQueuesAndWorkersAreEmpty().

    { return store_.empty(); }
bool stor::FragmentStore::full ( ) const [inline]

Checks if the fragment store is full

Definition at line 81 of file FragmentStore.h.

References maxMemoryUsage_, and memoryUsed_.

Referenced by stor::FragmentProcessor::processOneFragmentIfPossible().

    { return (memoryUsed_ >= maxMemoryUsage_); }
const bool FragmentStore::getStaleEvent ( I2OChain chain,
utils::Duration_t  timeout 
)

Checks for event fragments for which the last event fragment was added longer than timeout seconds ago. If it finds one it returns true and the I2OChain contains the faulty event. Otherwise it returns false and the I2OChain is empty.

Definition at line 81 of file FragmentStore.cc.

References end, stor::utils::getCurrentTime(), stor::I2OChain::markFaulty(), stor::I2OChain::memoryUsed(), memoryUsed_, pos, stor::I2OChain::release(), and store_.

{
  const utils::TimePoint_t cutOffTime = utils::getCurrentTime() - timeout;
  
  fragmentMap::iterator pos = store_.begin();
  fragmentMap::iterator end = store_.end();

  while ( (pos != end) && (pos->second.staleWindowStartTime() > cutOffTime ) )
  {
    ++pos;
  }

  if ( pos == end )
  {
    chain.release();
    return false;
  }
  else
  {
    chain = pos->second;
    store_.erase(pos);
    memoryUsed_ -= chain.memoryUsed();
    chain.markFaulty();
    return true;
  }
}
size_t stor::FragmentStore::memoryUsed ( ) const [inline]

Returns the total memory occupied by the events in the fragment store

Definition at line 95 of file FragmentStore.h.

References memoryUsed_.

Referenced by stor::Processing::do_processI2OFragment().

    { return memoryUsed_; }
FragmentStore& stor::FragmentStore::operator= ( FragmentStore const &  ) [private]
void FragmentStore::resetStaleEventTimes ( )

Resets the stale window start time for all I2OChains hold by the store.

Definition at line 69 of file FragmentStore.cc.

References store_.

{
  for (
    fragmentMap::iterator it = store_.begin(), itEnd = store_.end();
    it != itEnd;
    ++it
  )
  {
    it->second.resetStaleWindowStartTime();
  }
}
unsigned int stor::FragmentStore::size ( void  ) const [inline]

Returns the number of events in the fragment store (complete or not).

Definition at line 88 of file FragmentStore.h.

References store_.

Referenced by stor::Processing::do_processI2OFragment().

    { return store_.size(); }

Member Data Documentation

const size_t stor::FragmentStore::maxMemoryUsage_ [private]

Definition at line 109 of file FragmentStore.h.

Referenced by full().

Definition at line 108 of file FragmentStore.h.

Referenced by addFragment(), clear(), full(), getStaleEvent(), and memoryUsed().