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::_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::_2SUMOReal(myLineHandler.get("qpkw").c_str());
94  fd.vPKW = 0;
95  if (myLineHandler.know("vPKW")) {
96  fd.vPKW = TplConvert::_2SUMOReal(myLineHandler.get("vpkw").c_str());
97  }
98  fd.qLKW = 0;
99  if (myLineHandler.know("qLKW")) {
100  fd.qLKW = TplConvert::_2SUMOReal(myLineHandler.get("qlkw").c_str());
101  }
102  fd.vLKW = 0;
103  if (myLineHandler.know("vLKW")) {
104  fd.vLKW = TplConvert::_2SUMOReal(myLineHandler.get("vlkw").c_str());
105  }
106  if (fd.qLKW < 0) {
107  fd.qLKW = 0;
108  }
109  if (fd.qPKW < 0) {
110  fd.qPKW = 0;
111  }
112  myStorage.addFlow(detName, time, fd);
113  if (!myHaveWarnedAboutPartialDefs && !myLineHandler.hasFullDefinition()) {
114  myHaveWarnedAboutPartialDefs = true;
115  WRITE_WARNING("At least one line does not contain the correct number of columns.");
116  }
117  continue;
118  } catch (UnknownElement&) {} catch (OutOfBoundsException&) {} catch (NumberFormatException&) {}
119  throw ProcessError("The detector-flow-file '" + lr.getFileName() + "' is corrupt;\n"
120  + " The following values must be supplied : 'Detector', 'Time', 'qPKW'\n"
121  + " The according column names must be given in the first line of the file.");
122  }
123 }
124 
125 
126 /****************************************************************************/
127