CMS 3D CMS Logo

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

#include <FragmentStore.h>

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

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().

11  : maxMemoryUsage_(maxMemoryUsageMB*1024*1024)
12 {
13  clear();
14 }
const size_t maxMemoryUsage_
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().

17 {
18  // the trivial case that the chain is already complete
19  if ( chain.complete() ) return true;
20 
21  memoryUsed_ += chain.memoryUsed();
22  const FragKey newKey = chain.fragmentKey();
23 
24  // Use efficientAddOrUpdates pattern suggested by Item 24 of
25  // 'Effective STL' by Scott Meyers
26  fragmentMap::iterator pos = store_.lower_bound(newKey);
27 
28  if(pos != store_.end() && !(store_.key_comp()(newKey, pos->first)))
29  {
30  // key already exists
31  pos->second.addToChain(chain);
32 
33  if ( pos->second.complete() )
34  {
35  chain = pos->second;
36  store_.erase(pos);
37  memoryUsed_ -= chain.memoryUsed();
38  return true;
39  }
40  }
41  else
42  {
44 
45  // The key does not exist in the map, add it to the map
46  // Use pos as a hint to insert, so it can avoid another lookup
47  store_.insert(pos, fragmentMap::value_type(newKey, chain));
48  chain.release();
49 
50  // We already handled the trivial case that the chain is complete.
51  // Thus, store_ will not have a complete event.
52  }
53 
54  return false;
55 }
bool complete() const
Definition: I2OChain.cc:118
Container::value_type value_type
void release()
Definition: I2OChain.cc:210
size_t memoryUsed() const
Definition: I2OChain.cc:426
FragKey fragmentKey() const
Definition: I2OChain.cc:278
void resetStaleWindowStartTime()
Definition: I2OChain.cc:314
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().

58 {
59  for (
60  fragmentMap::iterator it = store_.begin(), itEnd = store_.end();
61  it != itEnd;
62  ++it
63  )
64  {
65  it->second.addToStaleWindowStartTime(duration);
66  }
67 }
void stor::FragmentStore::clear ( void  )
inline
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(), Vispa.Gui.VispaWidget.TextField::setAutosizeFont(), and Vispa.Gui.VispaWidget.TextField::setAutotruncate().

75  { 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().

82  { return (memoryUsed_ >= maxMemoryUsage_); }
const size_t 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_.

82 {
83  const utils::TimePoint_t cutOffTime = utils::getCurrentTime() - timeout;
84 
85  fragmentMap::iterator pos = store_.begin();
86  fragmentMap::iterator end = store_.end();
87 
88  while ( (pos != end) && (pos->second.staleWindowStartTime() > cutOffTime ) )
89  {
90  ++pos;
91  }
92 
93  if ( pos == end )
94  {
95  chain.release();
96  return false;
97  }
98  else
99  {
100  chain = pos->second;
101  store_.erase(pos);
102  memoryUsed_ -= chain.memoryUsed();
103  chain.markFaulty();
104  return true;
105  }
106 }
TimePoint_t getCurrentTime()
Definition: Utils.h:158
boost::posix_time::ptime TimePoint_t
Definition: Utils.h:35
#define end
Definition: vmac.h:38
void release()
Definition: I2OChain.cc:210
size_t memoryUsed() const
Definition: I2OChain.cc:426
void markFaulty()
Definition: I2OChain.cc:198
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().

96  { 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_.

70 {
71  for (
72  fragmentMap::iterator it = store_.begin(), itEnd = store_.end();
73  it != itEnd;
74  ++it
75  )
76  {
77  it->second.resetStaleWindowStartTime();
78  }
79 }
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().

89  { return store_.size(); }

Member Data Documentation

const size_t stor::FragmentStore::maxMemoryUsage_
private

Definition at line 109 of file FragmentStore.h.

Referenced by full().

size_t stor::FragmentStore::memoryUsed_
private

Definition at line 108 of file FragmentStore.h.

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

fragmentMap stor::FragmentStore::store_
private