RODFDetFlowLoader.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // A loader for detector flows
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 // ===========================================================================
00020 // included modules
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 // method definitions
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     // parse first line
00066     myLineHandler.reinit(lr.readLine(), ";", ";", true, true);
00067     // parse values
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 

Generated on Wed May 5 00:06:36 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6