Statistics
| Branch: | Revision:

root / src / envir / resultrecorder.cc @ master

History | View | Annotate | Download (3.8 KB)

1
//==========================================================================
2
//  RESULTRECORDER.CC - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 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
#include "resultrecorder.h"
19
#include "cproperty.h"
20
#include "chistogram.h"
21

    
22

    
23
cGlobalRegistrationList resultRecorders("resultRecorders");
24

    
25
CommonStringPool ResultRecorder::namesPool;
26

    
27

    
28
void ResultRecorder::init(cComponent *comp, const char *statsName, const char *recMode)
29
{
30
    component = comp;
31
    statisticName = namesPool.get(statsName);
32
    recordingMode = namesPool.get(recMode);
33
}
34

    
35
opp_string_map ResultRecorder::getStatisticAttributes()
36
{
37
    opp_string_map result;
38
    cProperty *property = getComponent()->getProperties()->get("statistic", getStatisticName());
39
    if (!property)
40
        return result;
41

    
42
    // fill result[] from the properties
43
    const std::vector<const char *>& keys = property->getKeys();
44
    for (int i = 0; i < (int)keys.size(); i++)
45
    {
46
        const char *key = keys[i];
47
        if (!strcmp(key, "record"))
48
            continue; // no need to save record= key
49
        int numValues = property->getNumValues(key);
50
        if (numValues == 0)
51
            result[key] = "";
52
        else if (numValues == 1)
53
            result[key] = property->getValue(key, 0);
54
        else {
55
            std::string buf;
56
            for (int j = 0; j < numValues; j++) {
57
                if (j > 0) buf += ",";
58
                buf += property->getValue(key, j);
59
            }
60
            result[key] = buf;
61
        }
62

    
63
        if (strcmp(key,"title")==0)
64
            tweakTitle(result[key]);
65
    }
66
    return result;
67
}
68

    
69
void ResultRecorder::tweakTitle(opp_string& title)
70
{
71
    //title = opp_string(getRecordingMode()) + " of " + title;
72
    title = title + ", " + getRecordingMode();
73
}
74

    
75
//---
76

    
77
void NumericResultRecorder::receiveSignal(ResultFilter *prev, simtime_t_cref t, long l)
78
{
79
    collect(t, l);
80
}
81

    
82
void NumericResultRecorder::receiveSignal(ResultFilter *prev, simtime_t_cref t, unsigned long l)
83
{
84
    collect(t, l);
85
}
86

    
87
void NumericResultRecorder::receiveSignal(ResultFilter *prev, simtime_t_cref t, double d)
88
{
89
    collect(t, d);
90
}
91

    
92
void NumericResultRecorder::receiveSignal(ResultFilter *prev, simtime_t_cref t, const SimTime& v)
93
{
94
    collect(t, v.dbl());
95
}
96

    
97
void NumericResultRecorder::receiveSignal(ResultFilter *prev, simtime_t_cref t, const char *s)
98
{
99
    throw cRuntimeError("%s: Cannot convert const char * to double", getClassName());
100
}
101

    
102
void NumericResultRecorder::receiveSignal(ResultFilter *prev, simtime_t_cref t, cObject *obj)
103
{
104
    // note: cITimestampedValue stuff was already dispatched to (simtime_t,double) method in base class
105
    throw cRuntimeError("%s: Cannot convert cObject * to double", getClassName());
106
}
107

    
108
//----
109

    
110
ResultRecorderDescriptor::ResultRecorderDescriptor(const char *name, ResultRecorder *(*f)())
111
  : cNoncopyableOwnedObject(name, false)
112
{
113
    creatorfunc = f;
114
}
115

    
116
ResultRecorderDescriptor *ResultRecorderDescriptor::find(const char *name)
117
{
118
    return dynamic_cast<ResultRecorderDescriptor *>(resultRecorders.getInstance()->lookup(name));
119
}
120

    
121
ResultRecorderDescriptor *ResultRecorderDescriptor::get(const char *name)
122
{
123
    ResultRecorderDescriptor *p = find(name);
124
    if (!p)
125
        throw cRuntimeError("Result recorder \"%s\" not found -- perhaps the name is wrong, "
126
                            "or the recorder was not registered with Register_ResultRecorder()", name);
127
    return p;
128
}
129

    
130