SUMO - Simulation of Urban MObility
RODFDetFlowLoader.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // A loader for detector flows
19 /****************************************************************************/
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <config.h>
24 
25 #include <string>
26 #include <fstream>
27 #include <sstream>
35 #include "RODFDetFlowLoader.h"
36 
37 
38 // ===========================================================================
39 // method definitions
40 // ===========================================================================
42  RODFDetectorFlows& into,
43  SUMOTime startTime, SUMOTime endTime,
44  SUMOTime timeOffset, SUMOTime timeScale)
45  : myStorage(into), myTimeOffset(timeOffset), myTimeScale(timeScale),
46  myStartTime(startTime), myEndTime(endTime), myDetectorContainer(dets),
47  myHaveWarnedAboutOverridingBoundaries(false), myHaveWarnedAboutPartialDefs(false) {}
48 
49 
50 
52 
53 
54 void
55 RODFDetFlowLoader::read(const std::string& file) {
56  LineReader lr(file);
57  // parse first line
58  myLineHandler.reinit(lr.readLine(), ";", ";", true, true);
59  // parse values
60  while (lr.hasMore()) {
61  std::string line = lr.readLine();
62  if (line.find(';') == std::string::npos) {
63  continue;
64  }
66  try {
67  std::string detName = myLineHandler.get("detector");
68  if (!myDetectorContainer.knows(detName)) {
69  continue;
70  }
71  const double parsedTime = StringUtils::toDouble((myLineHandler.get("time"))) * myTimeScale - myTimeOffset;
72  // parsing as float to handle values which would cause int overflow
73  if (parsedTime < myStartTime || parsedTime >= myEndTime) {
76  WRITE_WARNING("At least one value lies beyond given time boundaries.");
77  }
78  continue;
79  }
80  const SUMOTime time = (SUMOTime)(parsedTime + .5);
81  FlowDef fd;
82  fd.isLKW = 0;
84  fd.vPKW = 0;
85  if (myLineHandler.know("vPKW")) {
87  }
88  fd.qLKW = 0;
89  if (myLineHandler.know("qLKW")) {
91  }
92  fd.vLKW = 0;
93  if (myLineHandler.know("vLKW")) {
95  }
96  if (fd.qLKW < 0) {
97  fd.qLKW = 0;
98  }
99  if (fd.qPKW < 0) {
100  fd.qPKW = 0;
101  }
102  myStorage.addFlow(detName, time, fd);
105  WRITE_WARNING("At least one line does not contain the correct number of columns.");
106  }
107  continue;
108  } catch (UnknownElement&) {} catch (OutOfBoundsException&) {} catch (NumberFormatException&) {}
109  throw ProcessError("The detector-flow-file '" + lr.getFileName() + "' is corrupt;\n"
110  + " The following values must be supplied : 'Detector', 'Time', 'qPKW'\n"
111  + " The according column names must be given in the first line of the file.");
112  }
113 }
114 
115 
116 /****************************************************************************/
117 
bool myHaveWarnedAboutOverridingBoundaries
Whether a warning about overriding boundaries was already written.
const SUMOTime myTimeOffset
The time offset to apply to read time values.
long long int SUMOTime
Definition: SUMOTime.h:36
bool readLine(LineHandler &lh)
Reads a single (the next) line from the file and reports it to the given LineHandler.
Definition: LineReader.cpp:69
std::string getFileName() const
Returns the name of the used file.
Definition: LineReader.cpp:172
Retrieves a file linewise and reports the lines to a handler.
Definition: LineReader.h:51
const SUMOTime myEndTime
bool hasFullDefinition() const
Returns whether the number of named columns matches the actual number.
const RODFDetectorCon & myDetectorContainer
Container holding known detectors.
static double fd[10]
Definition: odrSpiral.cpp:94
std::string get(const std::string &name, bool prune=false) const
Returns the named information.
RODFDetFlowLoader(const RODFDetectorCon &dets, RODFDetectorFlows &into, SUMOTime startTime, SUMOTime endTime, SUMOTime timeOffset, SUMOTime timeScale)
Constructor.
A container for flows.
A container for RODFDetectors.
Definition: RODFDetector.h:221
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
double vPKW
RODFDetectorFlows & myStorage
The container for read detector values.
void reinit(const std::string &def, const std::string &defDelim=";", const std::string &lineDelim=";", bool chomp=false, bool ignoreCase=true)
Reinitialises the parser.
bool know(const std::string &name) const
Returns the information whether the named column is known.
double vLKW
bool knows(const std::string &id) const
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
void read(const std::string &file)
Reads the given file assuming it contains detector values.
Definition of the traffic during a certain time containing the flows and speeds.
double qPKW
const SUMOTime myTimeScale
The time scale to apply to read time values.
bool myHaveWarnedAboutPartialDefs
Whether a warning about partial definitions was already written.
void addFlow(const std::string &detector_id, SUMOTime timestamp, const FlowDef &fd)
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
Definition: LineReader.cpp:53
NamedColumnsParser myLineHandler
The value extractor.
double isLKW
double qLKW
~RODFDetFlowLoader()
Destructor.
void parseLine(const std::string &line)
Parses the contents of the line.