From c39c8fb148731a8d3cde9633e760157644eba719 Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Wed, 5 Aug 2026 16:06:45 +0200 Subject: [PATCH 1/7] Import frontend from VMS This should also be used at GPS and GPD --- CMakeLists.txt | 49 ++++---- frontend/strayfield_scfe.cxx | 215 +++++++++++++++++++++-------------- 2 files changed, 156 insertions(+), 108 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79fbb3a..e691af9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ add_compile_options( option( BUILD_FRONTEND "If ON, build the default frontend executable" - OFF + ON ) set(CMAKE_PREFIX_PATH "$ENV{MIDASSYS}") @@ -68,29 +68,34 @@ target_link_libraries( ## Test Frontend ################################################################################ -if(${BUILD_FRONTEND}) +set(FRONTEND_NAME Ext_stray_field_status CACHE STRING "Overridable frontend name") - add_executable( - strayfield_fe - frontend/strayfield_scfe.cxx - ) +add_executable( + Ext_stray_field_status_scfe + frontend/strayfield_scfe.cxx +) +add_compile_definitions(Ext_stray_field_status_scfe PRIVATE FRONTEND_NAME="${FRONTEND_NAME}") - set_property( - TARGET - strayfield_fe - PROPERTY - CXX_STANDARD 11 - ) +set_property( + TARGET + Ext_stray_field_status_scfe + PROPERTY + CXX_STANDARD 11 +) - target_include_directories( - strayfield_fe - PRIVATE - $ENV{MIDASSYS}/drivers - ) +target_include_directories( + Ext_stray_field_status_scfe + PRIVATE + $ENV{MIDASSYS}/drivers +) - target_link_libraries( - strayfield_fe - strayfield - ) +target_link_libraries( + Ext_stray_field_status_scfe + strayfield +) -endif() +install( + TARGETS + Ext_stray_field_status_scfe + RUNTIME DESTINATION bin +) diff --git a/frontend/strayfield_scfe.cxx b/frontend/strayfield_scfe.cxx index ffd2b2a..0535013 100644 --- a/frontend/strayfield_scfe.cxx +++ b/frontend/strayfield_scfe.cxx @@ -1,125 +1,168 @@ -/*******************************************************************\ +/********************************************************************\ - Name: strayfield_scfe.cxx - Created by: Edward Wall - Contents: Slow Control Frontend for Strayfield Cobra and Comet Magnets + Name: Ext_stray_field_status_scfe.c + Created by: Hubertus Luetkens -\********************************************************************/ + Contents: Midas frontend to read stray field status in the Experimental hall + (Cobra, Comet,...) from Multicasts + \********************************************************************/ + +#include #include "midas.h" -#include "mfe.h" - -#include "bus/tcpip.h" +#include "bus/null.h" #include "class/multi.h" - #include "device/strayfield.h" -/******************************************************************************* - * Global Variables Required by mfe.h - ******************************************************************************/ +/*-- Globals -------------------------------------------------------*/ -//! The frontend name (client name) as seen by other MIDAS clients -const char *frontend_name = "Strayfield"; +/* The frontend name (client name) as seen by other MIDAS clients + * This is a preprocessor macro with a default values that can be overriden + * with cmake*/ +const char *frontend_name = FRONTEND_NAME; -//! The frontend file name, don't change it +/* The frontend file name, don't change it */ const char *frontend_file_name = __FILE__; -//! frontend_loop is called periodically if this variable is TRUE +/* frontend_loop is called periodically if this variable is TRUE */ BOOL frontend_call_loop = FALSE; -//! a frontend status page is displayed with this frequency in ms +/* a frontend status page is displayed with this frequency in ms */ INT display_period = 1000; -//! maximum event size produced by this frontend +/* maximum event size produced by this frontend */ INT max_event_size = 10000; -//! maximum event size for fragmented events (EQ_FRAGMENTED) -INT max_event_size_frag = 5 * 1024 * 1024; +/* maximum event size for fragmented events (EQ_FRAGMENTED) */ +INT max_event_size_frag = 5*1024*1024; -//! buffer size to hold events -INT event_buffer_size = 10 * 10000; +/* buffer size to hold events */ +INT event_buffer_size = 10*10000; -/******************************************************************************* - * Equipment List Required by mfe.h - ******************************************************************************/ - -DEVICE_DRIVER strayfield_driver[] = { - // { name, *dd, channels, *bd, flags } - {"strayfield_inp", strayfield_in, 4, tcpip, DF_INPUT}}; +extern BOOL should_exit; /*! * equipment_common_overwrite: * - * - If that flag is TRUE, then the contents of the "equipment" structure is - * copied to the ODB on each start of the front-end. + * - If that flag is TRUE, then the contents of the "equipment" structure is copied to + * the ODB on each start of the front-end. * - * - If the flag is FALSE, then the ODB values are kept on the start of the - * front-end + * - If the flag is FALSE, then the ODB values are kept on the start of the front-end */ BOOL equipment_common_overwrite = FALSE; -/******************************************************************************* - * Equipment Structure Required by mfe.h - ******************************************************************************/ +/*-- Equipment list ------------------------------------------------*/ -EQUIPMENT equipment[] = { - { - "Strayfield_Magnet", /* equipment name */ - { - 94, /* Event ID associated with equipm. */ - 0, /* Trigger mask */ - "SYSTEM", /* Event buffer to send events into */ - EQ_SLOW, /* equipment type */ - 0, /* Event source (LAM/IRQ) */ - "FIXED", /* Data format to produce */ - TRUE, /* Enable flag */ - RO_RUNNING | - RO_TRANSITIONS, /* Combination of Read-On flags RO_xxx */ - 10000, /* Readout interval/Polling time in ms */ - 0, /* Stop run when limit is reached */ - 0, /* Number of events in super event */ - 1, /* log history every event */ - "", /* Host on which FE is running */ - "", /* Frontend name */ - "" /* Source file used for user FE */ - }, - cd_multi_read, /* readout routine */ - cd_multi, /* class driver main routine */ - strayfield_driver, /* device driver list */ - NULL, /* init string */ - }, - {""}}; +/* device driver list */ -/******************************************************************************* - * Routines Required by mfe.h - * - * Can be overwritten to modify the default frontend behaviour. - ******************************************************************************/ - -INT poll_event(INT source, INT count, BOOL test) { return CM_SUCCESS; }; - -INT interrupt_configure(INT cmd, INT source, POINTER_T adr) { - return CM_SUCCESS; +DEVICE_DRIVER strayfield_driver[] = { + { "stray_field", strayfield_in, 4, null, DF_INPUT}, +//{ "null", nulldev, 1, NULL, DF_OUTPUT}, /* not necessary ?? */ + { "" } }; -INT frontend_init() { - // de-register run-transition notifications - cm_deregister_transition(TR_START); - cm_deregister_transition(TR_STOP); - cm_deregister_transition(TR_PAUSE); - cm_deregister_transition(TR_RESUME); +EQUIPMENT equipment[] = { - return CM_SUCCESS; + { "Ext_stray_field_status", /* equipment name */ + {94, 0, /* event ID, trigger mask */ + "SYSTEM", /* event buffer */ + EQ_SLOW, /* equipment type */ + 0, /* event source */ + "FIXED", /* format */ + TRUE, /* enabled */ + RO_RUNNING | + RO_TRANSITIONS, /* read when running and on transitions */ + 10000, /* read every 10 sec */ + 0, /* stop run after this event limit */ + 0, /* number of sub events */ + 1, /* log history every event */ + "", "", ""}, + cd_multi_read, /* readout routine */ + cd_multi, /* class driver main routine */ + strayfield_driver, /* device driver list */ + NULL, /* init string */ + }, + + { "" } +}; + + + +/*-- Dummy routines ------------------------------------------------*/ + +INT poll_event(INT source, INT count, BOOL test) {return 1;} +INT interrupt_configure(INT cmd, INT source, PTYPE adr) {return 1;} + +/*-- Frontend Init -------------------------------------------------*/ + +INT frontend_init() +{ +#ifdef LEM_USED + // not necessary for bulk as mfe.c is compiled with NO_RUN_TRANSITION flag + // de-register run-transition notifications + cm_deregister_transition(TR_START); + cm_deregister_transition(TR_STOP); + cm_deregister_transition(TR_PAUSE); + cm_deregister_transition(TR_RESUME); +#endif + +#ifdef FORTIFY + Fortify_CheckAllMemory(); +#endif + + return CM_SUCCESS; } -INT frontend_loop() { return CM_SUCCESS; } +/*-- Frontend Exit -------------------------------------------------*/ -INT frontend_exit() { return CM_SUCCESS; } +INT frontend_exit() +{ -INT begin_of_run(INT run_number, char *error) { return CM_SUCCESS; } +#ifdef FORTIFY + Fortify_CheckAllMemory(); + Fortify_OutputStatistics(); +#endif -INT pause_run(INT run_number, char *error) { return CM_SUCCESS; } + return CM_SUCCESS; +} -INT resume_run(INT run_number, char *error) { return CM_SUCCESS; } +/*-- Frontend Loop -------------------------------------------------*/ -INT end_of_run(INT run_number, char *error) { return CM_SUCCESS; } +#ifdef FORTIFY +static DWORD last_time_fortify = 0; +#endif + +INT frontend_loop() +{ + return CM_SUCCESS; +} + +/*-- Begin of Run --------------------------------------------------*/ + +INT begin_of_run(INT run_number, char *error) +{ + return CM_SUCCESS; +} + +/*-- End of Run ----------------------------------------------------*/ + +INT end_of_run(INT run_number, char *error) +{ + return CM_SUCCESS; +} + +/*-- Pause Run -----------------------------------------------------*/ + +INT pause_run(INT run_number, char *error) +{ + return CM_SUCCESS; +} + +/*-- Resuem Run ----------------------------------------------------*/ + +INT resume_run(INT run_number, char *error) +{ + return CM_SUCCESS; +} + +/*------------------------------------------------------------------*/ -- 2.54.0 From ea3d1c5ac352a3b96c68ddd16450591f273afcbf Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Thu, 6 Aug 2026 10:47:09 +0200 Subject: [PATCH 2/7] Don't build frontend by default --- CMakeLists.txt | 56 +++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e691af9..72e65a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ add_compile_options( option( BUILD_FRONTEND "If ON, build the default frontend executable" - ON + OFF ) set(CMAKE_PREFIX_PATH "$ENV{MIDASSYS}") @@ -68,34 +68,38 @@ target_link_libraries( ## Test Frontend ################################################################################ -set(FRONTEND_NAME Ext_stray_field_status CACHE STRING "Overridable frontend name") +if(BUILD_FRONTEND) -add_executable( - Ext_stray_field_status_scfe - frontend/strayfield_scfe.cxx -) -add_compile_definitions(Ext_stray_field_status_scfe PRIVATE FRONTEND_NAME="${FRONTEND_NAME}") + set(FRONTEND_NAME Ext_stray_field_status CACHE STRING "Overridable frontend name") -set_property( - TARGET + add_executable( Ext_stray_field_status_scfe - PROPERTY - CXX_STANDARD 11 -) + frontend/strayfield_scfe.cxx + ) + add_compile_definitions(Ext_stray_field_status_scfe PRIVATE FRONTEND_NAME="${FRONTEND_NAME}") -target_include_directories( - Ext_stray_field_status_scfe - PRIVATE - $ENV{MIDASSYS}/drivers -) + set_property( + TARGET + Ext_stray_field_status_scfe + PROPERTY + CXX_STANDARD 11 + ) -target_link_libraries( - Ext_stray_field_status_scfe - strayfield -) - -install( - TARGETS + target_include_directories( Ext_stray_field_status_scfe - RUNTIME DESTINATION bin -) + PRIVATE + $ENV{MIDASSYS}/drivers + ) + + target_link_libraries( + Ext_stray_field_status_scfe + strayfield + ) + + install( + TARGETS + Ext_stray_field_status_scfe + RUNTIME DESTINATION bin + ) + +endif() -- 2.54.0 From bed403c5d274f202fb47566922a7ee2c18b7367a Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Thu, 6 Aug 2026 11:01:09 +0200 Subject: [PATCH 3/7] Apply clang-format to frontend --- frontend/strayfield_scfe.cxx | 125 +++++++++++++++-------------------- 1 file changed, 53 insertions(+), 72 deletions(-) diff --git a/frontend/strayfield_scfe.cxx b/frontend/strayfield_scfe.cxx index 0535013..9fccfe0 100644 --- a/frontend/strayfield_scfe.cxx +++ b/frontend/strayfield_scfe.cxx @@ -3,8 +3,8 @@ Name: Ext_stray_field_status_scfe.c Created by: Hubertus Luetkens - Contents: Midas frontend to read stray field status in the Experimental hall - (Cobra, Comet,...) from Multicasts + Contents: Midas frontend to read stray field status in the Experimental + hall (Cobra, Comet,...) from Multicasts \********************************************************************/ @@ -16,7 +16,7 @@ /*-- Globals -------------------------------------------------------*/ -/* The frontend name (client name) as seen by other MIDAS clients +/* The frontend name (client name) as seen by other MIDAS clients * This is a preprocessor macro with a default values that can be overriden * with cmake*/ const char *frontend_name = FRONTEND_NAME; @@ -34,20 +34,21 @@ INT display_period = 1000; INT max_event_size = 10000; /* maximum event size for fragmented events (EQ_FRAGMENTED) */ -INT max_event_size_frag = 5*1024*1024; +INT max_event_size_frag = 5 * 1024 * 1024; /* buffer size to hold events */ -INT event_buffer_size = 10*10000; +INT event_buffer_size = 10 * 10000; extern BOOL should_exit; /*! * equipment_common_overwrite: * - * - If that flag is TRUE, then the contents of the "equipment" structure is copied to - * the ODB on each start of the front-end. + * - If that flag is TRUE, then the contents of the "equipment" structure is + * copied to the ODB on each start of the front-end. * - * - If the flag is FALSE, then the ODB values are kept on the start of the front-end + * - If the flag is FALSE, then the ODB values are kept on the start of the + * front-end */ BOOL equipment_common_overwrite = FALSE; @@ -56,74 +57,69 @@ BOOL equipment_common_overwrite = FALSE; /* device driver list */ DEVICE_DRIVER strayfield_driver[] = { - { "stray_field", strayfield_in, 4, null, DF_INPUT}, -//{ "null", nulldev, 1, NULL, DF_OUTPUT}, /* not necessary ?? */ - { "" } -}; + {"stray_field", strayfield_in, 4, null, DF_INPUT}, + //{ "null", nulldev, 1, NULL, DF_OUTPUT}, /* not necessary ?? + //*/ + {""}}; EQUIPMENT equipment[] = { - { "Ext_stray_field_status", /* equipment name */ - {94, 0, /* event ID, trigger mask */ - "SYSTEM", /* event buffer */ - EQ_SLOW, /* equipment type */ - 0, /* event source */ - "FIXED", /* format */ - TRUE, /* enabled */ - RO_RUNNING | - RO_TRANSITIONS, /* read when running and on transitions */ - 10000, /* read every 10 sec */ - 0, /* stop run after this event limit */ - 0, /* number of sub events */ - 1, /* log history every event */ - "", "", ""}, - cd_multi_read, /* readout routine */ - cd_multi, /* class driver main routine */ - strayfield_driver, /* device driver list */ - NULL, /* init string */ - }, - - { "" } -}; - + { + "Ext_stray_field_status", /* equipment name */ + {94, 0, /* event ID, trigger mask */ + "SYSTEM", /* event buffer */ + EQ_SLOW, /* equipment type */ + 0, /* event source */ + "FIXED", /* format */ + TRUE, /* enabled */ + RO_RUNNING | RO_TRANSITIONS, /* read when running and on transitions */ + 10000, /* read every 10 sec */ + 0, /* stop run after this event limit */ + 0, /* number of sub events */ + 1, /* log history every event */ + "", "", ""}, + cd_multi_read, /* readout routine */ + cd_multi, /* class driver main routine */ + strayfield_driver, /* device driver list */ + NULL, /* init string */ + }, + {""}}; /*-- Dummy routines ------------------------------------------------*/ -INT poll_event(INT source, INT count, BOOL test) {return 1;} -INT interrupt_configure(INT cmd, INT source, PTYPE adr) {return 1;} +INT poll_event(INT source, INT count, BOOL test) { return 1; } +INT interrupt_configure(INT cmd, INT source, PTYPE adr) { return 1; } /*-- Frontend Init -------------------------------------------------*/ -INT frontend_init() -{ +INT frontend_init() { #ifdef LEM_USED - // not necessary for bulk as mfe.c is compiled with NO_RUN_TRANSITION flag - // de-register run-transition notifications - cm_deregister_transition(TR_START); - cm_deregister_transition(TR_STOP); - cm_deregister_transition(TR_PAUSE); - cm_deregister_transition(TR_RESUME); + // not necessary for bulk as mfe.c is compiled with NO_RUN_TRANSITION flag + // de-register run-transition notifications + cm_deregister_transition(TR_START); + cm_deregister_transition(TR_STOP); + cm_deregister_transition(TR_PAUSE); + cm_deregister_transition(TR_RESUME); #endif #ifdef FORTIFY - Fortify_CheckAllMemory(); + Fortify_CheckAllMemory(); #endif - return CM_SUCCESS; + return CM_SUCCESS; } /*-- Frontend Exit -------------------------------------------------*/ -INT frontend_exit() -{ +INT frontend_exit() { #ifdef FORTIFY - Fortify_CheckAllMemory(); - Fortify_OutputStatistics(); + Fortify_CheckAllMemory(); + Fortify_OutputStatistics(); #endif - return CM_SUCCESS; + return CM_SUCCESS; } /*-- Frontend Loop -------------------------------------------------*/ @@ -132,37 +128,22 @@ INT frontend_exit() static DWORD last_time_fortify = 0; #endif -INT frontend_loop() -{ - return CM_SUCCESS; -} +INT frontend_loop() { return CM_SUCCESS; } /*-- Begin of Run --------------------------------------------------*/ -INT begin_of_run(INT run_number, char *error) -{ - return CM_SUCCESS; -} +INT begin_of_run(INT run_number, char *error) { return CM_SUCCESS; } /*-- End of Run ----------------------------------------------------*/ -INT end_of_run(INT run_number, char *error) -{ - return CM_SUCCESS; -} +INT end_of_run(INT run_number, char *error) { return CM_SUCCESS; } /*-- Pause Run -----------------------------------------------------*/ -INT pause_run(INT run_number, char *error) -{ - return CM_SUCCESS; -} +INT pause_run(INT run_number, char *error) { return CM_SUCCESS; } /*-- Resuem Run ----------------------------------------------------*/ -INT resume_run(INT run_number, char *error) -{ - return CM_SUCCESS; -} +INT resume_run(INT run_number, char *error) { return CM_SUCCESS; } /*------------------------------------------------------------------*/ -- 2.54.0 From 14f58af4542ecb90ec17105c51d771e73aae9382 Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Thu, 6 Aug 2026 11:03:16 +0200 Subject: [PATCH 4/7] Fix workflows --- .gitea/workflows/action.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/action.yaml b/.gitea/workflows/action.yaml index cd615e3..6e8990b 100644 --- a/.gitea/workflows/action.yaml +++ b/.gitea/workflows/action.yaml @@ -8,11 +8,11 @@ jobs: - name: checkout repo uses: actions/checkout@v4 - name: formatting - run: clang-format --style=file --Werror --dry-run device/* frontends/* + run: clang-format --style=file --Werror --dry-run device/* frontend/* Lint: runs-on: linepics steps: - name: checkout repo uses: actions/checkout@v4 - name: cppcheck - run: cppcheck --std=c++17 --addon=cert --addon=misc --error-exitcode=1 device/ frontends/ + run: cppcheck --std=c++17 --addon=cert --addon=misc --error-exitcode=1 device/ frontend/ -- 2.54.0 From c04ca78c8c75d798e034cd3c68901c568e6f7b39 Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Thu, 6 Aug 2026 11:22:04 +0200 Subject: [PATCH 5/7] Give cmake frontend var a unique name --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72e65a5..3705174 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,7 @@ target_link_libraries( if(BUILD_FRONTEND) - set(FRONTEND_NAME Ext_stray_field_status CACHE STRING "Overridable frontend name") + set(STRAYFIELD_FRONTEND_NAME Ext_stray_field_status CACHE STRING "Overridable frontend name") add_executable( Ext_stray_field_status_scfe -- 2.54.0 From ce73e3d3185739eba21d47503316a7859ce44332 Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Thu, 6 Aug 2026 15:17:55 +0200 Subject: [PATCH 6/7] Fix frontend macro typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3705174..2c4cd3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,7 +76,7 @@ if(BUILD_FRONTEND) Ext_stray_field_status_scfe frontend/strayfield_scfe.cxx ) - add_compile_definitions(Ext_stray_field_status_scfe PRIVATE FRONTEND_NAME="${FRONTEND_NAME}") + add_compile_definitions(Ext_stray_field_status_scfe PRIVATE FRONTEND_NAME="${STRAYFIELD_FRONTEND_NAME}") set_property( TARGET -- 2.54.0 From 0904df4d5e0fc92dbbbf88a140586b6a3ed34bd5 Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Mon, 10 Aug 2026 16:58:55 +0200 Subject: [PATCH 7/7] default frontend improvements --- CMakeLists.txt | 2 +- frontend/strayfield_scfe.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c4cd3c..185833b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ target_link_libraries( ## Test Frontend ################################################################################ -if(BUILD_FRONTEND) +if(${BUILD_FRONTEND}) set(STRAYFIELD_FRONTEND_NAME Ext_stray_field_status CACHE STRING "Overridable frontend name") diff --git a/frontend/strayfield_scfe.cxx b/frontend/strayfield_scfe.cxx index 9fccfe0..c034cf4 100644 --- a/frontend/strayfield_scfe.cxx +++ b/frontend/strayfield_scfe.cxx @@ -65,7 +65,7 @@ DEVICE_DRIVER strayfield_driver[] = { EQUIPMENT equipment[] = { { - "Ext_stray_field_status", /* equipment name */ + FRONTEND_NAME, /* equipment name */ {94, 0, /* event ID, trigger mask */ "SYSTEM", /* event buffer */ EQ_SLOW, /* equipment type */ -- 2.54.0