RODFDetFlowLoader.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifdef _MSC_VER
00023 #include <windows_config.h>
00024 #else
00025 #include <config.h>
00026 #endif
00027
00028 #include <string>
00029 #include <fstream>
00030 #include <sstream>
00031 #include <utils/importio/LineReader.h>
00032 #include <utils/options/OptionsCont.h>
00033 #include <utils/common/IDSupplier.h>
00034 #include <utils/common/StringTokenizer.h>
00035 #include <utils/common/MsgHandler.h>
00036 #include <utils/common/FileHelpers.h>
00037 #include <utils/common/TplConvert.h>
00038 #include <utils/common/UtilExceptions.h>
00039 #include "RODFDetFlowLoader.h"
00040
00041 #ifdef CHECK_MEMORY_LEAKS
00042 #include <foreign/nvwa/debug_new.h>
00043 #endif // CHECK_MEMORY_LEAKS
00044
00045
00046
00047
00048
00049 RODFDetFlowLoader::RODFDetFlowLoader(const RODFDetectorCon &dets,
00050 RODFDetectorFlows &into,
00051 SUMOTime startTime, SUMOTime endTime,
00052 int timeOffset) throw()
00053 : myStorage(into), myTimeOffset(timeOffset),
00054 myStartTime(startTime/60), myEndTime((endTime+59)/60), myDetectorContainer(dets),
00055 myHaveWarnedAboutOverridingBoundaries(false) {}
00056
00057
00058
00059 RODFDetFlowLoader::~RODFDetFlowLoader() throw() {}
00060
00061
00062 void
00063 RODFDetFlowLoader::read(const std::string &file) throw(IOError, ProcessError) {
00064 LineReader lr(file);
00065
00066 myLineHandler.reinit(lr.readLine(), ";", ";", true, true);
00067
00068 while (lr.hasMore()) {
00069 std::string line = lr.readLine();
00070 if (line.find(';')==std::string::npos) {
00071 continue;
00072 }
00073 myLineHandler.parseLine(line);
00074 try {
00075 std::string detName = myLineHandler.get("detector");
00076 if (!myDetectorContainer.knows(detName)) {
00077 continue;
00078 }
00079 int time = TplConvert<char>::_2int((myLineHandler.get("time").c_str()));
00080 time -= myTimeOffset;
00081 if (time<myStartTime||time>myEndTime) {
00082 if (!myHaveWarnedAboutOverridingBoundaries) {
00083 myHaveWarnedAboutOverridingBoundaries = true;
00084 MsgHandler::getWarningInstance()->inform("At least one value lies beyond given time boundaries.");
00085 }
00086 continue;
00087 }
00088 FlowDef fd;
00089 fd.isLKW = 0;
00090 fd.qPKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("qpkw").c_str());
00091 fd.vPKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("vpkw").c_str());
00092 fd.qLKW = 0;
00093 if (myLineHandler.know("qLKW")) {
00094 fd.qLKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("qlkw").c_str());
00095 }
00096 fd.vLKW = 0;
00097 if (myLineHandler.know("vLKW")) {
00098 fd.vLKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("vlkw").c_str());
00099 }
00100 if (fd.qLKW<0) {
00101 fd.qLKW = 0;
00102 }
00103 if (fd.qPKW<0) {
00104 fd.qPKW = 0;
00105 }
00106 myStorage.addFlow(detName, time, fd);
00107 continue;
00108 } catch (UnknownElement &) {} catch (OutOfBoundsException &) {} catch (NumberFormatException &) {}
00109 throw ProcessError("The detector-flow-file '" + lr.getFileName() + "' is corrupt;\n"
00110 + " The following values must be supplied : 'Detector', 'Time', 'qPKW', 'vPKW'\n"
00111 + " The according column names must be given in the first line of the file.");
00112 }
00113 }
00114
00115
00116
00117