A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::FileHelper Class Reference

Helper class used to put data values into a file. More...

#include "file-helper.h"

+ Collaboration diagram for ns3::FileHelper:

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.
 
 FileHelper (const std::string &outputFileNameWithoutExtension, 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.
 
void AddTimeSeriesAdaptor (const std::string &adaptorName)
 Adds a time series adaptor to be used to write the file.
 
void ConfigureFile (const std::string &outputFileNameWithoutExtension, FileAggregator::FileType fileType=FileAggregator::SPACE_SEPARATED)
 
Ptr< FileAggregatorGetAggregatorMultiple (const std::string &aggregatorName, const std::string &outputFileName)
 Gets one of the multiple aggregators from the map.
 
Ptr< FileAggregatorGetAggregatorSingle ()
 Gets the single aggregator that is always constructed.
 
Ptr< ProbeGetProbe (std::string probeName) const
 Gets the specified probe.
 
void Set10dFormat (const std::string &format)
 Sets the 10D format string for the C-style sprintf() function.
 
void Set1dFormat (const std::string &format)
 Sets the 1D format string for the C-style sprintf() function.
 
void Set2dFormat (const std::string &format)
 Sets the 2D format string for the C-style sprintf() function.
 
void Set3dFormat (const std::string &format)
 Sets the 3D format string for the C-style sprintf() function.
 
void Set4dFormat (const std::string &format)
 Sets the 4D format string for the C-style sprintf() function.
 
void Set5dFormat (const std::string &format)
 Sets the 5D format string for the C-style sprintf() function.
 
void Set6dFormat (const std::string &format)
 Sets the 6D format string for the C-style sprintf() function.
 
void Set7dFormat (const std::string &format)
 Sets the 7D format string for the C-style sprintf() function.
 
void Set8dFormat (const std::string &format)
 Sets the 8D format string for the C-style sprintf() function.
 
void Set9dFormat (const std::string &format)
 Sets the 9D format string for the C-style sprintf() function.
 
void SetHeading (const std::string &heading)
 Sets the heading string that will be printed on the first line of the file.
 
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.
 
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.
 

Private Attributes

std::string m_10dFormat
 Format string for 10D format C-style sprintf() function.
 
std::string m_1dFormat
 Format string for 1D format C-style sprintf() function.
 
std::string m_2dFormat
 Format string for 2D format C-style sprintf() function.
 
std::string m_3dFormat
 Format string for 3D format C-style sprintf() function.
 
std::string m_4dFormat
 Format string for 4D format C-style sprintf() function.
 
std::string m_5dFormat
 Format string for 5D format C-style sprintf() function.
 
std::string m_6dFormat
 Format string for 6D format C-style sprintf() function.
 
std::string m_7dFormat
 Format string for 7D format C-style sprintf() function.
 
std::string m_8dFormat
 Format string for 8D format C-style sprintf() function.
 
std::string m_9dFormat
 Format string for 9D format C-style sprintf() function.
 
Ptr< FileAggregatorm_aggregator
 The single aggregator that is always created in the constructor.
 
std::map< std::string, Ptr< FileAggregator > > m_aggregatorMap
 Maps aggregator names to aggregators when multiple aggregators are needed.
 
ObjectFactory m_factory
 Used to create the probes and collectors as they are added.
 
uint32_t m_fileProbeCount
 Number of file probes that have been created.
 
FileAggregator::FileType m_fileType
 Determines the kind of file written by the aggregator.
 
bool m_hasHeadingBeenSet
 Indicates if the heading line for the file has been set.
 
std::string m_heading
 Heading line for the outputfile.
 
std::string m_outputFileNameWithoutExtension
 The name of the output file to created without its extension.
 
std::map< std::string, std::pair< Ptr< Probe >, std::string > > m_probeMap
 Maps probe names to probes.
 
std::map< std::string, Ptr< TimeSeriesAdaptor > > m_timeSeriesAdaptorMap
 Maps time series adaptor names to time series adaptors.
 

Detailed Description

Helper class used to put data values into a file.

Definition at line 28 of file file-helper.h.

Constructor & Destructor Documentation

◆ FileHelper() [1/2]

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 25 of file file-helper.cc.

References NS_LOG_FUNCTION.

◆ FileHelper() [2/2]

ns3::FileHelper::FileHelper ( const std::string & outputFileNameWithoutExtension,
FileAggregator::FileType fileType = FileAggregator::SPACE_SEPARATED )
Parameters
outputFileNameWithoutExtensionname of output file to write with no extension
fileTypetype 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 38 of file file-helper.cc.

References NS_LOG_FUNCTION.

◆ ~FileHelper()

ns3::FileHelper::~FileHelper ( )
virtual

Definition at line 52 of file file-helper.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ AddAggregator()

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.

Parameters
aggregatorNamethe aggregator's name.
outputFileNamename of the file to write.
onlyOneAggregatorindicates if more than one aggregator should be created or not.

Definition at line 225 of file file-helper.cc.

References ns3::CreateObject(), 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddProbe()

void ns3::FileHelper::AddProbe ( const std::string & typeId,
const std::string & probeName,
const std::string & path )
private

Adds a probe to be used to write values to files.

Parameters
typeIdthe type ID for the probe used when it is created.
probeNamethe probe's name.
pathConfig path to access the probe

Definition at line 168 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddTimeSeriesAdaptor()

void ns3::FileHelper::AddTimeSeriesAdaptor ( const std::string & adaptorName)

Adds a time series adaptor to be used to write the file.

Parameters
adaptorNamethe timeSeriesAdaptor's name.

Definition at line 204 of file file-helper.cc.

References ns3::CreateObject(), m_timeSeriesAdaptorMap, NS_ABORT_MSG, and NS_LOG_FUNCTION.

Referenced by ConnectProbeToAggregator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConfigureFile()

void ns3::FileHelper::ConfigureFile ( const std::string & outputFileNameWithoutExtension,
FileAggregator::FileType fileType = FileAggregator::SPACE_SEPARATED )
Parameters
outputFileNameWithoutExtensionname of output file to write with no extension
fileTypetype 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 58 of file file-helper.cc.

References m_aggregator, m_fileType, m_hasHeadingBeenSet, m_outputFileNameWithoutExtension, NS_LOG_FUNCTION, and NS_LOG_WARN.

◆ ConnectProbeToAggregator()

void ns3::FileHelper::ConnectProbeToAggregator ( const std::string & typeId,
const std::string & matchIdentifier,
const std::string & path,
const std::string & probeTraceSource,
const std::string & outputFileNameWithoutExtension,
bool onlyOneAggregator )
private

Connects the probe to the aggregator.

Parameters
typeIdthe type ID for the probe used when it is created.
matchIdentifierthis string is used to make the probe's context be unique.
pathConfig path to access the probe.
probeTraceSourcethe probe trace source to access.
outputFileNameWithoutExtensionname of output file to write with no extension
onlyOneAggregatorindicates 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 437 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetAggregatorMultiple()

Ptr< FileAggregator > ns3::FileHelper::GetAggregatorMultiple ( const std::string & aggregatorName,
const std::string & outputFileName )

Gets one of the multiple aggregators from the map.

Parameters
aggregatorNamename for aggregator.
outputFileNamename of output file to write.
Returns
Ptr to a FileAggregator object

This function is non-const because an aggregator may be lazily created by this method.

Definition at line 328 of file file-helper.cc.

References AddAggregator(), m_aggregatorMap, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetAggregatorSingle()

Ptr< FileAggregator > ns3::FileHelper::GetAggregatorSingle ( )

Gets the single aggregator that is always constructed.

Returns
Ptr to a FileAggregator object

This function is non-const because an aggregator may be lazily created by this method.

Definition at line 294 of file file-helper.cc.

References ns3::CreateObject(), 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetProbe()

Ptr< Probe > ns3::FileHelper::GetProbe ( std::string probeName) const

Gets the specified probe.

Parameters
probeNamethe probe's name.
Returns
Ptr to the probe

Definition at line 275 of file file-helper.cc.

References m_probeMap, NS_ABORT_MSG, and NS_LOG_FUNCTION.

◆ Set10dFormat()

void ns3::FileHelper::Set10dFormat ( const std::string & format)

Sets the 10D format string for the C-style sprintf() function.

Parameters
formatthe 10D format string.

Definition at line 429 of file file-helper.cc.

References m_10dFormat, and NS_LOG_FUNCTION.

◆ Set1dFormat()

void ns3::FileHelper::Set1dFormat ( const std::string & format)

Sets the 1D format string for the C-style sprintf() function.

Parameters
formatthe 1D format string.

Definition at line 357 of file file-helper.cc.

References m_1dFormat, and NS_LOG_FUNCTION.

◆ Set2dFormat()

void ns3::FileHelper::Set2dFormat ( const std::string & format)

Sets the 2D format string for the C-style sprintf() function.

Parameters
formatthe 2D format string.

Definition at line 365 of file file-helper.cc.

References m_2dFormat, and NS_LOG_FUNCTION.

◆ Set3dFormat()

void ns3::FileHelper::Set3dFormat ( const std::string & format)

Sets the 3D format string for the C-style sprintf() function.

Parameters
formatthe 3D format string.

Definition at line 373 of file file-helper.cc.

References m_3dFormat, and NS_LOG_FUNCTION.

◆ Set4dFormat()

void ns3::FileHelper::Set4dFormat ( const std::string & format)

Sets the 4D format string for the C-style sprintf() function.

Parameters
formatthe 4D format string.

Definition at line 381 of file file-helper.cc.

References m_4dFormat, and NS_LOG_FUNCTION.

◆ Set5dFormat()

void ns3::FileHelper::Set5dFormat ( const std::string & format)

Sets the 5D format string for the C-style sprintf() function.

Parameters
formatthe 5D format string.

Definition at line 389 of file file-helper.cc.

References m_5dFormat, and NS_LOG_FUNCTION.

◆ Set6dFormat()

void ns3::FileHelper::Set6dFormat ( const std::string & format)

Sets the 6D format string for the C-style sprintf() function.

Parameters
formatthe 6D format string.

Definition at line 397 of file file-helper.cc.

References m_6dFormat, and NS_LOG_FUNCTION.

◆ Set7dFormat()

void ns3::FileHelper::Set7dFormat ( const std::string & format)

Sets the 7D format string for the C-style sprintf() function.

Parameters
formatthe 7D format string.

Definition at line 405 of file file-helper.cc.

References m_7dFormat, and NS_LOG_FUNCTION.

◆ Set8dFormat()

void ns3::FileHelper::Set8dFormat ( const std::string & format)

Sets the 8D format string for the C-style sprintf() function.

Parameters
formatthe 8D format string.

Definition at line 413 of file file-helper.cc.

References m_8dFormat, and NS_LOG_FUNCTION.

◆ Set9dFormat()

void ns3::FileHelper::Set9dFormat ( const std::string & format)

Sets the 9D format string for the C-style sprintf() function.

Parameters
formatthe 9D format string.

Definition at line 421 of file file-helper.cc.

References m_9dFormat, and NS_LOG_FUNCTION.

◆ SetHeading()

void ns3::FileHelper::SetHeading ( const std::string & heading)

Sets the heading string that will be printed on the first line of the file.

Parameters
headingthe heading string.

Note that the heading string will only be printed if it has been set by calling this function.

Definition at line 348 of file file-helper.cc.

References m_hasHeadingBeenSet, m_heading, and NS_LOG_FUNCTION.

◆ WriteProbe()

void ns3::FileHelper::WriteProbe ( const std::string & typeId,
const std::string & path,
const std::string & probeTraceSource )
Parameters
typeIdthe type ID for the probe used when it is created.
pathConfig path for underlying trace source to be probed
probeTraceSourcethe 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 80 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.

+ Here is the call graph for this function:

Member Data Documentation

◆ m_10dFormat

std::string ns3::FileHelper::m_10dFormat
private

Format string for 10D format C-style sprintf() function.

Definition at line 310 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set10dFormat().

◆ m_1dFormat

std::string ns3::FileHelper::m_1dFormat
private

Format string for 1D format C-style sprintf() function.

Definition at line 301 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set1dFormat().

◆ m_2dFormat

std::string ns3::FileHelper::m_2dFormat
private

Format string for 2D format C-style sprintf() function.

Definition at line 302 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set2dFormat().

◆ m_3dFormat

std::string ns3::FileHelper::m_3dFormat
private

Format string for 3D format C-style sprintf() function.

Definition at line 303 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set3dFormat().

◆ m_4dFormat

std::string ns3::FileHelper::m_4dFormat
private

Format string for 4D format C-style sprintf() function.

Definition at line 304 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set4dFormat().

◆ m_5dFormat

std::string ns3::FileHelper::m_5dFormat
private

Format string for 5D format C-style sprintf() function.

Definition at line 305 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set5dFormat().

◆ m_6dFormat

std::string ns3::FileHelper::m_6dFormat
private

Format string for 6D format C-style sprintf() function.

Definition at line 306 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set6dFormat().

◆ m_7dFormat

std::string ns3::FileHelper::m_7dFormat
private

Format string for 7D format C-style sprintf() function.

Definition at line 307 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set7dFormat().

◆ m_8dFormat

std::string ns3::FileHelper::m_8dFormat
private

Format string for 8D format C-style sprintf() function.

Definition at line 308 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set8dFormat().

◆ m_9dFormat

std::string ns3::FileHelper::m_9dFormat
private

Format string for 9D format C-style sprintf() function.

Definition at line 309 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and Set9dFormat().

◆ m_aggregator

Ptr<FileAggregator> ns3::FileHelper::m_aggregator
private

The single aggregator that is always created in the constructor.

Definition at line 274 of file file-helper.h.

Referenced by ConfigureFile(), and GetAggregatorSingle().

◆ m_aggregatorMap

std::map<std::string, Ptr<FileAggregator> > ns3::FileHelper::m_aggregatorMap
private

Maps aggregator names to aggregators when multiple aggregators are needed.

Definition at line 278 of file file-helper.h.

Referenced by AddAggregator(), ConnectProbeToAggregator(), and GetAggregatorMultiple().

◆ m_factory

ObjectFactory ns3::FileHelper::m_factory
private

Used to create the probes and collectors as they are added.

Definition at line 271 of file file-helper.h.

Referenced by AddProbe().

◆ m_fileProbeCount

uint32_t ns3::FileHelper::m_fileProbeCount
private

Number of file probes that have been created.

Definition at line 287 of file file-helper.h.

Referenced by ConnectProbeToAggregator().

◆ m_fileType

FileAggregator::FileType ns3::FileHelper::m_fileType
private

Determines the kind of file written by the aggregator.

Definition at line 290 of file file-helper.h.

Referenced by AddAggregator(), ConfigureFile(), and GetAggregatorSingle().

◆ m_hasHeadingBeenSet

bool ns3::FileHelper::m_hasHeadingBeenSet
private

Indicates if the heading line for the file has been set.

Definition at line 296 of file file-helper.h.

Referenced by ConfigureFile(), and SetHeading().

◆ m_heading

std::string ns3::FileHelper::m_heading
private

Heading line for the outputfile.

Definition at line 299 of file file-helper.h.

Referenced by AddAggregator(), GetAggregatorSingle(), and SetHeading().

◆ m_outputFileNameWithoutExtension

std::string ns3::FileHelper::m_outputFileNameWithoutExtension
private

The name of the output file to created without its extension.

Definition at line 293 of file file-helper.h.

Referenced by ConfigureFile(), GetAggregatorSingle(), and WriteProbe().

◆ m_probeMap

std::map<std::string, std::pair<Ptr<Probe>, std::string> > ns3::FileHelper::m_probeMap
private

Maps probe names to probes.

Definition at line 281 of file file-helper.h.

Referenced by AddProbe(), ConnectProbeToAggregator(), and GetProbe().

◆ m_timeSeriesAdaptorMap

std::map<std::string, Ptr<TimeSeriesAdaptor> > ns3::FileHelper::m_timeSeriesAdaptorMap
private

Maps time series adaptor names to time series adaptors.

Definition at line 284 of file file-helper.h.

Referenced by AddTimeSeriesAdaptor(), and ConnectProbeToAggregator().


The documentation for this class was generated from the following files: