CFEL - ASG Software Suite  2.5.0
CASS
ratemeter.h
Go to the documentation of this file.
1 //Copyright (C) 2010 Lutz Foucar
2 
3 /**
4  * @file ratemeter.h file contains declaration of class calculating a rate
5  *
6  * @author Lutz Foucar
7  */
8 
9 #ifndef _CASS_RATEMETER_H_
10 #define _CASS_RATEMETER_H_
11 
12 #include <vector>
13 
14 #include <QtCore/QTime>
15 #include <QtCore/QMutex>
16 
17 #include "cass.h"
18 
19 namespace cass
20 {
21 /** class calculating a rate in Hz.
22  *
23  * slot count has to be called to increase the count
24  * the current rate will be updated once the rate is retrieved
25  *
26  * @author Lutz Foucar
27  */
28 class Ratemeter
29 {
30 public:
31  /** constuctor
32  *
33  * @param averagetime time in seconds over which you want to average the
34  * rate. Default is 1 s.
35  */
36  Ratemeter(const double averagetime=1);
37 
38  /** retrieve the rate
39  *
40  * the rate is calculated using the formular found in wiki at
41  * @see http://en.wikipedia.org/wiki/Moving_average
42  * It uses the elapsed time since the last time we called calculateRate() and
43  * the current value is the number of counts that we acquired since the last
44  * time.
45  */
46  double calculateRate();
47 
48  /** increase the counts
49  *
50  * this function is locked by a mutex to make it reentrant
51  *
52  * @param increase the value to increase by. Default is 1.
53  */
54  void count(double increase=1.);
55 
56 private:
57  /** mutex to make function counting reentrant */
59 
60  /** the time to stop the timeinterval */
62 
63  /** a counter that will increase with each call to count*/
64  double _counts;
65 
66  /** the current rate */
67  double _rate;
68 
69  /** time constant with which the rate will decrease */
70  const double _averagetime;
71 };
72 } //indenation
73 
74 #endif // RATEMETER_H
class calculating a rate in Hz.
Definition: ratemeter.h:28
double _rate
the current rate
Definition: ratemeter.h:67
double _counts
a counter that will increase with each call to count
Definition: ratemeter.h:64
file contains global definitions for project cass
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