A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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. 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 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 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< FileAggregatorGetAggregatorMultiple (const std::string &aggregatorName, const std::string &outputFileName)
 Gets one of the multiple aggregators from the map. More...
 
Ptr< FileAggregatorGetAggregatorSingle ()
 Gets the single aggregator that is always constructed. More...
 
Ptr< ProbeGetProbe (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 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< FileAggregatorm_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...
 

Detailed Description

Helper class used to put data values into a file.

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

Constructor & Destructor Documentation

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

References NS_LOG_FUNCTION.

ns3::FileHelper::FileHelper ( const std::string &  outputFileNameWithoutExtension,
enum 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 49 of file file-helper.cc.

References NS_LOG_FUNCTION.

ns3::FileHelper::~FileHelper ( )
virtual

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

References NS_LOG_FUNCTION.

Member Function Documentation

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 238 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().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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 181 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:

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

References m_timeSeriesAdaptorMap, NS_ABORT_MSG, and NS_LOG_FUNCTION.

Referenced by ConnectProbeToAggregator().

+ Here is the caller graph for this function:

void ns3::FileHelper::ConfigureFile ( const std::string &  outputFileNameWithoutExtension,
enum 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 69 of file file-helper.cc.

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

Referenced by main().

+ Here is the caller graph for this function:

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 452 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:

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

References AddAggregator(), m_aggregatorMap, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

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 307 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().

+ Here is the caller graph for this function:

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 288 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.

Parameters
formatthe 10D format string.

Definition at line 444 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.

Parameters
formatthe 1D format string.

Definition at line 372 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.

Parameters
formatthe 2D format string.

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

References m_2dFormat, and NS_LOG_FUNCTION.

Referenced by main().

+ Here is the caller graph for this function:

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 388 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.

Parameters
formatthe 4D format string.

Definition at line 396 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.

Parameters
formatthe 5D format string.

Definition at line 404 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.

Parameters
formatthe 6D format string.

Definition at line 412 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.

Parameters
formatthe 7D format string.

Definition at line 420 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.

Parameters
formatthe 8D format string.

Definition at line 428 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.

Parameters
formatthe 9D format string.

Definition at line 436 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.

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 363 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 
)
Parameters
typeIdthe type ID for the probe used when it is created.
pathConfig path to access the probe.
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.

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 91 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.

Referenced by main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The single aggregator that is always created in the constructor.

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

Referenced by ConfigureFile(), and GetAggregatorSingle().

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

Maps aggregator names to aggregators when multiple aggregators are needed.

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

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

ObjectFactory ns3::FileHelper::m_factory
private

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

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

Referenced by AddProbe().

uint32_t ns3::FileHelper::m_fileProbeCount
private

Number of file probes that have been created.

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

Referenced by ConnectProbeToAggregator().

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

Determines the kind of file written by the aggregator.

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

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

bool ns3::FileHelper::m_hasHeadingBeenSet
private

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

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

Referenced by ConfigureFile(), and SetHeading().

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

Heading line for the outputfile.

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

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

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

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

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

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

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

Maps probe names to probes.

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

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

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

Maps time series adaptor names to time series adaptors.

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

Referenced by AddTimeSeriesAdaptor(), and ConnectProbeToAggregator().


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