resultrecorders.h Source File¶

API: resultrecorders.h Source File
API
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#include "omnetpp/statsum_t.h"
22
23namespace omnetpp {
24
25class cStatistic;
26
31
35class SIM_API VectorRecorder : public cNumericResultRecorder
36{
37 protected:
38 void *handle; // identifies output vector for the output vector manager
39 simtime_t lastTime; // to ensure increasing timestamp order
40 double lastValue; // for getCurrentValue()
41 protected:
42 virtual void subscribedTo(cResultFilter *prev) override;
43 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
44 public:
45 VectorRecorder() {handle = nullptr; lastTime = 0; lastValue = NAN;}
46 virtual ~VectorRecorder();
47 virtual simtime_t getLastWriteTime() const {return lastTime;}
48 virtual double getLastValue() const {return lastValue;}
49 virtual std::string str() const override;
50};
51
55class SIM_API TotalCountRecorder : public cResultRecorder
56{
57 protected:
58 long count;
59 protected:
60 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, bool b, cObject *details) override {count++;}
61 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, intval_t l, cObject *details) override {count++;}
62 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, uintval_t l, cObject *details) override {count++;}
63 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {if (!std::isnan(d)) count++;}
64 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const SimTime& v, cObject *details) override {count++;}
65 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {if (s) count++;}
66 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {if (obj) count++;}
67 virtual void finish(cResultFilter *prev) override;
68 public:
69 TotalCountRecorder() {count = 0;}
70 long getCount() const {return count;}
71 virtual std::string str() const override;
72};
73
78class SIM_API CountRecorder : public TotalCountRecorder
79{
80 protected:
81 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, double d, cObject *details) override {if (!std::isnan(d)) count++;}
82 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, const char *s, cObject *details) override {if (s) count++;}
83 virtual void receiveSignal(cResultFilter *prev, simtime_t_cref t, cObject *obj, cObject *details) override {if (obj) count++;}
84 public:
85 CountRecorder() {}
86};
87
91class SIM_API LastValueRecorder : public cNumericResultRecorder
92{
93 protected:
94 double lastValue;
95 protected:
96 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
97 virtual void finish(cResultFilter *prev) override;
98 public:
99 LastValueRecorder() {lastValue = NAN;}
100 double getLastValue() const {return lastValue;}
101 virtual std::string str() const override;
102};
103
108class SIM_API ErrorNanRecorder : public cNumericResultRecorder
109{
110 protected:
111 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
112 public:
113 ErrorNanRecorder() {}
114};
115
120class SIM_API SumRecorder : public cNumericResultRecorder
121{
122 protected:
123 statsum_t sum;
124 protected:
125 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
126 virtual void finish(cResultFilter *prev) override;
127 public:
128 SumRecorder() {sum = 0;}
129 double getSum() const {return sum;}
130 virtual std::string str() const override;
131};
132
138class SIM_API MeanRecorder : public cNumericResultRecorder
139{
140 protected:
141 bool timeWeighted = false;
142 long count = 0;
143 double lastValue = NAN;
144 simtime_t lastTime = SIMTIME_ZERO;
145 statsum_t weightedSum = 0;
146 simtime_t totalTime = SIMTIME_ZERO;
147 protected:
148 virtual void init(Context *ctx) override;
149 virtual void finish(cResultFilter *prev) override;
150 public:
151 MeanRecorder() {}
152 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
153 double getMean() const;
154 virtual std::string str() const override;
155};
156
161class SIM_API MinRecorder : public cNumericResultRecorder
162{
163 protected:
164 double min;
165 protected:
166 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
167 virtual void finish(cResultFilter *prev) override;
168 public:
169 MinRecorder() {min = INFINITY;}
170 double getMin() const {return min;}
171 virtual std::string str() const override;
172};
173
178class SIM_API MaxRecorder : public cNumericResultRecorder
179{
180 protected:
181 double max;
182 protected:
183 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
184 virtual void finish(cResultFilter *prev) override;
185 public:
186 MaxRecorder() {max = -INFINITY;}
187 double getMax() const {return max;}
188 virtual std::string str() const override;
189};
190
195class SIM_API AverageRecorder : public cNumericResultRecorder
196{
197 protected:
198 long count;
199 statsum_t sum;
200 protected:
201 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
202 virtual void finish(cResultFilter *prev) override;
203 public:
204 AverageRecorder() {count = 0; sum = 0;}
205 double getAverage() const {return sum/count;}
206 virtual std::string str() const override;
207};
208
220class SIM_API TimeAverageRecorder : public cNumericResultRecorder
221{
222 protected:
223 double lastValue = NAN;
224 simtime_t lastTime = SIMTIME_ZERO;
225 statsum_t weightedSum = 0;
226 simtime_t totalTime = SIMTIME_ZERO;
227 protected:
228 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
229 virtual void finish(cResultFilter *prev) override;
230 public:
231 TimeAverageRecorder() {}
232 double getTimeAverage() const;
233 virtual std::string str() const override;
234};
235
251class SIM_API RateAverageRecorder : public cNumericResultRecorder
252{
253 protected:
254 simtime_t lastTime = SIMTIME_ZERO;
255 statsum_t weightedSum = 0;
256 simtime_t totalTime = SIMTIME_ZERO;
257 protected:
258 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
259 virtual void finish(cResultFilter *prev) override;
260 public:
261 RateAverageRecorder() {}
262 double getRateAverage() const;
263 virtual std::string str() const override;
264};
265
271class SIM_API StatisticsRecorder : public cNumericResultRecorder
272{
273 protected:
274 cStatistic *statistic = nullptr;
275 double lastValue = NAN;
276 simtime_t lastTime = SIMTIME_ZERO;
277 protected:
278 virtual void collect(simtime_t_cref t, double value, cObject *details) override;
279 virtual void finish(cResultFilter *prev) override;
280 virtual void forEachChild(cVisitor *v) override;
281 public:
282 StatisticsRecorder() {}
284 virtual void setStatistic(cStatistic* stat);
285 virtual cStatistic *getStatistic() const {return statistic;}
286 virtual std::string str() const override;
287};
288
289class SIM_API StatsRecorder : public StatisticsRecorder
290{
291 public:
292 virtual void init(Context *ctx) override;
293};
294
295class SIM_API HistogramRecorder : public StatisticsRecorder
296{
297 public:
298 virtual void init(Context *ctx) override;
299};
300
301class SIM_API TimeWeightedHistogramRecorder : public StatisticsRecorder
302{
303 public:
304 virtual void init(Context *ctx) override;
305};
306
307class SIM_API PSquareRecorder : public StatisticsRecorder
308{
309 public:
310 virtual void init(Context *ctx) override;
311};
312
313class SIM_API KSplitRecorder : public StatisticsRecorder
314{
315 public:
316 virtual void init(Context *ctx) override;
317};
318
320
321} // namespace omnetpp
322
323#endif
virtual std::string str() const override
virtual std::string str() const override
virtual std::string str() const override
virtual std::string str() const override
virtual std::string str() const override
virtual std::string str() const override
int64_t-based, base-10 fixed-point simulation time.
Definition simtime.h:67
Listener for recording signal values via a cStatistic. NaN values in the input are ignored,...
Definition resultrecorders.h:272
virtual void forEachChild(cVisitor *v) override
virtual std::string str() const override
virtual std::string str() const override
virtual std::string str() const override
virtual std::string str() const override
virtual std::string str() const override
Abstract base class for numeric result recorders.
Definition cresultrecorder.h:129
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition cobject.h:93
Base class for result filters.
Definition cresultfilter.h:73
cStatistic is an abstract class for computing statistical properties of a random variable.
Definition cstatistic.h:35
Enables traversing the tree of (cObject-rooted) simulation objects.
Definition cvisitor.h:57
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
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
SimTime simtime_t
Represents simulation time.
Definition simtime_t.h:40
const simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition simtime_t.h:48
#define SIMTIME_ZERO
Zero simulation time.
Definition simtime_t.h:70
Definition cresultrecorder.h:82