MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / run

Method run

src/workflow/OSWorkflow.cpp:274–550  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274bool OSWorkflow::run() {
275
276 // If the user passed something like `openstudio --loglevel Trace run --debug -w workflow.osw`, we retain the Trace
277 LogLevel oriLogLevel = openstudio::Logger::instance().standardOutLogger().logLevel().value_or(Warn);
278 LogLevel targetLogLevel = workflowJSON.runOptions()->debug() ? Debug : oriLogLevel;
279
280 openstudio::Logger::instance().addTimeStampToLogger(); // Needed for run.log formatting
281 openstudio::Logger::instance().standardOutLogger().setFormatter(&standardFormatterWithStringSeverity);
282
283 // TODO: ideally we want stdErr logger to always receive Error and Fatal
284 // and stdOut logger should receive all the others. This is definitely doable (cf LogSink::updateFilter) but now is not the time.
285 if (!m_show_stdout) {
286 openstudio::Logger::instance().standardOutLogger().setLogLevel(Error); // Still show errors
287 } else {
288 openstudio::Logger::instance().standardOutLogger().setLogLevel(targetLogLevel);
289 }
290
291 // Need to recreate the runDir as fast as possible, so I can direct a file log sink there
292 bool hasDeletedRunDir = false;
293 auto runDirPath = workflowJSON.absoluteRunDir();
294
295 if (runDirPath == workflowJSON.oswDir()) {
296 workflowJSON.runOptions()->setPreserveRunDir(true);
297 }
298
299 if (!workflowJSON.runOptions()->preserveRunDir() && !m_post_process_only) {
300 // We don't have a run_dir argument anyways
301 if (openstudio::filesystem::is_directory(runDirPath)) {
302 hasDeletedRunDir = true;
303 openstudio::filesystem::remove_all(runDirPath);
304 }
305 }
306 if (!openstudio::filesystem::is_directory(runDirPath)) {
307 openstudio::filesystem::create_directories(runDirPath);
308 }
309
310 FileLogSink logFile(runDirPath / "run.log");
311 constexpr bool use_workflow_gem_fmt = true;
312 constexpr bool include_channel = true; // or workflowJSON.runOptions()->debug();
313 logFile.useWorkflowGemFormatter(use_workflow_gem_fmt, include_channel);
314 logFile.setLogLevel(targetLogLevel);
315
316 if (hasDeletedRunDir) {
317 LOG(Debug, "Removing existing run directory: " << runDirPath);
318 }
319
320 // Communicate that the workflow has been started
321 LOG(Debug, "Registering that the workflow has started with the adapter");
322 {
323 // @output_adapter.communicate_started
324 openstudio::filesystem::ofstream file(runDirPath / "started.job");
325 OS_ASSERT(file.is_open());
326 file << fmt::format("Started Workflow {}\n", std::chrono::system_clock::now());
327 file.close();
328 }
329
330 // bool no_simulation = false;
331 // bool post_process = false;

Callers 8

setupRunOptionsFunction · 0.45
run_fileFunction · 0.45
run_workflowFunction · 0.45
mainFunction · 0.45
applyMeasuresMethod · 0.45
iFunction · 0.45
XbFunction · 0.45

Calls 15

standardOutLoggerMethod · 0.80
debugMethod · 0.80
runOptionsMethod · 0.80
addTimeStampToLoggerMethod · 0.80
setFormatterMethod · 0.80
setLogLevelMethod · 0.80
absoluteRunDirMethod · 0.80
oswDirMethod · 0.80
setPreserveRunDirMethod · 0.80
preserveRunDirMethod · 0.80
tockCurrentTimerMethod · 0.80

Tested by 1

run_fileFunction · 0.36