|
19 |
*/ |
19 |
*/ |
20 |
|
20 |
|
21 |
#include <fstream> |
21 |
#include <fstream> |
|
|
22 |
#include <cstdlib> |
22 |
|
23 |
|
23 |
#include "ns3/log.h" |
24 |
#include "ns3/log.h" |
24 |
#include "ns3/nstime.h" |
25 |
#include "ns3/nstime.h" |
|
54 |
} |
55 |
} |
55 |
|
56 |
|
56 |
//---------------------------------------------- |
57 |
//---------------------------------------------- |
|
|
58 |
|
59 |
inline bool isNumeric(const std::string& s) { |
60 |
char *endp; |
61 |
strtod(s.c_str(), &endp); |
62 |
return endp == s.c_str() + s.size(); |
63 |
} |
64 |
|
57 |
void |
65 |
void |
58 |
OmnetDataOutput::Output(DataCollector &dc) |
66 |
OmnetDataOutput::Output(DataCollector &dc) |
59 |
{ |
67 |
{ |
60 |
|
68 |
|
61 |
std::ofstream scalarFile; |
69 |
std::ofstream scalarFile; |
62 |
std::string fn = m_filePrefix + ".sca"; |
70 |
std::string fn = m_filePrefix +"-"+dc.GetRunLabel()+ ".sca"; |
63 |
scalarFile.open(fn.c_str(), std::ios_base::app); |
71 |
scalarFile.open(fn.c_str(), std::ios_base::out); |
64 |
|
72 |
|
65 |
scalarFile << std::endl; |
73 |
// TODO add timestamp to the runlevel |
66 |
scalarFile << "run " << dc.GetRunLabel() << std::endl; |
74 |
scalarFile << "run " << dc.GetRunLabel() << std::endl; |
67 |
scalarFile << std::endl; |
|
|
68 |
scalarFile << "attr experiment \"" << dc.GetExperimentLabel() |
75 |
scalarFile << "attr experiment \"" << dc.GetExperimentLabel() |
69 |
<< "\"" << std::endl; |
76 |
<< "\"" << std::endl; |
70 |
scalarFile << "attr strategy \"" << dc.GetStrategyLabel() |
77 |
scalarFile << "attr strategy \"" << dc.GetStrategyLabel() |
71 |
<< "\"" << std::endl; |
78 |
<< "\"" << std::endl; |
72 |
scalarFile << "attr input \"" << dc.GetInputLabel() |
79 |
scalarFile << "attr measurement \"" << dc.GetInputLabel() |
73 |
<< "\"" << std::endl; |
80 |
<< "\"" << std::endl; |
74 |
scalarFile << "attr description \"" << dc.GetDescription() |
81 |
scalarFile << "attr description \"" << dc.GetDescription() |
75 |
<< "\"" << std::endl; |
82 |
<< "\"" << std::endl; |
76 |
scalarFile << std::endl; |
|
|
77 |
|
83 |
|
78 |
for (MetadataList::iterator i = dc.MetadataBegin(); |
84 |
for (MetadataList::iterator i = dc.MetadataBegin(); |
79 |
i != dc.MetadataEnd(); i++) { |
85 |
i != dc.MetadataEnd(); i++) { |
|
83 |
} |
89 |
} |
84 |
|
90 |
|
85 |
scalarFile << std::endl; |
91 |
scalarFile << std::endl; |
86 |
|
92 |
if (isNumeric(dc.GetInputLabel())) { |
|
|
93 |
scalarFile << "scalar . measurement \"" << dc.GetInputLabel() |
94 |
<< "\"" << std::endl; |
95 |
} |
96 |
for (MetadataList::iterator i = dc.MetadataBegin(); |
97 |
i != dc.MetadataEnd(); i++) { |
98 |
std::pair<std::string, std::string> blob = (*i); |
99 |
if (isNumeric(blob.second)) { |
100 |
scalarFile << "scalar . \"" << blob.first << "\" \"" << blob.second << "\"" |
101 |
<< std::endl; |
102 |
} |
103 |
} |
87 |
OmnetOutputCallback callback(&scalarFile); |
104 |
OmnetOutputCallback callback(&scalarFile); |
88 |
|
105 |
|
89 |
for (DataCalculatorList::iterator i = dc.DataCalculatorBegin(); |
106 |
for (DataCalculatorList::iterator i = dc.DataCalculatorBegin(); |
|
97 |
// end OmnetDataOutput::Output |
114 |
// end OmnetDataOutput::Output |
98 |
} |
115 |
} |
99 |
|
116 |
|
|
|
117 |
|
100 |
OmnetDataOutput::OmnetOutputCallback::OmnetOutputCallback |
118 |
OmnetDataOutput::OmnetOutputCallback::OmnetOutputCallback |
101 |
(std::ostream *scalar) : |
119 |
(std::ostream *scalar) : |
102 |
m_scalar(scalar) |
120 |
m_scalar(scalar) |
|
104 |
} |
122 |
} |
105 |
|
123 |
|
106 |
void |
124 |
void |
107 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key, |
125 |
OmnetDataOutput::OmnetOutputCallback::OutputStatistic(std::string context, |
108 |
std::string variable, |
126 |
std::string name, |
|
|
127 |
const StatisticalSummary *statSum) |
128 |
{ |
129 |
if (context == "") |
130 |
context = "."; |
131 |
if (name == "") |
132 |
name = "\"\""; |
133 |
(*m_scalar) << "statistic " << context << " " << name << std::endl; |
134 |
if (!isNaN(statSum->getCount())) |
135 |
(*m_scalar) << "field count " << statSum->getCount() << std::endl; |
136 |
if (!isNaN(statSum->getSum())) |
137 |
(*m_scalar) << "field sum " << statSum->getSum() << std::endl; |
138 |
if (!isNaN(statSum->getMean())) |
139 |
(*m_scalar) << "field mean " << statSum->getMean() << std::endl; |
140 |
if (!isNaN(statSum->getMin())) |
141 |
(*m_scalar) << "field min " << statSum->getMin() << std::endl; |
142 |
if (!isNaN(statSum->getMax())) |
143 |
(*m_scalar) << "field max " << statSum->getMax() << std::endl; |
144 |
if (!isNaN(statSum->getSqrSum())) |
145 |
(*m_scalar) << "field sqrsum " << statSum->getSqrSum() << std::endl; |
146 |
if (!isNaN(statSum->getStddev())) |
147 |
(*m_scalar) << "field stddev " << statSum->getStddev() << std::endl; |
148 |
} |
149 |
|
150 |
void |
151 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context, |
152 |
std::string name, |
109 |
int val) |
153 |
int val) |
110 |
{ |
154 |
{ |
111 |
(*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl; |
155 |
if (context == "") |
|
|
156 |
context = "."; |
157 |
if (name == "") |
158 |
name = "\"\""; |
159 |
(*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl; |
112 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
160 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
113 |
} |
161 |
} |
|
|
162 |
|
114 |
void |
163 |
void |
115 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key, |
164 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context, |
116 |
std::string variable, |
165 |
std::string name, |
117 |
uint32_t val) |
166 |
uint32_t val) |
118 |
{ |
167 |
{ |
119 |
(*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl; |
168 |
if (context == "") |
|
|
169 |
context = "."; |
170 |
if (name == "") |
171 |
name = "\"\""; |
172 |
(*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl; |
120 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
173 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
121 |
} |
174 |
} |
|
|
175 |
|
122 |
void |
176 |
void |
123 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key, |
177 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context, |
124 |
std::string variable, |
178 |
std::string name, |
125 |
double val) |
179 |
double val) |
126 |
{ |
180 |
{ |
127 |
(*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl; |
181 |
if (context == "") |
|
|
182 |
context = "."; |
183 |
if (name == "") |
184 |
name = "\"\""; |
185 |
(*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl; |
128 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
186 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
129 |
} |
187 |
} |
|
|
188 |
|
130 |
void |
189 |
void |
131 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key, |
190 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context, |
132 |
std::string variable, |
191 |
std::string name, |
133 |
std::string val) |
192 |
std::string val) |
134 |
{ |
193 |
{ |
135 |
(*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl; |
194 |
if (context == "") |
|
|
195 |
context = "."; |
196 |
if (name == "") |
197 |
name = "\"\""; |
198 |
(*m_scalar) << "scalar " << context << " " << name << " " << val << std::endl; |
136 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
199 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
137 |
} |
200 |
} |
|
|
201 |
|
138 |
void |
202 |
void |
139 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string key, |
203 |
OmnetDataOutput::OmnetOutputCallback::OutputSingleton(std::string context, |
140 |
std::string variable, |
204 |
std::string name, |
141 |
Time val) |
205 |
Time val) |
142 |
{ |
206 |
{ |
143 |
(*m_scalar) << "scalar " << key << " " << variable << " " << val << std::endl; |
207 |
if (context == "") |
|
|
208 |
context = "."; |
209 |
if (name == "") |
210 |
name = "\"\""; |
211 |
(*m_scalar) << "scalar " << context << " " << name << " " << val.GetTimeStep() << std::endl; |
144 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
212 |
// end OmnetDataOutput::OmnetOutputCallback::OutputSingleton |
145 |
} |
213 |
} |