diff --git a/sources/Common/CMakeLists.txt b/sources/Common/CMakeLists.txt index ef8caacd..ac42e45c 100644 --- a/sources/Common/CMakeLists.txt +++ b/sources/Common/CMakeLists.txt @@ -53,6 +53,7 @@ target_link_libraries(dfl_Common PRIVATE Boost::filesystem + libZIP::libZIP ) add_library(DynaFlowLauncher::common ALIAS dfl_Common) install(FILES ${CMAKE_SOURCE_DIR}/etc/Dictionaries/DFLLog_en_GB.dic ${CMAKE_SOURCE_DIR}/etc/Dictionaries/DFLError_en_GB.dic DESTINATION share) diff --git a/sources/Common/include/Options.h b/sources/Common/include/Options.h index b1017457..1cec4dee 100644 --- a/sources/Common/include/Options.h +++ b/sources/Common/include/Options.h @@ -9,7 +9,6 @@ #pragma once -#include #include #include #include @@ -43,6 +42,7 @@ class Options { std::string networkFilePath; ///< Network filepath to process std::string contingenciesFilePath; ///< Contingencies filepath for security analysis std::string configPath; ///< Launcher configuration filepath + std::string zipArchivePath; ///< zip archive path to unzip to get input files std::string dynawoLogLevel; ///< chosen log level }; diff --git a/sources/Common/src/Options.cpp b/sources/Common/src/Options.cpp index fea954ad..19038a34 100644 --- a/sources/Common/src/Options.cpp +++ b/sources/Common/src/Options.cpp @@ -16,6 +16,10 @@ #include "version.h" +#include + +#include + #include #include #include @@ -81,14 +85,18 @@ Options::basename(const std::string& filepath) { return path.filename().replace_extension().generic_string(); } -Options::Options() : desc_{}, config_{"", "", "", "", defaultLogLevel_} { - desc_.add_options()("help,h", "Display help message")( - "log-level", po::value(), - (std::string("Dynawo logger level (allowed values are ERROR, WARN, INFO, DEBUG): default is ") + defaultLogLevel_).c_str())( - "network", po::value(&config_.networkFilePath)->required(), "Network file path to process (IIDM support only)")( - "contingencies", po::value(&config_.contingenciesFilePath), "Contingencies file path to process (Security Analysis)")( - "config", po::value(&config_.configPath)->required(), "launcher Configuration file to use")("version,v", "Display version")( - "nsa", "Run steady state calculation followed by security analysis. Requires contingencies file to be defined."); +Options::Options() : desc_{}, config_{"", "", "", "", "", defaultLogLevel_} { + desc_.add_options() + ("help,h", "Display help message") + ("version,v", "Display version") + ("log-level", po::value(), + (std::string("Dynawo logger level (allowed values are ERROR, WARN, INFO, DEBUG): default is ") + defaultLogLevel_).c_str()) + ("network", po::value(&config_.networkFilePath)->required(), "Network file path to process (IIDM support only)") + ("config", po::value(&config_.configPath)->required(), "launcher Configuration file to use") + ("contingencies", po::value(&config_.contingenciesFilePath), "Contingencies file path to process (Security Analysis)") + ("nsa", "Run steady state calculation followed by security analysis. Requires contingencies file to be defined.") + ("input-archive", po::value(&config_.zipArchivePath), + "Path to a ZIP archive containing input files for '--network', '--config', and '--contingencies'."); } Options::Request @@ -108,6 +116,21 @@ Options::parse(int argc, char* argv[]) { po::notify(vm); + if (vm.count("input-archive") > 0) { + boost::shared_ptr archive = zip::ZipInputStream::read(config_.zipArchivePath); + std::string archiveParentPath = boost::filesystem::path(config_.zipArchivePath).parent_path().string(); + for (std::map>::const_iterator archiveIt = archive->getEntries().begin(); + archiveIt != archive->getEntries().end(); ++archiveIt) { + std::string name = archiveIt->first; + std::string data(archiveIt->second->getData()); + std::ofstream file; + std::string filepath = createAbsolutePath(name, archiveParentPath); + file.open(createAbsolutePath(name, archiveParentPath).c_str(), std::ios::binary); + file << data; + file.close(); + } + } + // These are not binded automatically if (vm.count("log-level") > 0) { config_.dynawoLogLevel = vm["log-level"].as().logLevelDefinition; diff --git a/sources/Context.cpp b/sources/Context.cpp index e220ab47..6bb75c37 100644 --- a/sources/Context.cpp +++ b/sources/Context.cpp @@ -350,7 +350,11 @@ void Context::executeSecurityAnalysis() { multipleJobs->setScenarios(scenarios); auto saLauncher = boost::make_shared(); saLauncher->setMultipleJobs(multipleJobs); - saLauncher->setOutputFile("aggregatedResults.xml"); + if (def_.outputIsZip) { + saLauncher->setOutputFile("output.zip"); + } else { + saLauncher->setOutputFile("aggregatedResults.xml"); + } saLauncher->setDirectory(config_.outputDir().generic_string()); saLauncher->init(); saLauncher->launch(); diff --git a/sources/Context.h b/sources/Context.h index a1883970..b426d4a3 100644 --- a/sources/Context.h +++ b/sources/Context.h @@ -63,6 +63,7 @@ class Context { boost::filesystem::path settingFilePath; ///< setting file path for dynamic data base boost::filesystem::path assemblingFilePath; ///< assembling file path for dynamic data base boost::filesystem::path contingenciesFilePath; ///< contigencies file path for Security Analysis simulation + bool outputIsZip; ///< true if the output is zip archive, false otherwise std::string dynawoLogLevel; ///< string representation of the dynawo log level boost::filesystem::path dynawoResDir; ///< DYNAWO resources std::string locale; ///< localization diff --git a/sources/main.cpp b/sources/main.cpp index b6544921..68a46a38 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -53,12 +53,14 @@ static inline double elapsed(const std::chrono::steady_clock::time_point &timePo static boost::shared_ptr buildContext(dfl::inputs::SimulationParams const ¶ms, dfl::inputs::Configuration &config) { auto timeContextStart = std::chrono::steady_clock::now(); + bool outputIsZip = !params.runtimeConfig->zipArchivePath.empty(); dfl::Context::ContextDef def{config.getStartingPointMode(), params.simulationKind, params.networkFilePath, config.settingFilePath(), config.assemblingFilePath(), params.runtimeConfig->contingenciesFilePath, + outputIsZip, params.runtimeConfig->dynawoLogLevel, params.resourcesDirPath, params.locale};