OMNeT++ Simulation Library  6.0.3
resultrecorders.h
1 //==========================================================================
2 // RESULTRECORDERS.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_RESULTRECORDERS_H
17 #define __OMNETPP_RESULTRECORDERS_H
18 
19 #include <cmath> // INFINITY, NAN
20 #include "omnetpp/cresultrecorder.h"
21 
22 namespace omnetpp {
23 
24 class cStatistic;
25 
34 class SIM_API VectorRecorder : public cNumericResultRecorder
35 {
36  protected:
37  void *handle; // identifies output vector for the output vector manager
38  simtime_t lastTime; // to ensure increasing timestamp order
39  double lastValue; // for getCurrentValue()
40  protected:
41  virtual void subscribedTo(cResultFilter *prev) override;
42  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
43  public:
44  VectorRecorder() {handle = nullptr; lastTime = 0; lastValue = NAN;}
45  virtual ~VectorRecorder();
46  virtual simtime_t getLastWriteTime() const {return lastTime;}
47  virtual double getLastValue() const {return lastValue;}
48  virtual std::string str() const override;
49 };
50 
54 class SIM_API TotalCountRecorder : public cResultRecorder
55 {
56  protected:
57  long count;
58  protected:
59  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {count++;}
60  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override {count++;}
61  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override {count++;}
62  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {if (!std::isnan(d)) count++;}
63  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {count++;}
64  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {if (s) count++;}
65  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {if (obj) count++;}
66  virtual void finish(cResultFilter *prev) override;
67  public:
68  TotalCountRecorder() {count = 0;}
69  long getCount() const {return count;}
70  virtual std::string str() const override;
71 };
72 
77 class SIM_API CountRecorder : public TotalCountRecorder
78 {
79  protected:
80  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {if (!std::isnan(d)) count++;}
81  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {if (s) count++;}
82  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {if (obj) count++;}
83  public:
84  CountRecorder() {}
85 };
86 
91 {
92  protected:
93  double lastValue;
94  protected:
95  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
96  virtual void finish(cResultFilter *prev) override;
97  public:
98  LastValueRecorder() {lastValue = NAN;}
99  double getLastValue() const {return lastValue;}
100  virtual std::string str() const override;
101 };
102 
108 {
109  protected:
110  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
111  public:
112  ErrorNanRecorder() {}
113 };
114 
119 class SIM_API SumRecorder : public cNumericResultRecorder
120 {
121  protected:
122  double sum;
123  protected:
124  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
125  virtual void finish(cResultFilter *prev) override;
126  public:
127  SumRecorder() {sum = 0;}
128  double getSum() const {return sum;}
129  virtual std::string str() const override;
130 };
131 
137 class SIM_API MeanRecorder : public cNumericResultRecorder
138 {
139  protected:
140  bool timeWeighted = false;
141  long count = 0;
142  double lastValue = NAN;
143  simtime_t lastTime = SIMTIME_ZERO;
144  double weightedSum = 0;
145  simtime_t totalTime = SIMTIME_ZERO;
146  protected:
147  virtual void init(Context *ctx) override;
148  virtual void finish(cResultFilter *prev) override;
149  public:
150  MeanRecorder() {}
151  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
152  double getMean() const;
153  virtual std::string str() const override;
154 };
155 
160 class SIM_API MinRecorder : public cNumericResultRecorder
161 {
162  protected:
163  double min;
164  protected:
165  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
166  virtual void finish(cResultFilter *prev) override;
167  public:
168  MinRecorder() {min = INFINITY;}
169  double getMin() const {return min;}
170  virtual std::string str() const override;
171 };
172 
177 class SIM_API MaxRecorder : public cNumericResultRecorder
178 {
179  protected:
180  double max;
181  protected:
182  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
183  virtual void finish(cResultFilter *prev) override;
184  public:
185  MaxRecorder() {max = -INFINITY;}
186  double getMax() const {return max;}
187  virtual std::string str() const override;
188 };
189 
195 {
196  protected:
197  long count;
198  double sum;
199  protected:
200  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
201  virtual void finish(cResultFilter *prev) override;
202  public:
203  AverageRecorder() {count = 0; sum = 0;}
204  double getAverage() const {return sum/count;}
205  virtual std::string str() const override;
206 };
207 
213 {
214  protected:
215  double lastValue = NAN;
216  simtime_t lastTime = SIMTIME_ZERO;
217  double weightedSum = 0;
218  simtime_t totalTime = SIMTIME_ZERO;
219  protected:
220  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
221  virtual void finish(cResultFilter *prev) override;
222  public:
224  double getTimeAverage() const;
225  virtual std::string str() const override;
226 };
227 
234 {
235  protected:
236  cStatistic *statistic = nullptr;
237  double lastValue = NAN;
238  simtime_t lastTime = SIMTIME_ZERO;
239  protected:
240  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
241  virtual void finish(cResultFilter *prev) override;
242  virtual void forEachChild(cVisitor *v) override;
243  public:
244  StatisticsRecorder() {}
246  virtual void setStatistic(cStatistic* stat);
247  virtual cStatistic *getStatistic() const {return statistic;}
248  virtual std::string str() const override;
249 };
250 
251 class SIM_API StatsRecorder : public StatisticsRecorder
252 {
253  public:
254  virtual void init(Context *ctx) override;
255 };
256 
257 class SIM_API HistogramRecorder : public StatisticsRecorder
258 {
259  public:
260  virtual void init(Context *ctx) override;
261 };
262 
263 class SIM_API TimeWeightedHistogramRecorder : public StatisticsRecorder
264 {
265  public:
266  virtual void init(Context *ctx) override;
267 };
268 
269 class SIM_API PSquareRecorder : public StatisticsRecorder
270 {
271  public:
272  virtual void init(Context *ctx) override;
273 };
274 
275 class SIM_API KSplitRecorder : public StatisticsRecorder
276 {
277  public:
278  virtual void init(Context *ctx) override;
279 };
280 
283 } // namespace omnetpp
284 
285 #endif
omnetpp::simtime_t_cref
const typedef simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition: simtime_t.h:48
omnetpp::MaxRecorder
Listener for recording the maximum of signal values. NaN values in the input are ignored.
Definition: resultrecorders.h:177
omnetpp::AverageRecorder
Listener for recording the arithmetic mean of signal values. NaN values in the input are ignored.
Definition: resultrecorders.h:194
omnetpp::VectorRecorder
Listener for recording a signal to an output vector.
Definition: resultrecorders.h:34
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::StatisticsRecorder
Listener for recording signal values via a cStatistic. NaN values in the input are ignored,...
Definition: resultrecorders.h:233
omnetpp::cResultRecorder::Context
Definition: cresultrecorder.h:82
omnetpp::cVisitor
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
omnetpp::cNumericResultRecorder
Abstract base class for numeric result recorders.
Definition: cresultrecorder.h:128
omnetpp::LastValueRecorder
Listener for recording the last non-NaN signal value.
Definition: resultrecorders.h:90
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::SumRecorder
Listener for recording the sum of signal values. NaN values in the input are ignored.
Definition: resultrecorders.h:119
omnetpp::uintval_t
uint64_t uintval_t
Unsigned integer type which is guaranteed to be at least 64 bits wide. It is used throughout the libr...
Definition: simkerneldefs.h:109
omnetpp::ErrorNanRecorder
Recorder that raises a runtime error if it sees a NaN in the input (and never records anything).
Definition: resultrecorders.h:107
omnetpp::cResultRecorder
Abstract base class for result recorders.
Definition: cresultrecorder.h:70
omnetpp::MeanRecorder
Listener for recording the (time-weighted or unweighted) mean of signal values. NaN values in the inp...
Definition: resultrecorders.h:137
omnetpp::TimeAverageRecorder
Listener for recording the time average of signal values. NaN values in the input denote intervals to...
Definition: resultrecorders.h:212
SIMTIME_ZERO
#define SIMTIME_ZERO
Zero simulation time.
Definition: simtime_t.h:70
omnetpp::TotalCountRecorder
Listener for recording the count of signal values, including NaN and nullptr.
Definition: resultrecorders.h:54
omnetpp::intval_t
int64_t intval_t
Signed integer type which is guaranteed to be at least 64 bits wide. It is used throughout the librar...
Definition: simkerneldefs.h:101
omnetpp::cStatistic
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
omnetpp::cResultFilter
Base class for result filters.
Definition: cresultfilter.h:72
omnetpp::CountRecorder
Listener for recording the count of signal values. Signal values do not need to be numeric to be coun...
Definition: resultrecorders.h:77
omnetpp::MinRecorder
Listener for recording the minimum of signal values. NaN values in the input are ignored.
Definition: resultrecorders.h:160