12#include "ns3/config.h"
13#include "ns3/get-wildcard-matches.h"
26 : m_aggregator(nullptr),
29 m_outputFileNameWithoutExtension(
"file-helper"),
30 m_hasHeadingBeenSet(false)
40 : m_aggregator(nullptr),
43 m_outputFileNameWithoutExtension(outputFileNameWithoutExtension),
44 m_hasHeadingBeenSet(false)
67 <<
m_aggregator <<
" may be destroyed if no references remain.");
81 const std::string& path,
82 const std::string& probeTraceSource)
86 std::string pathWithoutLastToken;
87 std::string lastToken;
90 bool pathHasNoWildcards = path.find(
'*') == std::string::npos;
93 size_t lastSlash = path.find_last_of(
'/');
94 if (lastSlash == std::string::npos)
96 pathWithoutLastToken = path;
102 pathWithoutLastToken = path.substr(0, lastSlash);
105 lastToken = path.substr(lastSlash + 1, std::string::npos);
114 std::string matchIdentifier;
117 bool onlyOneAggregator;
120 if (matchCount == 1 && pathHasNoWildcards)
125 matchIdentifier =
"0";
126 onlyOneAggregator =
true;
134 else if (matchCount > 0)
137 for (
uint32_t i = 0; i < matchCount; i++)
140 std::ostringstream matchIdentifierStream;
141 matchIdentifierStream << i;
142 matchIdentifier = matchIdentifierStream.str();
143 onlyOneAggregator =
false;
147 std::string wildcardSeparator =
"-";
149 std::string wildcardMatches =
GetWildcardMatches(path, matchedPath, wildcardSeparator);
169 const std::string& probeName,
170 const std::string& path)
191 probe->SetName(probeName);
194 probe->ConnectByPath(path);
200 m_probeMap[probeName] = std::make_pair(probe, typeId);
211 NS_ABORT_MSG(
"That time series adaptor has already been added");
218 timeSeriesAdaptor->Enable();
226 const std::string& outputFileName,
227 bool onlyOneAggregator)
229 NS_LOG_FUNCTION(
this << aggregatorName << outputFileName << onlyOneAggregator);
234 NS_ABORT_MSG(
"That file aggregator has already been added");
239 if (onlyOneAggregator)
265 multipleAggregator->SetHeading(
m_heading);
268 multipleAggregator->Enable();
280 auto mapIterator =
m_probeMap.find(probeName);
285 return mapIterator->second.first;
329 const std::string& outputFileName)
341 bool onlyOneAggregator =
false;
342 AddAggregator(aggregatorName, outputFileName, onlyOneAggregator);
438 const std::string& matchIdentifier,
439 const std::string& path,
440 const std::string& probeTraceSource,
441 const std::string& outputFileNameWithoutExtension,
442 bool onlyOneAggregator)
444 NS_LOG_FUNCTION(
this << typeId << matchIdentifier << path << probeTraceSource
445 << outputFileNameWithoutExtension << onlyOneAggregator);
451 std::ostringstream probeNameStream;
453 std::string probeName = probeNameStream.str();
456 std::string probeContext = probeName +
"/" + matchIdentifier +
"/" + probeTraceSource;
471 m_probeMap[probeName].first->TraceConnectWithoutContext(
478 m_probeMap[probeName].first->TraceConnectWithoutContext(
489 m_probeMap[probeName].first->TraceConnectWithoutContext(
496 m_probeMap[probeName].first->TraceConnectWithoutContext(
503 m_probeMap[probeName].first->TraceConnectWithoutContext(
511 <<
"; need to add support in the helper for this");
516 std::string outputFileName = outputFileNameWithoutExtension +
".txt";
517 AddAggregator(probeContext, outputFileName, onlyOneAggregator);
520 std::string adaptorTraceSource =
"Output";
hold a set of objects which match a specific search string.
std::string GetMatchedPath(uint32_t i) const
This aggregator sends values it receives to a file.
void Write2d(std::string context, double v1, double v2)
Writes 2 values to the file.
FileType
The type of file written by the aggregator.
void Set2dFormat(const std::string &format)
Sets the 2D 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 Set5dFormat(const std::string &format)
Sets the 5D format string for the C-style sprintf() function.
void AddTimeSeriesAdaptor(const std::string &adaptorName)
Adds a time series adaptor to be used to write the file.
Ptr< FileAggregator > GetAggregatorSingle()
Gets the single aggregator that is always constructed.
std::string m_6dFormat
Format string for 6D format C-style sprintf() function.
std::map< std::string, std::pair< Ptr< Probe >, std::string > > m_probeMap
Maps probe names to probes.
void Set3dFormat(const std::string &format)
Sets the 3D format string for the C-style sprintf() function.
Ptr< Probe > GetProbe(std::string probeName) const
Gets the specified probe.
std::map< std::string, Ptr< TimeSeriesAdaptor > > m_timeSeriesAdaptorMap
Maps time series adaptor names to time series adaptors.
void WriteProbe(const std::string &typeId, const std::string &path, const std::string &probeTraceSource)
std::map< std::string, Ptr< FileAggregator > > m_aggregatorMap
Maps aggregator names to aggregators when multiple aggregators are needed.
FileHelper()
Constructs a file helper that will create a space separated file named "file-helper....
void Set6dFormat(const std::string &format)
Sets the 6D format string for the C-style sprintf() function.
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.
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::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.
void ConfigureFile(const std::string &outputFileNameWithoutExtension, FileAggregator::FileType fileType=FileAggregator::SPACE_SEPARATED)
bool m_hasHeadingBeenSet
Indicates if the heading line for the file has been set.
std::string m_2dFormat
Format string for 2D format C-style sprintf() function.
void AddAggregator(const std::string &aggregatorName, const std::string &outputFileName, bool onlyOneAggregator)
Adds an aggregator to be used to write values to files.
void Set1dFormat(const std::string &format)
Sets the 1D format string for the C-style sprintf() function.
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.
std::string m_1dFormat
Format string for 1D format C-style sprintf() function.
std::string m_10dFormat
Format string for 10D format C-style sprintf() function.
std::string m_4dFormat
Format string for 4D format C-style sprintf() function.
std::string m_7dFormat
Format string for 7D format C-style sprintf() function.
void Set4dFormat(const std::string &format)
Sets the 4D 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.
FileAggregator::FileType m_fileType
Determines the kind of file written by the aggregator.
Ptr< FileAggregator > m_aggregator
The single aggregator that is always created in the constructor.
std::string m_5dFormat
Format string for 5D format C-style sprintf() function.
std::string m_3dFormat
Format string for 3D format C-style sprintf() function.
void Set8dFormat(const std::string &format)
Sets the 8D format string for the C-style sprintf() function.
Ptr< FileAggregator > GetAggregatorMultiple(const std::string &aggregatorName, const std::string &outputFileName)
Gets one of the multiple aggregators from the map.
void Set10dFormat(const std::string &format)
Sets the 10D format string for the C-style sprintf() function.
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.
void Set9dFormat(const std::string &format)
Sets the 9D format string for the C-style sprintf() function.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Smart pointer class similar to boost::intrusive_ptr.
void TraceSinkUinteger8(uint8_t oldData, uint8_t newData)
Trace sink for receiving data from uint8_t valued trace sources.
void TraceSinkDouble(double oldData, double newData)
Trace sink for receiving data from double valued trace sources.
void TraceSinkBoolean(bool oldData, bool newData)
Trace sink for receiving data from bool valued trace sources.
void TraceSinkUinteger32(uint32_t oldData, uint32_t newData)
Trace sink for receiving data from uint32_t valued trace sources.
void TraceSinkUinteger16(uint16_t oldData, uint16_t newData)
Trace sink for receiving data from uint16_t valued trace sources.
MatchContainer LookupMatches(std::string path)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Callback< R, Args... > MakeCallback(R(T::*memPtr)(Args...), OBJ objPtr)
Build Callbacks for class method members which take varying numbers of arguments and potentially retu...
std::string GetWildcardMatches(const std::string &configPath, const std::string &matchedPath, const std::string &wildcardSeparator)
Returns the text matches from the matched path for each of the wildcards in the Config path,...