Helper class used to put data values into a file. More...
#include "file-helper.h"
Public Member Functions | |
FileHelper () | |
Constructs a file helper that will create a space separated file named "file-helper.txt" unless it is later configured otherwise. More... | |
FileHelper (const std::string &outputFileNameWithoutExtension, enum FileAggregator::FileType fileType=FileAggregator::SPACE_SEPARATED) | |
virtual | ~FileHelper () |
void | AddAggregator (const std::string &aggregatorName, const std::string &outputFileName, bool onlyOneAggregator) |
Adds an aggregator to be used to write values to files. More... | |
void | AddTimeSeriesAdaptor (const std::string &adaptorName) |
Adds a time series adaptor to be used to write the file. More... | |
void | ConfigureFile (const std::string &outputFileNameWithoutExtension, enum FileAggregator::FileType fileType=FileAggregator::SPACE_SEPARATED) |
Ptr< FileAggregator > | GetAggregatorMultiple (const std::string &aggregatorName, const std::string &outputFileName) |
Gets one of the multiple aggregators from the map. More... | |
Ptr< FileAggregator > | GetAggregatorSingle () |
Gets the single aggregator that is always constructed. More... | |
Ptr< Probe > | GetProbe (std::string probeName) const |
Gets the specified probe. More... | |
void | Set10dFormat (const std::string &format) |
Sets the 10D format string for the C-style sprintf() function. More... | |
void | Set1dFormat (const std::string &format) |
Sets the 1D format string for the C-style sprintf() function. More... | |
void | Set2dFormat (const std::string &format) |
Sets the 2D format string for the C-style sprintf() function. More... | |
void | Set3dFormat (const std::string &format) |
Sets the 3D format string for the C-style sprintf() function. More... | |
void | Set4dFormat (const std::string &format) |
Sets the 4D format string for the C-style sprintf() function. More... | |
void | Set5dFormat (const std::string &format) |
Sets the 5D format string for the C-style sprintf() function. More... | |
void | Set6dFormat (const std::string &format) |
Sets the 6D format string for the C-style sprintf() function. More... | |
void | Set7dFormat (const std::string &format) |
Sets the 7D format string for the C-style sprintf() function. More... | |
void | Set8dFormat (const std::string &format) |
Sets the 8D format string for the C-style sprintf() function. More... | |
void | Set9dFormat (const std::string &format) |
Sets the 9D format string for the C-style sprintf() function. More... | |
void | SetHeading (const std::string &heading) |
Sets the heading string that will be printed on the first line of the file. More... | |
void | WriteProbe (const std::string &typeId, const std::string &path, const std::string &probeTraceSource) |
Private Member Functions | |
void | AddProbe (const std::string &typeId, const std::string &probeName, const std::string &path) |
Adds a probe to be used to write values to files. More... | |
void | ConnectProbeToAggregator (const std::string &typeId, const std::string &matchIdentifier, const std::string &path, const std::string &probeTraceSource, const std::string &outputFileNameWithoutExtension, bool onlyOneAggregator) |
Connects the probe to the aggregator. More... | |
Private Attributes | |
std::string | m_10dFormat |
Format string for 10D format C-style sprintf() function. More... | |
std::string | m_1dFormat |
Format string for 1D format C-style sprintf() function. More... | |
std::string | m_2dFormat |
Format string for 2D format C-style sprintf() function. More... | |
std::string | m_3dFormat |
Format string for 3D format C-style sprintf() function. More... | |
std::string | m_4dFormat |
Format string for 4D format C-style sprintf() function. More... | |
std::string | m_5dFormat |
Format string for 5D format C-style sprintf() function. More... | |
std::string | m_6dFormat |
Format string for 6D format C-style sprintf() function. More... | |
std::string | m_7dFormat |
Format string for 7D format C-style sprintf() function. More... | |
std::string | m_8dFormat |
Format string for 8D format C-style sprintf() function. More... | |
std::string | m_9dFormat |
Format string for 9D format C-style sprintf() function. More... | |
Ptr< FileAggregator > | m_aggregator |
The single aggregator that is always created in the constructor. More... | |
std::map< std::string, Ptr< FileAggregator > > | m_aggregatorMap |
Maps aggregator names to aggregators when multiple aggregators are needed. More... | |
ObjectFactory | m_factory |
Used to create the probes and collectors as they are added. More... | |
uint32_t | m_fileProbeCount |
Number of file probes that have been created. More... | |
enum FileAggregator::FileType | m_fileType |
Determines the kind of file written by the aggregator. More... | |
bool | m_hasHeadingBeenSet |
Indicates if the heading line for the file has been set. More... | |
std::string | m_heading |
Heading line for the outputfile. More... | |
std::string | m_outputFileNameWithoutExtension |
The name of the output file to created without its extension. More... | |
std::map< std::string, std::pair< Ptr< Probe >, std::string > > | m_probeMap |
Maps probe names to probes. More... | |
std::map< std::string, Ptr< TimeSeriesAdaptor > > | m_timeSeriesAdaptorMap |
Maps time series adaptor names to time series adaptors. More... | |
Helper class used to put data values into a file.
Definition at line 38 of file file-helper.h.
ns3::FileHelper::FileHelper | ( | ) |
Constructs a file helper that will create a space separated file named "file-helper.txt" unless it is later configured otherwise.
Definition at line 35 of file file-helper.cc.
References NS_LOG_FUNCTION.
ns3::FileHelper::FileHelper | ( | const std::string & | outputFileNameWithoutExtension, |
enum FileAggregator::FileType | fileType = FileAggregator::SPACE_SEPARATED |
||
) |
outputFileNameWithoutExtension | name of output file to write with no extension |
fileType | type of file to write. |
Constructs a file helper that will create a file named outputFileNameWithoutExtension plus possible extra information from wildcard matches plus ".txt" with values printed as specified by fileType. The default file type is space-separated.
Definition at line 48 of file file-helper.cc.
References NS_LOG_FUNCTION.
|
virtual |
Definition at line 62 of file file-helper.cc.
References NS_LOG_FUNCTION.
void ns3::FileHelper::AddAggregator | ( | const std::string & | aggregatorName, |
const std::string & | outputFileName, | ||
bool | onlyOneAggregator | ||
) |
Adds an aggregator to be used to write values to files.
aggregatorName | the aggregator's name. |
outputFileName | name of the file to write. |
onlyOneAggregator | indicates if more than one aggregator should be created or not. |
Definition at line 237 of file file-helper.cc.
References GetAggregatorSingle(), m_10dFormat, m_1dFormat, m_2dFormat, m_3dFormat, m_4dFormat, m_5dFormat, m_6dFormat, m_7dFormat, m_8dFormat, m_9dFormat, m_aggregatorMap, m_fileType, m_heading, NS_ABORT_MSG, and NS_LOG_FUNCTION.
Referenced by ConnectProbeToAggregator(), and GetAggregatorMultiple().
|
private |
Adds a probe to be used to write values to files.
typeId | the type ID for the probe used when it is created. |
probeName | the probe's name. |
path | Config path to access the probe |
Definition at line 180 of file file-helper.cc.
References ns3::ObjectFactory::Create(), ns3::Object::GetObject(), m_factory, m_probeMap, NS_ABORT_MSG, NS_LOG_FUNCTION, and ns3::ObjectFactory::SetTypeId().
Referenced by ConnectProbeToAggregator().
void ns3::FileHelper::AddTimeSeriesAdaptor | ( | const std::string & | adaptorName | ) |
Adds a time series adaptor to be used to write the file.
adaptorName | the timeSeriesAdaptor's name. |
Definition at line 216 of file file-helper.cc.
References m_timeSeriesAdaptorMap, NS_ABORT_MSG, and NS_LOG_FUNCTION.
Referenced by ConnectProbeToAggregator().
void ns3::FileHelper::ConfigureFile | ( | const std::string & | outputFileNameWithoutExtension, |
enum FileAggregator::FileType | fileType = FileAggregator::SPACE_SEPARATED |
||
) |
outputFileNameWithoutExtension | name of output file to write with no extension |
fileType | type of file to write. |
Configures file related parameters for this file helper so that it will create a file named outputFileNameWithoutExtension plus possible extra information from wildcard matches plus ".txt" with values printed as specified by fileType. The default file type is space-separated.
Definition at line 68 of file file-helper.cc.
References m_aggregator, m_fileType, m_hasHeadingBeenSet, m_outputFileNameWithoutExtension, NS_LOG_FUNCTION, and NS_LOG_WARN.
|
private |
Connects the probe to the aggregator.
typeId | the type ID for the probe used when it is created. |
matchIdentifier | this string is used to make the probe's context be unique. |
path | Config path to access the probe. |
probeTraceSource | the probe trace source to access. |
outputFileNameWithoutExtension | name of output file to write with no extension |
onlyOneAggregator | indicates if more than one aggregator should be created or not. |
A fatal error will result if an unknown probe type is used.
Definition at line 451 of file file-helper.cc.
References AddAggregator(), AddProbe(), AddTimeSeriesAdaptor(), m_aggregatorMap, m_fileProbeCount, m_probeMap, m_timeSeriesAdaptorMap, ns3::MakeCallback(), NS_FATAL_ERROR, NS_LOG_FUNCTION, ns3::TimeSeriesAdaptor::TraceSinkBoolean(), ns3::TimeSeriesAdaptor::TraceSinkDouble(), ns3::TimeSeriesAdaptor::TraceSinkUinteger16(), ns3::TimeSeriesAdaptor::TraceSinkUinteger32(), ns3::TimeSeriesAdaptor::TraceSinkUinteger8(), and ns3::FileAggregator::Write2d().
Referenced by WriteProbe().
Ptr< FileAggregator > ns3::FileHelper::GetAggregatorMultiple | ( | const std::string & | aggregatorName, |
const std::string & | outputFileName | ||
) |
Gets one of the multiple aggregators from the map.
aggregatorName | name for aggregator. |
outputFileName | name of output file to write. |
Definition at line 340 of file file-helper.cc.
References AddAggregator(), m_aggregatorMap, and NS_LOG_FUNCTION.
Ptr< FileAggregator > ns3::FileHelper::GetAggregatorSingle | ( | ) |
Gets the single aggregator that is always constructed.
Definition at line 306 of file file-helper.cc.
References m_10dFormat, m_1dFormat, m_2dFormat, m_3dFormat, m_4dFormat, m_5dFormat, m_6dFormat, m_7dFormat, m_8dFormat, m_9dFormat, m_aggregator, m_fileType, m_heading, m_outputFileNameWithoutExtension, and NS_LOG_FUNCTION.
Referenced by AddAggregator().
Gets the specified probe.
probeName | the probe's name. |
Definition at line 287 of file file-helper.cc.
References m_probeMap, NS_ABORT_MSG, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set10dFormat | ( | const std::string & | format | ) |
Sets the 10D format string for the C-style sprintf() function.
format | the 10D format string. |
Definition at line 443 of file file-helper.cc.
References m_10dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set1dFormat | ( | const std::string & | format | ) |
Sets the 1D format string for the C-style sprintf() function.
format | the 1D format string. |
Definition at line 371 of file file-helper.cc.
References m_1dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set2dFormat | ( | const std::string & | format | ) |
Sets the 2D format string for the C-style sprintf() function.
format | the 2D format string. |
Definition at line 379 of file file-helper.cc.
References m_2dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set3dFormat | ( | const std::string & | format | ) |
Sets the 3D format string for the C-style sprintf() function.
format | the 3D format string. |
Definition at line 387 of file file-helper.cc.
References m_3dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set4dFormat | ( | const std::string & | format | ) |
Sets the 4D format string for the C-style sprintf() function.
format | the 4D format string. |
Definition at line 395 of file file-helper.cc.
References m_4dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set5dFormat | ( | const std::string & | format | ) |
Sets the 5D format string for the C-style sprintf() function.
format | the 5D format string. |
Definition at line 403 of file file-helper.cc.
References m_5dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set6dFormat | ( | const std::string & | format | ) |
Sets the 6D format string for the C-style sprintf() function.
format | the 6D format string. |
Definition at line 411 of file file-helper.cc.
References m_6dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set7dFormat | ( | const std::string & | format | ) |
Sets the 7D format string for the C-style sprintf() function.
format | the 7D format string. |
Definition at line 419 of file file-helper.cc.
References m_7dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set8dFormat | ( | const std::string & | format | ) |
Sets the 8D format string for the C-style sprintf() function.
format | the 8D format string. |
Definition at line 427 of file file-helper.cc.
References m_8dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::Set9dFormat | ( | const std::string & | format | ) |
Sets the 9D format string for the C-style sprintf() function.
format | the 9D format string. |
Definition at line 435 of file file-helper.cc.
References m_9dFormat, and NS_LOG_FUNCTION.
void ns3::FileHelper::SetHeading | ( | const std::string & | heading | ) |
Sets the heading string that will be printed on the first line of the file.
heading | the heading string. |
Note that the heading string will only be printed if it has been set by calling this function.
Definition at line 362 of file file-helper.cc.
References m_hasHeadingBeenSet, m_heading, and NS_LOG_FUNCTION.
void ns3::FileHelper::WriteProbe | ( | const std::string & | typeId, |
const std::string & | path, | ||
const std::string & | probeTraceSource | ||
) |
typeId | the type ID for the probe used when it is created. |
path | Config path for underlying trace source to be probed |
probeTraceSource | the probe trace source to access. |
Creates output files generated by hooking the ns-3 trace source with a probe, and then writing the values from the probeTraceSource. The output file names will have the text stored in m_outputFileNameWithoutExtension plus ".txt", and will consist of the 'newValue' at each timestamp.
This method will create one or more probes according to the TypeId provided, connect the probe(s) to the trace source specified by the config path, and hook the probeTraceSource(s) to the downstream aggregator.
If the config path has more than one match in the system (e.g. there is a wildcard), then one output file for each match will be created. The output file names will contain the text in m_outputFileNameWithoutExtension plus the matched characters for each of the wildcards in the config path, separated by dashes, plus ".txt". For example, if the value in m_outputFileNameWithoutExtension is the string "packet-byte-count", and there are two wildcards in the path, then output file names like "packet-byte-count-0-0.txt" or "packet-byte-count-12-9.txt" will be possible as names for the files that will be created.
A fatal error will result if an unknown probe type is used.
This is used to indicate if multiple aggregators are needed.
Definition at line 90 of file file-helper.cc.
References ConnectProbeToAggregator(), ns3::Config::MatchContainer::GetMatchedPath(), ns3::Config::MatchContainer::GetN(), ns3::GetWildcardMatches(), ns3::Config::LookupMatches(), m_outputFileNameWithoutExtension, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
|
private |
Format string for 10D format C-style sprintf() function.
Definition at line 322 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set10dFormat().
|
private |
Format string for 1D format C-style sprintf() function.
Definition at line 313 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set1dFormat().
|
private |
Format string for 2D format C-style sprintf() function.
Definition at line 314 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set2dFormat().
|
private |
Format string for 3D format C-style sprintf() function.
Definition at line 315 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set3dFormat().
|
private |
Format string for 4D format C-style sprintf() function.
Definition at line 316 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set4dFormat().
|
private |
Format string for 5D format C-style sprintf() function.
Definition at line 317 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set5dFormat().
|
private |
Format string for 6D format C-style sprintf() function.
Definition at line 318 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set6dFormat().
|
private |
Format string for 7D format C-style sprintf() function.
Definition at line 319 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set7dFormat().
|
private |
Format string for 8D format C-style sprintf() function.
Definition at line 320 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set8dFormat().
|
private |
Format string for 9D format C-style sprintf() function.
Definition at line 321 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and Set9dFormat().
|
private |
The single aggregator that is always created in the constructor.
Definition at line 286 of file file-helper.h.
Referenced by ConfigureFile(), and GetAggregatorSingle().
|
private |
Maps aggregator names to aggregators when multiple aggregators are needed.
Definition at line 290 of file file-helper.h.
Referenced by AddAggregator(), ConnectProbeToAggregator(), and GetAggregatorMultiple().
|
private |
Used to create the probes and collectors as they are added.
Definition at line 283 of file file-helper.h.
Referenced by AddProbe().
|
private |
Number of file probes that have been created.
Definition at line 299 of file file-helper.h.
Referenced by ConnectProbeToAggregator().
|
private |
Determines the kind of file written by the aggregator.
Definition at line 302 of file file-helper.h.
Referenced by AddAggregator(), ConfigureFile(), and GetAggregatorSingle().
|
private |
Indicates if the heading line for the file has been set.
Definition at line 308 of file file-helper.h.
Referenced by ConfigureFile(), and SetHeading().
|
private |
Heading line for the outputfile.
Definition at line 311 of file file-helper.h.
Referenced by AddAggregator(), GetAggregatorSingle(), and SetHeading().
|
private |
The name of the output file to created without its extension.
Definition at line 305 of file file-helper.h.
Referenced by ConfigureFile(), GetAggregatorSingle(), and WriteProbe().
Maps probe names to probes.
Definition at line 293 of file file-helper.h.
Referenced by AddProbe(), ConnectProbeToAggregator(), and GetProbe().
|
private |
Maps time series adaptor names to time series adaptors.
Definition at line 296 of file file-helper.h.
Referenced by AddTimeSeriesAdaptor(), and ConnectProbeToAggregator().