SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RODFDetFlowLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // A loader for detector flows
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include <fstream>
34 #include <sstream>
43 #include "RODFDetFlowLoader.h"
44 
45 #ifdef CHECK_MEMORY_LEAKS
46 #include <foreign/nvwa/debug_new.h>
47 #endif // CHECK_MEMORY_LEAKS
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
54  RODFDetectorFlows& into,
55  SUMOTime startTime, SUMOTime endTime,
56  SUMOTime timeOffset, SUMOTime timeScale)
57  : myStorage(into), myTimeOffset(timeOffset), myTimeScale(timeScale),
58  myStartTime(startTime), myEndTime(endTime), myDetectorContainer(dets),
59  myHaveWarnedAboutOverridingBoundaries(false), myHaveWarnedAboutPartialDefs(false) {}
60 
61 
62 
64 
65 
66 void
67 RODFDetFlowLoader::read(const std::string& file) throw(IOError, ProcessError) {
68  LineReader lr(file);
69  // parse first line
70  myLineHandler.reinit(lr.readLine(), ";", ";", true, true);
71  // parse values
72  while (lr.hasMore()) {
73  std::string line = lr.readLine();
74  if (line.find(';') == std::string::npos) {
75  continue;
76  }
77  myLineHandler.parseLine(line);
78  try {
79  std::string detName = myLineHandler.get("detector");
80  if (!myDetectorContainer.knows(detName)) {
81  continue;
82  }
83  const SUMOTime time = TplConvert<char>::_2int((myLineHandler.get("time").c_str())) * myTimeScale - myTimeOffset;
84  if (time < myStartTime || time > myEndTime) {
85  if (!myHaveWarnedAboutOverridingBoundaries) {
86  myHaveWarnedAboutOverridingBoundaries = true;
87  WRITE_WARNING("At least one value lies beyond given time boundaries.");
88  }
89  continue;
90  }
91  FlowDef fd;
92  fd.isLKW = 0;
93  fd.qPKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("qpkw").c_str());
94  fd.vPKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("vpkw").c_str());
95  fd.qLKW = 0;
96  if (myLineHandler.know("qLKW")) {
97  fd.qLKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("qlkw").c_str());
98  }
99  fd.vLKW = 0;
100  if (myLineHandler.know("vLKW")) {
101  fd.vLKW = TplConvert<char>::_2SUMOReal(myLineHandler.get("vlkw").c_str());
102  }
103  if (fd.qLKW < 0) {
104  fd.qLKW = 0;
105  }
106  if (fd.qPKW < 0) {
107  fd.qPKW = 0;
108  }
109  myStorage.addFlow(detName, time, fd);
110  if (!myHaveWarnedAboutPartialDefs && !myLineHandler.hasFullDefinition()) {
111  myHaveWarnedAboutPartialDefs = true;
112  WRITE_WARNING("At least one line does not contain the correct number of columns.");
113  }
114  continue;
115  } catch (UnknownElement&) {} catch (OutOfBoundsException&) {} catch (NumberFormatException&) {}
116  throw ProcessError("The detector-flow-file '" + lr.getFileName() + "' is corrupt;\n"
117  + " The following values must be supplied : 'Detector', 'Time', 'qPKW', 'vPKW'\n"
118  + " The according column names must be given in the first line of the file.");
119  }
120 }
121 
122 
123 /****************************************************************************/
124