Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
SystemFrame.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-2026 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/****************************************************************************/
20// A set of actions common to all applications
21/****************************************************************************/
22#include <config.h>
23
24#include <string>
25#include <utils/xml/XMLSubSys.h>
33#include "SystemFrame.h"
34
35
36// ===========================================================================
37// method definitions
38// ===========================================================================
39void
41 oc.addOptionSubTopic("Configuration");
42
43 oc.doRegister("configuration-file", 'c', new Option_FileName());
44 oc.addSynonyme("configuration-file", "configuration");
45 oc.addDescription("configuration-file", "Configuration", TL("Loads the named config on startup"));
46 oc.addXMLDefault("configuration-file");
47
48 oc.doRegister("save-configuration", 'C', new Option_FileName());
49 oc.addSynonyme("save-config", "save-configuration");
50 oc.addDescription("save-configuration", "Configuration", TL("Saves current configuration into FILE"));
51
52 oc.doRegister("save-configuration.relative", new Option_Bool(false));
53 oc.addSynonyme("save-config.relative", "save-configuration.relative");
54 oc.addDescription("save-configuration.relative", "Configuration", TL("Enforce relative paths when saving the configuration"));
55
56 oc.doRegister("save-template", new Option_FileName());
57 oc.addDescription("save-template", "Configuration", TL("Saves a configuration template (empty) into FILE"));
58
59 oc.doRegister("save-schema", new Option_FileName());
60 oc.addDescription("save-schema", "Configuration", TL("Saves the configuration schema into FILE"));
61
62 oc.doRegister("save-commented", new Option_Bool(false));
63 oc.addSynonyme("save-commented", "save-template.commented");
64 oc.addDescription("save-commented", "Configuration", TL("Adds comments to saved template, configuration, or schema"));
65}
66
67
68void
70 oc.addOptionSubTopic("Report");
71
72 oc.doRegister("verbose", 'v', new Option_Bool(false));
73 oc.addDescription("verbose", "Report", TL("Switches to verbose output"));
74
75 oc.doRegister("print-options", new Option_Bool(false));
76 oc.addDescription("print-options", "Report", TL("Prints option values before processing"));
77
78 oc.doRegister("help", '?', new Option_BoolExtended(false));
79 oc.addDescription("help", "Report", TL("Prints this screen or selected topics"));
80
81 oc.doRegister("version", 'V', new Option_Bool(false));
82 oc.addDescription("version", "Report", TL("Prints the current version"));
83
84 oc.doRegister("xml-validation", 'X', new Option_String("local"));
85 oc.addDescription("xml-validation", "Report", "Set schema validation scheme of XML inputs (\"never\", \"local\", \"auto\" or \"always\")");
86
87 if (oc.exists("net-file")) {
88 oc.doRegister("xml-validation.net", new Option_String("never"));
89 oc.addDescription("xml-validation.net", "Report", "Set schema validation scheme of SUMO network inputs (\"never\", \"local\", \"auto\" or \"always\")");
90 }
91
92 if (oc.exists("route-files")) {
93 oc.doRegister("xml-validation.routes", new Option_String("local"));
94 oc.addDescription("xml-validation.routes", "Report", "Set schema validation scheme of SUMO route inputs (\"never\", \"local\", \"auto\" or \"always\")");
95 }
96
97 oc.doRegister("no-warnings", 'W', new Option_Bool(false));
98 oc.addSynonyme("no-warnings", "suppress-warnings", true);
99 oc.addDescription("no-warnings", "Report", TL("Disables output of warnings"));
100
101 oc.doRegister("aggregate-warnings", new Option_Integer(-1));
102 oc.addDescription("aggregate-warnings", "Report", TL("Aggregate warnings of the same type whenever more than INT occur"));
103
104 oc.doRegister("log", 'l', new Option_FileName());
105 oc.addSynonyme("log", "log-file");
106 oc.addDescription("log", "Report", TL("Writes all messages to FILE (implies verbose)"));
107
108 oc.doRegister("message-log", new Option_FileName());
109 oc.addDescription("message-log", "Report", TL("Writes all non-error messages to FILE (implies verbose)"));
110
111 oc.doRegister("error-log", new Option_FileName());
112 oc.addDescription("error-log", "Report", TL("Writes all warnings and errors to FILE"));
113
114 oc.doRegister("log.timestamps", new Option_Bool(false));
115 oc.addDescription("log.timestamps", "Report", TL("Writes timestamps in front of all messages"));
116
117 oc.doRegister("log.processid", new Option_Bool(false));
118 oc.addDescription("log.processid", "Report", TL("Writes process ID in front of all messages"));
119
120 oc.doRegister("language", new Option_String(gLanguage));
121 oc.addDescription("language", "Report", TL("Language to use in messages"));
122
123 oc.doRegister("write-license", new Option_Bool(false));
124 oc.addDescription("write-license", "Output", TL("Include license info into every output file"));
125
126 oc.doRegister("write-metadata", new Option_Bool(false));
127 oc.addDescription("write-metadata", "Output", TL("Write parsable metadata (configuration etc.) instead of comments"));
128
129 oc.doRegister("output-prefix", new Option_String());
130 oc.addDescription("output-prefix", "Output", TL("Prefix which is applied to all output files. The special string 'TIME' is replaced by the current time."));
131
132 oc.doRegister("output-suffix", new Option_String());
133 oc.addDescription("output-suffix", "Output", TL("Suffix which is applied to all output files. The special string 'TIME' is replaced by the current time."));
134
135 oc.doRegister("precision", new Option_Integer(2));
136 oc.addDescription("precision", "Output", TL("Defines the number of digits after the comma for floating point output"));
137
138 oc.doRegister("precision.geo", new Option_Integer(6));
139 oc.addDescription("precision.geo", "Output", TL("Defines the number of digits after the comma for lon,lat output"));
140
141 oc.doRegister("output.compression", new Option_String());
142 oc.addDescription("output.compression", "Output", TL("Defines the standard compression algorithm (currently only for parquet output)"));
143
144 oc.doRegister("output.format", new Option_String("xml"));
145 oc.addDescription("output.format", "Output", TL("Defines the standard output format if not derivable from the file name ('xml', 'csv', 'parquet')"));
146
147 oc.doRegister("output.column-header", new Option_String("auto"));
148 oc.addDescription("output.column-header", "Output", TL("How to derive column headers from attribute names ('none', 'tag', 'auto', 'plain', 'full')"));
149
150 oc.doRegister("output.column-separator", new Option_String(";"));
151 oc.addDescription("output.column-separator", "Output", TL("Separator in CSV output"));
152
153 oc.doRegister("human-readable-time", 'H', new Option_Bool(false));
154 oc.addDescription("human-readable-time", "Output", TL("Write time values as hour:minute:second or day:hour:minute:second rather than seconds"));
155}
156
157
158bool
160 gPrecision = oc.getInt("precision");
161 if (oc.exists("emission-output.precision")) {
162 gPrecisionEmissions = oc.getInt("emission-output.precision");
163 }
164 gPrecisionGeo = oc.getInt("precision.geo");
165 gHumanReadableTime = oc.getBool("human-readable-time");
166 if (oc.exists("weights.random-factor")) {
167 gWeightsRandomFactor = oc.getFloat("weights.random-factor");
168 }
169 if (oc.exists("persontrip.walk-opposite-factor")) {
170 gWeightsWalkOppositeFactor = oc.getFloat("persontrip.walk-opposite-factor");
171 }
172 if (oc.exists("xml-validation.routes") && oc.isDefault("xml-validation.routes") && !oc.isDefault("xml-validation")) {
173 oc.setDefault("xml-validation.routes", oc.getString("xml-validation"));
174 }
175 if ((oc.exists("ignore-errors") && oc.getBool("ignore-errors")) || gSimulation) {
177 }
178 std::cout << std::setprecision(gPrecision);
179 return true;
180}
181
182
183void
186 settings.format = oc.exists("output.format") ? oc.getString("output.format") : "";
187 settings.prefix = oc.exists("output-prefix") && oc.isSet("output-prefix") ? oc.getString("output-prefix") : "";
188 settings.suffix = oc.exists("output-suffix") && oc.isSet("output-suffix") ? oc.getString("output-suffix") : "";
189 if (oc.exists("output.column-header")) {
190 settings.columnHeader = oc.getString("output.column-header");
191 }
192 if (oc.exists("output.column-separator")) {
193 settings.columnSeparator = oc.getString("output.column-separator");
194 }
195 settings.compression = oc.exists("output.compression") ? oc.getString("output.compression") : "";
196 settings.loadTime = OptionsIO::getLoadTime();
197 std::function<void(std::ostream&)> metadataWriter;
198 if (oc.exists("write-metadata") && oc.getBool("write-metadata")) {
199 metadataWriter = [](std::ostream & into) {
201 into << " <metadata created_at=\"" << StringUtils::isoTimeString() << "\" created_by=\"" << oc.getFullName() << "\">\n";
202 oc.writeConfiguration(into, true, false, false, "", false, true, " ");
203 into << " </metadata>\n";
204 };
205 }
206 PlainXMLFormatter::setHeaderWriters([](std::ostream & into, bool includeConfig) {
207 OptionsCont::getOptions().writeXMLHeader(into, includeConfig);
208 }, metadataWriter);
209}
210
211
212void
215 // initialize console properly
216 OutputDevice::getDevice("stdout");
217 OutputDevice::getDevice("stderr");
221 if (oc.getBool("no-warnings")) {
223 }
224 // build the logger if possible
225 if (oc.isSet("log", false)) {
226 OutputDevice* logFile = &OutputDevice::getDevice(oc.getString("log"));
228 if (!oc.getBool("no-warnings")) {
230 }
232 if (oc.getBool("log.timestamps")) {
234 }
235 if (oc.getBool("log.processid")) {
237 }
238 }
239 if (oc.isSet("message-log", false)) {
240 OutputDevice* logFile = &OutputDevice::getDevice(oc.getString("message-log"));
242 }
243 if (oc.isSet("error-log", false)) {
244 OutputDevice* logFile = &OutputDevice::getDevice(oc.getString("error-log"));
247 }
248 if (oc.getBool("verbose")) {
249 MsgHandler::getErrorInstance()->addInitialMessage("Repeating initial error messages:");
250 } else {
252 }
253}
254
255
256void
258 // flush aggregated warnings
260 // close all output devices
262 // close the xml-subsystem
264 // delete build program options
266 // delete messages
268}
269
270
271void
273 // registers random number options
274 oc.addOptionSubTopic("Random Number");
275
276 oc.doRegister("random", new Option_Bool(false));
277 oc.addSynonyme("random", "abs-rand", true);
278 oc.addDescription("random", "Random Number", TL("Initialises the random number generator with the current system time"));
279
280 oc.doRegister("seed", new Option_Integer(23423));
281 oc.addSynonyme("seed", "srand", true);
282 oc.addDescription("seed", "Random Number", TL("Initialises the random number generator with the given value"));
283}
284
285
286void
289 RandHelper::initRand(which, oc.getBool("random"), oc.getInt("seed"));
290}
291
292
293/****************************************************************************/
#define TL(string)
Definition MsgHandler.h:316
int gPrecisionEmissions
Definition StdDefs.cpp:28
int gPrecision
the precision for floating point outputs
Definition StdDefs.cpp:27
double gWeightsRandomFactor
Definition StdDefs.cpp:35
double gWeightsWalkOppositeFactor
Definition StdDefs.cpp:36
std::string gLanguage
the language for GUI elements and messages
Definition StdDefs.cpp:39
bool gSimulation
Definition StdDefs.cpp:32
bool gHumanReadableTime
Definition StdDefs.cpp:31
bool gIgnoreUnknownVClass
Definition StdDefs.cpp:33
int gPrecisionGeo
Definition StdDefs.cpp:29
virtual void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
static void setWriteTimestamps(bool enable)
enable/disable timestamps in log output
Definition MsgHandler.h:105
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
virtual void clear(bool resetInformed=true)
Clears information whether an error occurred previously and print aggregated message summary.
void setAggregationThreshold(const int thresh)
Definition MsgHandler.h:176
void addInitialMessage(const std::string &msg)
add a message which is repeated at the end if errors occurred
Definition MsgHandler.h:115
static void setWriteProcessId(bool enable)
enable/disable process id in log output
Definition MsgHandler.h:110
static void cleanupOnEnd()
Removes pending handler.
virtual void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
A storage for options typed value containers)
Definition OptionsCont.h:92
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void writeConfiguration(std::ostream &os, const bool filled, const bool complete, const bool addComments, const std::string &relativeTo="", const bool forceRelative=false, const bool inComment=false, const std::string &indent="") const
Writes the configuration.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void writeXMLHeader(std::ostream &os, const bool includeConfig=true) const
Writes a standard XML header, including the configuration.
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
bool setDefault(const std::string &name, const std::string &value)
Sets the given value for the named option as new default value.
void doRegister(const std::string &name, Option *o)
Adds an option under the given name.
bool exists(const std::string &name) const
Returns the information whether the named option is known.
const std::string & getFullName() const
get options full name
void clear()
Removes all information from the container.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void addXMLDefault(const std::string &name, const std::string &xmlRoot="")
Adds an XML root element to handle by default. The special root "" denotes the default handler.
static OptionsCont & getOptions()
Retrieves the options.
static const std::chrono::time_point< std::chrono::system_clock > & getLoadTime()
Return the time stamp of the last init.
Definition OptionsIO.h:101
Static storage of an output device and its base (abstract) implementation.
static Settings mySettings
the output related option values, set by SystemFrame so that this class does not depend on the option...
static void closeAll(bool keepErrorRetrievers=false)
static OutputDevice & getDevice(const std::string &name, bool usePrefix=true)
Returns the described OutputDevice.
static void setHeaderWriters(std::function< void(std::ostream &, bool)> headerWriter, std::function< void(std::ostream &)> metadataWriter)
Sets the functions which write the file header and the metadata block.
static void initRand(SumoRNG *which=nullptr, const bool random=false, const int seed=23423)
Initialises the random number generator with hardware randomness or seed.
static std::string isoTimeString(const std::chrono::time_point< std::chrono::system_clock > *const timeRef=nullptr)
Returns an ISO8601 formatted time string with microsecond precision.
static void close()
Closes all of an applications subsystems.
static bool checkOptions(OptionsCont &oc)
checks shared options and sets StdDefs
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
static void insertRandOptions(OptionsCont &oc)
Initialises the given options container with random number options.
static void updateOutputSettings(const OptionsCont &oc)
hands the output related option values and the XML header writers over to the output devices
static void initOutputOptions()
init message output (console and log files) according to the options
static void close()
Closes the xml-subsystem.
values of the output related options, handed over by SystemFrame so that this class does not depend o...
std::string suffix
the suffix to append to all output file names
std::string prefix
the prefix to prepend to all output file names
std::string columnHeader
how to derive column headers (CSV and Parquet)
std::string columnSeparator
the separator for CSV output
std::string compression
the compression algorithm for Parquet output
std::chrono::time_point< std::chrono::system_clock > loadTime
the time the configuration was loaded, used to replace TIME in prefix, suffix and file names
std::string format
the default output format ("xml", "csv" or "parquet")