26 #include "ns3/abort.h" 28 #include "ns3/config.h" 29 #include "ns3/get-wildcard-matches.h" 39 m_outputFileNameWithoutExtension (
"file-helper"),
40 m_hasHeadingBeenSet (false)
52 m_fileType (fileType),
53 m_outputFileNameWithoutExtension (outputFileNameWithoutExtension),
54 m_hasHeadingBeenSet (false)
77 " may be destroyed if no references remain.");
91 const std::string &path,
92 const std::string &probeTraceSource)
96 std::string pathWithoutLastToken;
97 std::string lastToken;
100 bool pathHasNoWildcards = path.find (
"*") == std::string::npos;
103 size_t lastSlash = path.find_last_of (
"/");
104 if (lastSlash == std::string::npos)
106 pathWithoutLastToken = path;
112 pathWithoutLastToken = path.substr (0, lastSlash);
115 lastToken = path.substr (lastSlash + 1, std::string::npos);
121 uint32_t matchCount = matches.
GetN ();
124 std::string matchIdentifier;
127 bool onlyOneAggregator;
130 if (matchCount == 1 && pathHasNoWildcards)
135 matchIdentifier =
"0";
136 onlyOneAggregator =
true;
144 else if (matchCount > 0)
147 for (uint32_t i = 0; i < matchCount; i++)
150 std::ostringstream matchIdentifierStream;
151 matchIdentifierStream << i;
152 matchIdentifier = matchIdentifierStream.str ();
153 onlyOneAggregator =
false;
157 std::string wildcardSeparator =
"-";
181 const std::string &probeName,
182 const std::string &path)
203 probe->SetName (probeName);
206 probe->ConnectByPath (path);
212 m_probeMap[probeName] = std::make_pair (probe, typeId);
223 NS_ABORT_MSG (
"That time series adaptor has already been added");
230 timeSeriesAdaptor->Enable ();
238 const std::string &outputFileName,
239 bool onlyOneAggregator)
241 NS_LOG_FUNCTION (
this << aggregatorName << outputFileName << onlyOneAggregator);
246 NS_ABORT_MSG (
"That file aggregator has already been added");
251 if (onlyOneAggregator)
262 CreateObject<FileAggregator> (outputFileName,
m_fileType);
277 multipleAggregator->SetHeading (
m_heading);
280 multipleAggregator->Enable ();
292 std::map<std::string, std::pair <Ptr<Probe>, std::string> >::const_iterator mapIterator =
m_probeMap.find (probeName);
297 return mapIterator->second.first;
341 const std::string &outputFileName)
353 bool onlyOneAggregator =
false;
452 const std::string &matchIdentifier,
453 const std::string &path,
454 const std::string &probeTraceSource,
455 const std::string &outputFileNameWithoutExtension,
456 bool onlyOneAggregator)
458 NS_LOG_FUNCTION (
this << typeId << matchIdentifier << path << probeTraceSource
459 << outputFileNameWithoutExtension << onlyOneAggregator);
465 std::ostringstream probeNameStream;
467 std::string probeName = probeNameStream.str ();
470 std::string probeContext = probeName
471 +
"/" + matchIdentifier +
"/" + probeTraceSource;
485 m_probeMap[probeName].first->TraceConnectWithoutContext
492 m_probeMap[probeName].first->TraceConnectWithoutContext
499 m_probeMap[probeName].first->TraceConnectWithoutContext
506 m_probeMap[probeName].first->TraceConnectWithoutContext
513 m_probeMap[probeName].first->TraceConnectWithoutContext
520 m_probeMap[probeName].first->TraceConnectWithoutContext
527 m_probeMap[probeName].first->TraceConnectWithoutContext
534 m_probeMap[probeName].first->TraceConnectWithoutContext
541 m_probeMap[probeName].first->TraceConnectWithoutContext
548 m_probeMap[probeName].first->TraceConnectWithoutContext
560 std::string outputFileName = outputFileNameWithoutExtension +
".txt";
561 AddAggregator (probeContext, outputFileName, onlyOneAggregator);
564 std::string adaptorTraceSource =
"Output";
std::string GetMatchedPath(uint32_t i) const
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
std::string m_3dFormat
Format string for 3D format C-style sprintf() function.
std::string m_6dFormat
Format string for 6D format C-style sprintf() function.
std::string m_9dFormat
Format string for 9D format C-style sprintf() function.
void Set4dFormat(const std::string &format)
Sets the 4D format string for the C-style sprintf() function.
std::string m_4dFormat
Format string for 4D format C-style sprintf() function.
Ptr< FileAggregator > m_aggregator
The single aggregator that is always created in the constructor.
void Set8dFormat(const std::string &format)
Sets the 8D format string for the C-style sprintf() function.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
void Set6dFormat(const std::string &format)
Sets the 6D format string for the C-style sprintf() function.
std::size_t GetN(void) const
void Set5dFormat(const std::string &format)
Sets the 5D format string for the C-style sprintf() function.
void Set10dFormat(const std::string &format)
Sets the 10D format string for the C-style sprintf() function.
std::string m_7dFormat
Format string for 7D format 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.
This aggregator sends values it receives to a file.
void AddAggregator(const std::string &aggregatorName, const std::string &outputFileName, bool onlyOneAggregator)
Adds an aggregator to be used to write values to files.
void Write2d(std::string context, double v1, double v2)
Writes 2 values to the file.
void Set9dFormat(const std::string &format)
Sets the 9D format string for the C-style sprintf() function.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
uint32_t m_fileProbeCount
Number of file probes that have been created.
std::string m_10dFormat
Format string for 10D format C-style sprintf() function.
std::string m_8dFormat
Format string for 8D format C-style sprintf() function.
FileType
The type of file written by the aggregator.
FileHelper()
Constructs a file helper that will create a space separated file named "file-helper.txt" unless it is later configured otherwise.
std::string m_heading
Heading line for the outputfile.
Callback< R > MakeCallback(R(T::*memPtr)(void), OBJ objPtr)
Ptr< FileAggregator > GetAggregatorSingle()
Gets the single aggregator that is always constructed.
void TraceSinkUinteger32(uint32_t oldData, uint32_t newData)
Trace sink for receiving data from uint32_t valued trace sources.
void AddTimeSeriesAdaptor(const std::string &adaptorName)
Adds a time series adaptor to be used to write the file.
ObjectFactory m_factory
Used to create the probes and collectors as they are added.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
void Set7dFormat(const std::string &format)
Sets the 7D format string for the C-style sprintf() function.
std::map< std::string, std::pair< Ptr< Probe >, std::string > > m_probeMap
Maps probe names to probes.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::map< std::string, Ptr< FileAggregator > > m_aggregatorMap
Maps aggregator names to aggregators when multiple aggregators are needed.
void TraceSinkUinteger8(uint8_t oldData, uint8_t newData)
Trace sink for receiving data from uint8_t valued trace sources.
enum FileAggregator::FileType m_fileType
Determines the kind of file written by the aggregator.
Ptr< FileAggregator > GetAggregatorMultiple(const std::string &aggregatorName, const std::string &outputFileName)
Gets one of the multiple aggregators from the map.
void SetHeading(const std::string &heading)
Sets the heading string that will be printed on the first line of the file.
Ptr< Probe > GetProbe(std::string probeName) const
Gets the specified probe.
void ConfigureFile(const std::string &outputFileNameWithoutExtension, enum FileAggregator::FileType fileType=FileAggregator::SPACE_SEPARATED)
void Set1dFormat(const std::string &format)
Sets the 1D format string for the C-style sprintf() function.
std::string m_1dFormat
Format string for 1D format C-style sprintf() function.
hold a set of objects which match a specific search string.
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.
std::string m_2dFormat
Format string for 2D format C-style sprintf() function.
MatchContainer LookupMatches(std::string path)
void Set3dFormat(const std::string &format)
Sets the 3D format string for the C-style sprintf() function.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
bool m_hasHeadingBeenSet
Indicates if the heading line for the file has been set.
std::string m_5dFormat
Format string for 5D format C-style sprintf() function.
std::map< std::string, Ptr< TimeSeriesAdaptor > > m_timeSeriesAdaptorMap
Maps time series adaptor names to time series adaptors.
void TraceSinkUinteger16(uint16_t oldData, uint16_t newData)
Trace sink for receiving data from uint16_t valued trace sources.
void WriteProbe(const std::string &typeId, const std::string &path, const std::string &probeTraceSource)
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.
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...
std::string m_outputFileNameWithoutExtension
The name of the output file to created without its extension.
void Set2dFormat(const std::string &format)
Sets the 2D format string for the C-style sprintf() function.