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-2025 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),
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 }
65 myLineHandler.parseLine(line);
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;
82 fd.qPKW = StringUtils::toDouble(myLineHandler.get("qpkw"));
83 fd.vPKW = 0;
84 if (myLineHandler.know("vPKW")) {
85 fd.vPKW = StringUtils::toDouble(myLineHandler.get("vpkw"));
86 }
87 fd.qLKW = 0;
88 if (myLineHandler.know("qLKW")) {
89 fd.qLKW = StringUtils::toDouble(myLineHandler.get("qlkw"));
90 }
91 fd.vLKW = 0;
92 if (myLineHandler.know("vLKW")) {
93 fd.vLKW = StringUtils::toDouble(myLineHandler.get("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);
102 if (!myHaveWarnedAboutPartialDefs && !myLineHandler.hasFullDefinition()) {
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:286
#define TL(string)
Definition MsgHandler.h:304
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.
const SUMOTime myStartTime
The first and the last time step to read.
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.
A container for flows.
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.