CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ExpirableQueue.h
Go to the documentation of this file.
1 // $Id: ExpirableQueue.h,v 1.8 2011/03/07 15:31:31 mommsen Exp $
3 
4 
5 #ifndef EventFilter_StorageManager_ExpirableQueue_h
6 #define EventFilter_StorageManager_ExpirableQueue_h
7 
12 
13 namespace stor
14 {
26  template <class T, class Policy>
28  {
29  public:
30  typedef Policy PolicyType; // publish template parameter
32  typedef typename Policy::ValueType ValueType;
33 
38  explicit ExpirableQueue
39  (
43  );
52  bool deqNowait(ValueType&);
53 
62  (
63  T const&,
65  );
66 
71 
76 
80  SizeType clear();
81 
85  bool empty() const;
86 
90  bool full() const;
91 
95  bool stale(const utils::TimePoint_t&) const;
96 
100  SizeType size() const;
101 
108  bool clearIfStale(const utils::TimePoint_t&, SizeType& clearedEvents);
109 
110  private:
112 
118 
119  /*
120  The following are not implemented, to prevent copying and
121  assignment.
122  */
125  };
126 
127 
128  template <class T, class Policy>
130  (
131  SizeType maxsize,
132  utils::Duration_t stalenessInterval,
134  ) :
135  events_(maxsize),
136  stalenessInterval_(stalenessInterval),
137  stalenessTime_(now+stalenessInterval_)
138  {
139  }
140 
141  template <class T, class Policy>
142  bool
144  {
145  stalenessTime_ = utils::getCurrentTime() + stalenessInterval_;
146  return events_.deqNowait(event);
147  }
148 
149  template <class T, class Policy>
152  {
153  if ( stale(now) )
154  {
155  events_.addExternallyDroppedEvents(1);
156  return 1;
157  }
158  return events_.enqNowait(event);
159  }
160 
161  template <class T, class Policy>
162  inline
163  void
165  {
166  stalenessInterval_ = t;
167  }
168 
169  template <class T, class Policy>
170  inline
173  {
174  return stalenessInterval_;
175  }
176 
177  template <class T, class Policy>
178  inline
181  {
182  return events_.clear();
183  }
184 
185  template <class T, class Policy>
186  inline
187  bool
189  {
190  return events_.empty();
191  }
192 
193  template <class T, class Policy>
194  inline
197  {
198  return events_.size();
199  }
200 
201  template <class T, class Policy>
202  inline
203  bool
205  {
206  return events_.full();
207  }
208 
209  template <class T, class Policy>
210  inline
211  bool
213  {
214  return (stalenessTime_ < now);
215  }
216 
217  template <class T, class Policy>
218  inline
219  bool
221  (
222  const utils::TimePoint_t& now,
223  SizeType& clearedEvents
224  )
225  {
226  if (stalenessTime_ < now)
227  {
228  clearedEvents = clear();
229  return true;
230  }
231  else
232  {
233  clearedEvents = 0;
234  return false;
235  }
236  }
237 
238 } // namespace stor
239 
240 
241 #endif // EventFilter_StorageManager_ExpirableQueue_h
242 
249 
TimePoint_t getCurrentTime()
Definition: Utils.h:158
double seconds()
bool stale(const utils::TimePoint_t &) const
SizeType enqNowait(T const &, const utils::TimePoint_t &now=utils::getCurrentTime())
SizeType size() const
utils::Duration_t stalenessInterval() const
boost::posix_time::time_duration Duration_t
Definition: Utils.h:41
const T & max(const T &a, const T &b)
ConcurrentQueue< T, Policy >::SizeType SizeType
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:168
utils::TimePoint_t stalenessTime_
Policy::ValueType ValueType
boost::posix_time::ptime TimePoint_t
Definition: Utils.h:35
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
ConcurrentQueue< T, Policy > queue_t
utils::Duration_t stalenessInterval_
void setStalenessInterval(const utils::Duration_t &)
ExpirableQueue(SizeType maxsize=std::numeric_limits< SizeType >::max(), utils::Duration_t stalenessInterval=boost::posix_time::seconds(120), utils::TimePoint_t now=utils::getCurrentTime())
bool clearIfStale(const utils::TimePoint_t &, SizeType &clearedEvents)
bool deqNowait(ValueType &)
long double T
ExpirableQueue & operator=(ExpirableQueue &)