A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
omnet-data-output.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 Drexel University
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Joe Kopena (tjkopena@cs.drexel.edu)
19
*/
20
21
#include <fstream>
22
#include <cstdlib>
23
24
#include "ns3/log.h"
25
#include "ns3/nstime.h"
26
27
#include "
data-collector.h
"
28
#include "
data-calculator.h
"
29
#include "
omnet-data-output.h
"
30
31
using namespace
ns3;
32
33
NS_LOG_COMPONENT_DEFINE
(
"OmnetDataOutput"
);
34
35
36
//--------------------------------------------------------------
37
//----------------------------------------------
38
OmnetDataOutput::OmnetDataOutput
()
39
{
40
m_filePrefix
=
"data"
;
41
42
NS_LOG_FUNCTION_NOARGS
();
43
}
44
OmnetDataOutput::~OmnetDataOutput
()
45
{
46
NS_LOG_FUNCTION_NOARGS
();
47
}
48
void
49
OmnetDataOutput::DoDispose
()
50
{
51
NS_LOG_FUNCTION_NOARGS
();
52
53
DataOutputInterface::DoDispose
();
54
// end OmnetDataOutput::DoDispose
55
}
56
57
//----------------------------------------------
58
59
inline
bool
isNumeric
(
const
std::string& s) {
60
bool
decimalPtSeen =
false
;
61
bool
exponentSeen =
false
;
62
char
last =
'\0'
;
63
64
for
(std::string::const_iterator it = s.begin (); it != s.end (); it++)
65
{
66
if
((*it ==
'.'
) && (decimalPtSeen))
67
return
false
;
68
else
if
(*it ==
'.'
)
69
decimalPtSeen =
true
;
70
else
if
((*it ==
'e'
) && exponentSeen)
71
return
false
;
72
else
if
(*it ==
'e'
)
73
{
74
exponentSeen =
true
;
75
decimalPtSeen =
false
;
76
}
77
else
if
(*it ==
'-'
&& it != s.begin () && last !=
'e'
)
78
return
false
;
79
80
last = *it;
81
}
82
return
true
;
83
}
84
85
void
86
OmnetDataOutput::Output
(
DataCollector
&dc)
87
{
88
89
std::ofstream scalarFile;
90
std::string fn =
m_filePrefix
+
"-"
+dc.
GetRunLabel
()+
".sca"
;
91
scalarFile.open (fn.c_str (), std::ios_base::out);
92
93
// TODO add timestamp to the runlevel
94
scalarFile <<
"run "
<< dc.
GetRunLabel
() << std::endl;
95
scalarFile <<
"attr experiment \""
<< dc.
GetExperimentLabel
()
96
<<
"\""
<< std::endl;
97
scalarFile <<
"attr strategy \""
<< dc.
GetStrategyLabel
()
98
<<
"\""
<< std::endl;
99
scalarFile <<
"attr measurement \""
<< dc.
GetInputLabel
()
100
<<
"\""
<< std::endl;
101
scalarFile <<
"attr description \""
<< dc.
GetDescription
()
102
<<
"\""
<< std::endl;
103
104
for
(MetadataList::iterator i = dc.
MetadataBegin
();
105
i != dc.
MetadataEnd
(); i++) {
106
std::pair<std::string, std::string> blob = (*i);
107
scalarFile <<
"attr \""
<< blob.first <<
"\" \""
<< blob.second <<
"\""
108
<< std::endl;
109
}
110
111
scalarFile << std::endl;
112
if
(
isNumeric
(dc.
GetInputLabel
())) {
113
scalarFile <<
"scalar . measurement \""
<< dc.
GetInputLabel
()
114
<<
"\""
<< std::endl;
115
}
116
for
(MetadataList::iterator i = dc.
MetadataBegin
();
117
i != dc.
MetadataEnd
(); i++) {
118
std::pair<std::string, std::string> blob = (*i);
119
if
(
isNumeric
(blob.second)) {
120
scalarFile <<
"scalar . \""
<< blob.first <<
"\" \""
<< blob.second <<
"\""
121
<< std::endl;
122
}
123
}
124
OmnetOutputCallback
callback (&scalarFile);
125
126
for
(DataCalculatorList::iterator i = dc.
DataCalculatorBegin
();
127
i != dc.
DataCalculatorEnd
(); i++) {
128
(*i)->Output (callback);
129
}
130
131
scalarFile << std::endl << std::endl;
132
scalarFile.close ();
133
134
// end OmnetDataOutput::Output
135
}
136
137
138
OmnetDataOutput::OmnetOutputCallback::OmnetOutputCallback
139
(std::ostream *scalar) :
140
m_scalar (scalar)
141
{
142
}
143
144
void
145
OmnetDataOutput::OmnetOutputCallback::OutputStatistic
(std::string context,
146
std::string name,
147
const
StatisticalSummary
*statSum)
148
{
149
if
(context ==
""
)
150
context =
"."
;
151
if
(name ==
""
)
152
name =
"\"\""
;
153
(*m_scalar) <<
"statistic "
<< context <<
" "
<< name << std::endl;
154
if
(!
isNaN
(statSum->
getCount
()))
155
(*m_scalar) <<
"field count "
<< statSum->
getCount
() << std::endl;
156
if
(!
isNaN
(statSum->
getSum
()))
157
(*m_scalar) <<
"field sum "
<< statSum->
getSum
() << std::endl;
158
if
(!
isNaN
(statSum->
getMean
()))
159
(*m_scalar) <<
"field mean "
<< statSum->
getMean
() << std::endl;
160
if
(!
isNaN
(statSum->
getMin
()))
161
(*m_scalar) <<
"field min "
<< statSum->
getMin
() << std::endl;
162
if
(!
isNaN
(statSum->
getMax
()))
163
(*m_scalar) <<
"field max "
<< statSum->
getMax
() << std::endl;
164
if
(!
isNaN
(statSum->
getSqrSum
()))
165
(*m_scalar) <<
"field sqrsum "
<< statSum->
getSqrSum
() << std::endl;
166
if
(!
isNaN
(statSum->
getStddev
()))
167
(*m_scalar) <<
"field stddev "
<< statSum->
getStddev
() << std::endl;
168
}
169
170
void
171
OmnetDataOutput::OmnetOutputCallback::OutputSingleton
(std::string context,
172
std::string name,
173
int
val)
174
{
175
if
(context ==
""
)
176
context =
"."
;
177
if
(name ==
""
)
178
name =
"\"\""
;
179
(*m_scalar) <<
"scalar "
<< context <<
" "
<< name <<
" "
<< val << std::endl;
180
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
181
}
182
183
void
184
OmnetDataOutput::OmnetOutputCallback::OutputSingleton
(std::string context,
185
std::string name,
186
uint32_t val)
187
{
188
if
(context ==
""
)
189
context =
"."
;
190
if
(name ==
""
)
191
name =
"\"\""
;
192
(*m_scalar) <<
"scalar "
<< context <<
" "
<< name <<
" "
<< val << std::endl;
193
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
194
}
195
196
void
197
OmnetDataOutput::OmnetOutputCallback::OutputSingleton
(std::string context,
198
std::string name,
199
double
val)
200
{
201
if
(context ==
""
)
202
context =
"."
;
203
if
(name ==
""
)
204
name =
"\"\""
;
205
(*m_scalar) <<
"scalar "
<< context <<
" "
<< name <<
" "
<< val << std::endl;
206
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
207
}
208
209
void
210
OmnetDataOutput::OmnetOutputCallback::OutputSingleton
(std::string context,
211
std::string name,
212
std::string val)
213
{
214
if
(context ==
""
)
215
context =
"."
;
216
if
(name ==
""
)
217
name =
"\"\""
;
218
(*m_scalar) <<
"scalar "
<< context <<
" "
<< name <<
" "
<< val << std::endl;
219
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
220
}
221
222
void
223
OmnetDataOutput::OmnetOutputCallback::OutputSingleton
(std::string context,
224
std::string name,
225
Time
val)
226
{
227
if
(context ==
""
)
228
context =
"."
;
229
if
(name ==
""
)
230
name =
"\"\""
;
231
(*m_scalar) <<
"scalar "
<< context <<
" "
<< name <<
" "
<< val.
GetTimeStep
() << std::endl;
232
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton
233
}
src
stats
model
omnet-data-output.cc
Generated on Tue May 14 2013 11:08:33 for ns-3 by
1.8.1.2