CFEL - ASG Software Suite  2.5.0
CASS
ratemeter.cpp
Go to the documentation of this file.
1 //Copyright (C) 2010 Lutz Foucar
2 
3 /**
4  * @file ratemeter.cpp file contains definition of class calculating a rate
5  *
6  * @author Lutz Foucar
7  */
8 
9 #include <iostream>
10 #include <cmath>
11 
12 #include "ratemeter.h"
13 
14 using namespace cass;
15 using namespace std;
16 
17 Ratemeter::Ratemeter(const double averagetime)
18  : _counts(0),
19  _rate(0),
20  _averagetime(averagetime)
21 {
22  //start the clock//
23  _time.start();
24 }
25 
27 {
28  //how long since the last calculation?//
29  const double elapsedtime = _time.elapsed();
30 
31  //calc rate//
32  _rate = ((1 - exp(-elapsedtime/_averagetime))*_counts) +
33  exp(-elapsedtime/_averagetime)*_rate;
34 
35  //reset values//
36  _counts = 0.;
37  _time.restart();
38 
39  return _rate;
40 }
41 
42 void Ratemeter::count(double increase)
43 {
44  QMutexLocker lock(&_mutex);
45  _counts += increase;
46 }
file contains declaration of class calculating a rate
double _rate
the current rate
Definition: ratemeter.h:67
STL namespace.
double _counts
a counter that will increase with each call to count
Definition: ratemeter.h:64
const double _averagetime
time constant with which the rate will decrease
Definition: ratemeter.h:70
double calculateRate()
retrieve the rate
Definition: ratemeter.cpp:26
void count(double increase=1.)
increase the counts
Definition: ratemeter.cpp:42
Ratemeter(const double averagetime=1)
constuctor
Definition: ratemeter.cpp:17
QMutex _mutex
mutex to make function counting reentrant
Definition: ratemeter.h:58
QTime _time
the time to stop the timeinterval
Definition: ratemeter.h:61