OMNeT++ Simulation Library  5.6.1
resultrecorders.h
1 //==========================================================================
2 // RESULTRECORDERS.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 // Author: Andras Varga
7 //
8 //==========================================================================
9 
10 /*--------------------------------------------------------------*
11  Copyright (C) 1992-2017 Andras Varga
12  Copyright (C) 2006-2017 OpenSim Ltd.
13 
14  This file is distributed WITHOUT ANY WARRANTY. See the file
15  `license' for details on this and other legal matters.
16 *--------------------------------------------------------------*/
17 
18 #ifndef __OMNETPP_RESULTRECORDERS_H
19 #define __OMNETPP_RESULTRECORDERS_H
20 
21 #include <cmath> // INFINITY, NAN
22 #include "omnetpp/cresultrecorder.h"
23 
24 namespace omnetpp {
25 
26 class cStatistic;
27 
31 class SIM_API VectorRecorder : public cNumericResultRecorder
32 {
33  protected:
34  void *handle; // identifies output vector for the output vector manager
35  simtime_t lastTime; // to ensure increasing timestamp order
36  double lastValue; // for getCurrentValue()
37  protected:
38  virtual void subscribedTo(cResultFilter *prev) override;
39  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
40  public:
41  VectorRecorder() {handle = nullptr; lastTime = 0; lastValue = NAN;}
42  virtual ~VectorRecorder();
43  virtual simtime_t getLastWriteTime() const {return lastTime;}
44  virtual double getLastValue() const {return lastValue;}
45  virtual std::string str() const override;
46 };
47 
51 class SIM_API TotalCountRecorder : public cResultRecorder
52 {
53  protected:
54  long count;
55  protected:
56  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {count++;}
57  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, long l, cObject *details) override {count++;}
58  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, unsigned long l, cObject *details) override {count++;}
59  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {if (!std::isnan(d)) count++;}
60  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {count++;}
61  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {if (s) count++;}
62  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {if (obj) count++;}
63  virtual void finish(cResultFilter *prev) override;
64  public:
65  TotalCountRecorder() {count = 0;}
66  long getCount() const {return count;}
67  virtual std::string str() const override;
68 };
69 
74 class SIM_API CountRecorder : public TotalCountRecorder
75 {
76  protected:
77  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {if (!std::isnan(d)) count++;}
78  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {if (s) count++;}
79  virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {if (obj) count++;}
80  public:
81  CountRecorder() {}
82 };
83 
88 {
89  protected:
90  double lastValue;
91  protected:
92  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
93  virtual void finish(cResultFilter *prev) override;
94  public:
95  LastValueRecorder() {lastValue = NAN;}
96  double getLastValue() const {return lastValue;}
97  virtual std::string str() const override;
98 };
99 
105 {
106  protected:
107  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
108  public:
109  ErrorNanRecorder() {}
110 };
111 
116 class SIM_API SumRecorder : public cNumericResultRecorder
117 {
118  protected:
119  double sum;
120  protected:
121  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
122  virtual void finish(cResultFilter *prev) override;
123  public:
124  SumRecorder() {sum = 0;}
125  double getSum() const {return sum;}
126  virtual std::string str() const override;
127 };
128 
134 class SIM_API MeanRecorder : public cNumericResultRecorder
135 {
136  protected:
137  bool timeWeighted = false;
138  long count = 0;
139  double lastValue = NAN;
140  simtime_t lastTime = SIMTIME_ZERO;
141  double weightedSum = 0;
142  simtime_t totalTime = SIMTIME_ZERO;
143  protected:
144  virtual void init(cComponent *component, const char *statsName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs) override;
145  virtual void finish(cResultFilter *prev) override;
146  public:
147  MeanRecorder() {}
148  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
149  double getMean() const;
150  virtual std::string str() const override;
151 };
152 
157 class SIM_API MinRecorder : public cNumericResultRecorder
158 {
159  protected:
160  double min;
161  protected:
162  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
163  virtual void finish(cResultFilter *prev) override;
164  public:
165  MinRecorder() {min = INFINITY;}
166  double getMin() const {return min;}
167  virtual std::string str() const override;
168 };
169 
174 class SIM_API MaxRecorder : public cNumericResultRecorder
175 {
176  protected:
177  double max;
178  protected:
179  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
180  virtual void finish(cResultFilter *prev) override;
181  public:
182  MaxRecorder() {max = -INFINITY;}
183  double getMax() const {return max;}
184  virtual std::string str() const override;
185 };
186 
192 {
193  protected:
194  long count;
195  double sum;
196  protected:
197  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
198  virtual void finish(cResultFilter *prev) override;
199  public:
200  AverageRecorder() {count = 0; sum = 0;}
201  double getAverage() const {return sum/count;}
202  virtual std::string str() const override;
203 };
204 
210 {
211  protected:
212  double lastValue = NAN;
213  simtime_t lastTime = SIMTIME_ZERO;
214  double weightedSum = 0;
215  simtime_t totalTime = SIMTIME_ZERO;
216  protected:
217  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
218  virtual void finish(cResultFilter *prev) override;
219  public:
221  double getTimeAverage() const;
222  virtual std::string str() const override;
223 };
224 
231 {
232  protected:
233  cStatistic *statistic = nullptr;
234  double lastValue = NAN;
235  simtime_t lastTime = SIMTIME_ZERO;
236  protected:
237  virtual void collect(simtime_t_cref t, double value, cObject *details) override;
238  virtual void finish(cResultFilter *prev) override;
239  virtual void forEachChild(cVisitor *v) override;
240  public:
243  virtual void setStatistic(cStatistic* stat);
244  virtual cStatistic *getStatistic() const {return statistic;}
245  virtual std::string str() const override;
246 };
247 
248 class SIM_API StatsRecorder : public StatisticsRecorder
249 {
250  public:
251  virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs) override;
252 };
253 
254 class SIM_API HistogramRecorder : public StatisticsRecorder
255 {
256  public:
257  virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs) override;
258 };
259 
260 class SIM_API TimeWeightedHistogramRecorder : public StatisticsRecorder
261 {
262  public:
263  virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs) override;
264 };
265 
266 class SIM_API PSquareRecorder : public StatisticsRecorder
267 {
268  public:
269  virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs) override;
270 };
271 
272 class SIM_API KSplitRecorder : public StatisticsRecorder
273 {
274  public:
275  virtual void init(cComponent *component, const char *statisticName, const char *recordingMode, cProperty *attrsProperty, opp_string_map *manualAttrs) override;
276 };
277 
278 } // namespace omnetpp
279 
280 #endif
Common base for module and channel classes.
Definition: ccomponent.h:48
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
Abstract base class for result recorders.
Definition: cresultrecorder.h:69
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
Listener for recording the count of signal values, including NaN and nullptr.
Definition: resultrecorders.h:51
Abstract base class for numeric result recorders.
Definition: cresultrecorder.h:111
Listener for recording the arithmetic mean of signal values. NaN values in the input are ignored...
Definition: resultrecorders.h:191
Listener for recording the count of signal values. Signal values do not need to be numeric to be coun...
Definition: resultrecorders.h:74
Listener for recording the (time-weighted or unweighted) mean of signal values. NaN values in the inp...
Definition: resultrecorders.h:134
#define SIMTIME_ZERO
Zero simulation time.
Definition: simtime_t.h:73
Stores a (NED) property with its (possibly compound) value.
Definition: cproperty.h:38
Base class for result filters.
Definition: cresultfilter.h:72
Listener for recording a signal to an output vector.
Definition: resultrecorders.h:31
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition: opp_string.h:200
Recorder that raises a runtime error if it sees a NaN in the input (and never records anything)...
Definition: resultrecorders.h:104
Listener for recording signal values via a cStatistic. NaN values in the input are ignored...
Definition: resultrecorders.h:230
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition: cvisitor.h:56
Definition: cabstracthistogram.h:21
Listener for recording the time average of signal values. NaN values in the input denote intervals to...
Definition: resultrecorders.h:209
Listener for recording the sum of signal values. NaN values in the input are ignored.
Definition: resultrecorders.h:116
Listener for recording the maximum of signal values. NaN values in the input are ignored.
Definition: resultrecorders.h:174
Listener for recording the last non-NaN signal value.
Definition: resultrecorders.h:87
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition: cstatistic.h:34
Listener for recording the minimum of signal values. NaN values in the input are ignored.
Definition: resultrecorders.h:157