![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #include <WNS/probe/bus/TimeSeriesProbeBus.hpp> 00029 #include <WNS/simulator/ISimulator.hpp> 00030 #include <WNS/Ttos.hpp> 00031 00032 #include <fstream> 00033 #include <iomanip> 00034 00035 using namespace wns::probe::bus; 00036 00037 STATIC_FACTORY_REGISTER_WITH_CREATOR( 00038 TimeSeriesProbeBus, 00039 wns::probe::bus::ProbeBus, 00040 "TimeSeriesProbeBus", 00041 wns::PyConfigViewCreator); 00042 00043 TimeSeriesProbeBus::TimeSeriesProbeBus(const wns::pyconfig::View& pyco): 00044 filename(pyco.get<std::string>("outputFilename")), 00045 firstWrite(true), 00046 timePrecision(pyco.get<int>("timePrecision")), 00047 valuePrecision(pyco.get<int>("valuePrecision")), 00048 format((pyco.get<std::string>("format")=="scientific") ? formatScientific : formatFixed), 00049 name(pyco.get<std::string>("name")), 00050 desc(pyco.get<std::string>("description")), 00051 prefix("#") 00052 { 00053 wns::pyconfig::View pycoRoot = wns::simulator::getConfiguration(); 00054 outputPath = pycoRoot.get<std::string>("outputDir"); 00055 00056 for (int ii = 0; ii < pyco.len("contextKeys"); ++ii) 00057 { 00058 contextKeys.push_back(pyco.get<std::string>("contextKeys", ii)); 00059 } 00060 } 00061 00062 TimeSeriesProbeBus::~TimeSeriesProbeBus() 00063 { 00064 } 00065 00066 bool 00067 TimeSeriesProbeBus::accepts(const wns::simulator::Time&, const IContext&) 00068 { 00069 return true; 00070 } 00071 00072 void 00073 TimeSeriesProbeBus::onMeasurement(const wns::simulator::Time& _time, 00074 const double& _value, 00075 const IContext& _context) 00076 { 00077 LogEntry entry; 00078 entry.value = _value; 00079 entry.time = _time; 00080 00081 for(std::vector<std::string>::const_iterator it = contextKeys.begin(); 00082 it != contextKeys.end(); 00083 ++it) 00084 { 00085 if(_context.knows(*it)) 00086 { 00087 if(_context.isInt(*it)) 00088 { 00089 entry.context.push_back(wns::Ttos(_context.getInt(*it))); 00090 } 00091 else if(_context.isString(*it)) 00092 { 00093 entry.context.push_back(_context.getString(*it)); 00094 } 00095 } 00096 } 00097 00098 // Store value for later output 00099 logQueue.push_back(entry); 00100 } 00101 00102 void 00103 TimeSeriesProbeBus::output() 00104 { 00105 std::ofstream out((outputPath + "/" + filename).c_str(), 00106 (firstWrite ? std::ios::out : (std::ios::out | std::ios::app))); 00107 00108 if (firstWrite) 00109 { 00110 firstWrite = false; 00111 out<<prefix<<" PROBE RESULTS (THIS IS A MAGIC LINE)" << std::endl; 00112 out<<prefix<<" ---------------------------------------------------------------------------" << std::endl; 00113 out<<prefix<<" Evaluation: TimeSeries" << std::endl; 00114 out<<prefix<<" ---------------------------------------------------------------------------" << std::endl; 00115 out<<prefix<<" Name: " << name << std::endl; 00116 out<<prefix<<" Description: " << desc << std::endl; 00117 if(not contextKeys.empty()) 00118 { 00119 out<<prefix<<" ContextKeys:"; 00120 for(std::vector<std::string>::const_iterator it = contextKeys.begin(); 00121 it != contextKeys.end(); 00122 ++it) 00123 { 00124 out << " " << (*it); 00125 } 00126 out << std::endl; 00127 } 00128 out<<prefix<<" ---------------------------------------------------------------------------" << std::endl; 00129 } 00130 00131 out << (format == formatFixed ? std::setiosflags(std::ios::fixed) : std::setiosflags(std::ios::scientific)) 00132 << std::resetiosflags(std::ios::right) 00133 << std::setiosflags(std::ios::left); 00134 00135 assure(out, "I/O Error: Can't dump TimeSeriesProbeBus log file"); 00136 while (!logQueue.empty()) 00137 { 00138 LogEntry entry = logQueue.front(); 00139 logQueue.pop_front(); 00140 out << std::setprecision(timePrecision) << entry.time 00141 << " " << std::setprecision(valuePrecision) << entry.value; 00142 for(std::vector<std::string>::const_iterator it = entry.context.begin(); 00143 it != entry.context.end(); 00144 ++it) 00145 { 00146 out << " " << (*it); 00147 } 00148 out << std::endl; 00149 assure(out, "I/O Error: Can't dump TimeSeriesProbeBus log file"); 00150 } 00151 } 00152
1.5.5