//========================================================================== // OMNETPPSCALARFILEEXPORTER.CC - part of // OMNeT++/OMNEST // Discrete System Simulation in C++ // // Author: Andras Varga // //========================================================================== /*--------------------------------------------------------------* Copyright (C) 1992-2015 Andras Varga Copyright (C) 2006-2015 OpenSim Ltd. This file is distributed WITHOUT ANY WARRANTY. See the file `license' for details on this and other legal matters. *--------------------------------------------------------------*/ #include #include #include "common/stringutil.h" #include "common/stringtokenizer.h" #include "common/stlutil.h" #include "common/fileutil.h" #include "xyarray.h" #include "resultfilemanager.h" #include "datasorter.h" #include "datatable.h" #include "exportutils.h" #include "omnetppscalarfileexporter.h" using namespace std; using namespace omnetpp::common; namespace omnetpp { namespace scave { class OmnetppScalarFileExporterType : public ExporterType { public: virtual std::string getFormatName() const {return "OmnetppScalarFile";} virtual std::string getDisplayName() const {return "OMNeT++ Scalar File";} virtual std::string getDescription() const {return "Export results in OMNeT++ scalar file (.sca) format.";} virtual int getSupportedResultTypes() {return ResultFileManager::SCALAR | ResultFileManager::STATISTICS | ResultFileManager::HISTOGRAM;} virtual std::string getFileExtension() {return "sca";} virtual StringMap getSupportedOptions() const; virtual std::string getXswtForm() const; virtual Exporter *create() const {return new OmnetppScalarFileExporter();} }; string OmnetppScalarFileExporterType::getXswtForm() const { return "\n" "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\n"; } StringMap OmnetppScalarFileExporterType::getSupportedOptions() const { StringMap options { {"precision", "The number of significant digits for floating-point values (double). The maximum value is ~15."}, }; return options; } //--- ExporterType *OmnetppScalarFileExporter::getDescription() { static OmnetppScalarFileExporterType desc; return &desc; } void OmnetppScalarFileExporter::setOption(const std::string& key, const std::string& value) { checkOptionKey(getDescription(), key); if (key == "precision") setPrecision(opp_atol(value.c_str())); else throw opp_runtime_error("Exporter: unhandled option '%s'", key.c_str()); } void OmnetppScalarFileExporter::saveResults(const std::string& fileName, ResultFileManager *manager, const IDList& idlist, IProgressMonitor *monitor) { //TODO progress reporting checkItemTypes(idlist, ResultFileManager::SCALAR | ResultFileManager::STATISTICS | ResultFileManager::HISTOGRAM); removeFile(fileName.c_str(), "existing file"); // remove existing file, as open() appends writer.open(fileName.c_str()); RunList *runList = manager->getUniqueRuns(idlist); std::unique_ptr tmp(runList); for (Run *run : *runList) { writer.beginRecordingForRun(run->getRunName(), run->getAttributes(), run->getIterationVariables(), run->getParamAssignments()); IDList filteredList = manager->filterIDList(idlist, run, nullptr, nullptr); for (int i=0; igetScalar(id); writer.recordScalar(scalar.getModuleName(), scalar.getName(), scalar.getValue(), scalar.getAttributes()); } else if (ResultFileManager::getTypeOf(id) == ResultFileManager::STATISTICS) { const StatisticsResult& statistics = manager->getStatistics(id); writer.recordStatistic(statistics.getModuleName(), statistics.getName(), statistics.getStatistics(), statistics.getAttributes()); } else if (ResultFileManager::getTypeOf(id) == ResultFileManager::HISTOGRAM) { const HistogramResult& histogram = manager->getHistogram(id); writer.recordHistogram(histogram.getModuleName(), histogram.getName(), histogram.getStatistics(), histogram.getHistogram(), histogram.getAttributes()); } } writer.endRecordingForRun(); } writer.close(); } } // namespace scave } // namespace omnetpp