Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
RODFDetFlowLoader.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// A loader for detector flows
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// ===========================================================================
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
54void
55RODFDetFlowLoader::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 SUMOTime time = (SUMOTime)(StringUtils::toDouble(myLineHandler.get("time")) * (double)myTimeScale + .5) - myTimeOffset;
72 // parsing as float to handle values which would cause int overflow
73 if (time < myStartTime || time >= myEndTime) {
76 WRITE_WARNING(TL("At least one value lies beyond given time boundaries."));
77 }
78 continue;
79 }
80 FlowDef fd;
81 fd.isLKW = 0;
83 fd.vPKW = 0;
84 if (myLineHandler.know("vPKW")) {
86 }
87 fd.qLKW = 0;
88 if (myLineHandler.know("qLKW")) {
90 }
91 fd.vLKW = 0;
92 if (myLineHandler.know("vLKW")) {
94 }
95 if (fd.qLKW < 0) {
96 fd.qLKW = 0;
97 }
98 if (fd.qPKW < 0) {
99 fd.qPKW = 0;
100 }
101 myStorage.addFlow(detName, time, fd);
104 WRITE_WARNING(TL("At least one line does not contain the correct number of columns."));
105 }
106 continue;
107 } catch (ProcessError& e) {
108 throw ProcessError(toString(e.what()) + " in '" + lr.getFileName() + "', line " + toString(lr.getLineNumber()) + ";\n"
109 + " The following values must be supplied : 'Detector', 'Time', 'qPKW'\n"
110 + " The according column names must be given in the first line of the file.");
111 }
112 }
113}
114
115
116/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
#define WRITE_WARNING(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:315
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
Retrieves a file linewise and reports the lines to a handler.
Definition LineReader.h:48
bool readLine(LineHandler &lh)
Reads a single (the next) line from the file and reports it to the given LineHandler.
int getLineNumber()
Definition LineReader.h:143
bool hasMore() const
Returns whether another line may be read (the file was not read completely)
std::string getFileName() const
Returns the name of the used file.
bool hasFullDefinition() const
Returns whether the number of named columns matches the actual number.
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.
void parseLine(const std::string &line)
Parses the contents of the line.
std::string get(const std::string &name, bool prune=false) const
Returns the named information.
const SUMOTime myTimeOffset
The time offset to apply to read time values.
RODFDetFlowLoader(const RODFDetectorCon &dets, RODFDetectorFlows &into, SUMOTime startTime, SUMOTime endTime, SUMOTime timeOffset, SUMOTime timeScale)
Constructor.
RODFDetectorFlows & myStorage
The container for read detector values.
const SUMOTime myTimeScale
The time scale to apply to read time values.
const SUMOTime myEndTime
NamedColumnsParser myLineHandler
The value extractor.
bool myHaveWarnedAboutPartialDefs
Whether a warning about partial definitions was already written.
const RODFDetectorCon & myDetectorContainer
Container holding known detectors.
void read(const std::string &file)
Reads the given file assuming it contains detector values.
~RODFDetFlowLoader()
Destructor.
bool myHaveWarnedAboutOverridingBoundaries
Whether a warning about overriding boundaries was already written.
A container for RODFDetectors.
bool knows(const std::string &id) const
A container for flows.
void addFlow(const std::string &detector_id, SUMOTime timestamp, const FlowDef &fd)
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
static double fd[10]
Definition odrSpiral.cpp:99
Definition of the traffic during a certain time containing the flows and speeds.