Statistics
| Branch: | Revision:

root / src / envir / runattributes.cc @ fbe00e73

History | View | Annotate | Download (2.79 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  RUNATTRIBUTES.CC - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Tamas Borbely
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 "simkerneldefs.h"
19
20
#include <string.h>
21
#include "cconfigoption.h"
22
#include "platmisc.h"
23
#include "envirbase.h"
24
#include "csimulation.h"
25
#include "stringutil.h"
26
#include "runattributes.h"
27
28
USING_NAMESPACE
29
30
31
#ifdef CHECK
32
#undef CHECK
33
#endif
34
#define CHECK(fprintf)    if (fprintf<0) throw cRuntimeError("Cannot write output vector file `%s'", fname.c_str())
35
36
37
void sRunData::initRun()
38
{
39
    if (!initialized)
40
    {
41
        // Collect the attributes and module parameters of the current run
42
        // from the configuration.
43
        cConfigurationEx *cfg = ev.getConfigEx();
44
        runId = cfg->getVariable(CFGVAR_RUNID);
45
46
        std::vector<const char *> keys1 = cfg->getPredefinedVariableNames();
47
        for (int i=0; i<(int)keys1.size(); i++)
48
            if (opp_strcmp(keys1[i], CFGVAR_RUNID)!=0) // skip runId
49
                attributes[keys1[i]] = cfg->getVariable(keys1[i]);
50
51
        std::vector<const char *> keys2 = cfg->getIterationVariableNames();
52
        for (int i=0; i<(int)keys2.size(); i++)
53
            attributes[keys2[i]] = cfg->getVariable(keys2[i]);
54
55
/*XXX
56
        std::vector<const char *> keys = cfg->getMatchingConfigKeys("*");
57
        for (int i=0; i<(int)keys.size(); i++)
58
        {
59
            const char *key = keys[i];
60
            config[key] = cfg->getConfigValue(key);
61
        }
62
*/
63
        // fill in moduleParams[]
64
        std::vector<const char *> params = cfg->getParameterKeyValuePairs();
65
        for (int i=0; i<(int)params.size(); i+=2)
66
            moduleParams[params[i]] = params[i+1];
67
68
        initialized = true;
69
    }
70
}
71
72
void sRunData::reset()
73
{
74
    initialized = false;
75
    attributes.clear();
76
    moduleParams.clear();
77
}
78
79
80
void sRunData::writeRunData(FILE *f, opp_string fname)
81
{
82
    CHECK(fprintf(f, "run %s\n", QUOTE(runId.c_str())));
83
    for (opp_string_map::const_iterator it = attributes.begin(); it != attributes.end(); ++it)
84
    {
85
        CHECK(fprintf(f, "attr %s %s\n", it->first.c_str(), QUOTE(it->second.c_str())));
86
    }
87
    for (opp_string_map::const_iterator it = moduleParams.begin(); it != moduleParams.end(); ++it)
88
    {
89
        CHECK(fprintf(f, "param %s %s\n", it->first.c_str(), QUOTE(it->second.c_str())));
90
    }
91
    CHECK(fprintf(f, "\n"));
92
}