From 8251ad11522232a1cc8b6f2909a746d5cb022796 Mon Sep 17 00:00:00 2001 From: Sondre Sortland Date: Thu, 9 Jan 2020 13:54:03 +0100 Subject: [PATCH] Allow HOOK_WORKFLOW in site-config --- lib/enkf/hook_manager.cpp | 43 +++++++++++++++++----------- lib/enkf/site_config.cpp | 14 +++++++++ lib/include/ert/enkf/config_keys.hpp | 4 +++ 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/lib/enkf/hook_manager.cpp b/lib/enkf/hook_manager.cpp index 28112801f0..2314defb07 100644 --- a/lib/enkf/hook_manager.cpp +++ b/lib/enkf/hook_manager.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -35,10 +36,6 @@ #define HOOK_MANAGER_NAME "HOOK MANAGER" #define QC_WORKFLOW_NAME "QC WORKFLOW" -#define RUN_MODE_PRE_SIMULATION_NAME "PRE_SIMULATION" -#define RUN_MODE_POST_SIMULATION_NAME "POST_SIMULATION" -#define RUN_MODE_PRE_UPDATE_NAME "PRE_UPDATE" -#define RUN_MODE_POST_UPDATE_NAME "POST_UPDATE" struct hook_manager_struct { vector_type * hook_workflow_list; /* vector of hook_workflow_type instances */ @@ -52,18 +49,6 @@ struct hook_manager_struct { }; -hook_manager_type * hook_manager_alloc_default(ert_workflow_list_type * workflow_list) { - hook_manager_type * hook_manager = (hook_manager_type *)util_malloc( sizeof * hook_manager ); - hook_manager->hook_workflow_list = vector_alloc_new(); - - hook_manager->workflow_list = workflow_list; - - hook_manager->runpath_list = NULL; - - hook_manager->input_context = hash_alloc(); - - return hook_manager; -} hook_manager_type * hook_manager_alloc( @@ -104,6 +89,32 @@ static void hook_manager_add_workflow( hook_manager_type * hook_manager , const } } +hook_manager_type * hook_manager_alloc_default(ert_workflow_list_type * workflow_list) { + hook_manager_type * hook_manager = (hook_manager_type *)util_malloc( sizeof * hook_manager ); + hook_manager->workflow_list = workflow_list; + + hook_manager->hook_workflow_list = vector_alloc_new(); + + config_parser_type * config = config_alloc(); + config_content_type * site_config_content = site_config_alloc_content(config); + + if (config_content_has_item( site_config_content , HOOK_WORKFLOW_KEY)) { + for (int ihook = 0; ihook < config_content_get_occurences(site_config_content , HOOK_WORKFLOW_KEY); ihook++) { + const char * workflow_name = config_content_iget( site_config_content , HOOK_WORKFLOW_KEY, ihook , 0 ); + hook_run_mode_enum run_mode = hook_workflow_run_mode_from_name(config_content_iget(site_config_content , HOOK_WORKFLOW_KEY , ihook , 1)); + hook_manager_add_workflow( hook_manager , workflow_name , run_mode ); + } + } + config_free(config); + config_content_free(site_config_content); + + hook_manager->runpath_list = NULL; + + hook_manager->input_context = hash_alloc(); + + return hook_manager; +} + hook_manager_type * hook_manager_alloc_full( ert_workflow_list_type * workflow_list, const char * workflow_file, diff --git a/lib/enkf/site_config.cpp b/lib/enkf/site_config.cpp index 033e00b0c7..771dda8b49 100644 --- a/lib/enkf/site_config.cpp +++ b/lib/enkf/site_config.cpp @@ -462,6 +462,20 @@ void site_config_add_config_items(config_parser_type * config, bool site_mode) { item = config_add_schema_item( config , ANALYSIS_LOAD_KEY , false ); config_schema_item_set_argc_minmax( item , 2 , 2); + + item = config_add_schema_item( config , HOOK_WORKFLOW_KEY , false ); + config_schema_item_set_argc_minmax(item , 2 , 2 ); + config_schema_item_iset_type( item , 0 , CONFIG_STRING ); + config_schema_item_iset_type( item , 1 , CONFIG_STRING ); + { + stringlist_type * argv = stringlist_alloc_new(); + stringlist_append_copy(argv, RUN_MODE_PRE_SIMULATION_NAME); + stringlist_append_copy(argv, RUN_MODE_POST_SIMULATION_NAME); + stringlist_append_copy(argv, RUN_MODE_PRE_UPDATE_NAME); + stringlist_append_copy(argv, RUN_MODE_POST_UPDATE_NAME); + config_schema_item_set_indexed_selection_set(item, 1, argv); + stringlist_free( argv ); + } } const char * site_config_get_config_file(const site_config_type * site_config) { diff --git a/lib/include/ert/enkf/config_keys.hpp b/lib/include/ert/enkf/config_keys.hpp index 1dc2642cb4..e50c179092 100644 --- a/lib/include/ert/enkf/config_keys.hpp +++ b/lib/include/ert/enkf/config_keys.hpp @@ -144,6 +144,10 @@ extern "C" { #define WORKFLOW_JOB_DIRECTORY_KEY "WORKFLOW_JOB_DIRECTORY" #define LOAD_WORKFLOW_KEY "LOAD_WORKFLOW" #define LOAD_WORKFLOW_JOB_KEY "LOAD_WORKFLOW_JOB" +#define RUN_MODE_PRE_SIMULATION_NAME "PRE_SIMULATION" +#define RUN_MODE_POST_SIMULATION_NAME "POST_SIMULATION" +#define RUN_MODE_PRE_UPDATE_NAME "PRE_UPDATE" +#define RUN_MODE_POST_UPDATE_NAME "POST_UPDATE" #define STOP_LONG_RUNNING_KEY "STOP_LONG_RUNNING" #define MAX_RUNTIME_KEY "MAX_RUNTIME" #define TIME_MAP_KEY "TIME_MAP"