From 6cb9d7ae74fc81233aa59dbac9f9df455c3dd0ca Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Mon, 7 Sep 2026 10:24:55 +0200 Subject: [PATCH 1/2] Cleanup commented code and HAVE_TEST_RUN --- CMakeLists.txt | 8 +-- device/struck_sis3820.c | 85 +++----------------------- frontend/struck_sis3820_fcfe.cxx | 101 ------------------------------- 3 files changed, 10 insertions(+), 184 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00cca72..276b5e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,7 @@ set(CMAKE_PREFIX_PATH "$ENV{MIDASSYS}") set(SIS1100_DIR "struck_sis1100-310x") -# Always build the library (even for test mode, we can define HAVE_TEST_RUN) +# Always build the library add_library(sis3100scal STATIC ${SIS1100_DIR}/sis3100_calls/sis3100_vme_calls.c ${SIS1100_DIR}/sis3100_calls/sharc_utils.c @@ -64,12 +64,6 @@ target_include_directories(sis3100scal ${SIS1100_DIR} ) -# --- TEST FRONTEND MODE --- -if (FRONTEND) - target_compile_definitions(sis3100scal PUBLIC HAVE_TEST_RUN) - message(STATUS "Building in TEST FRONTEND mode (no hardware required).") -endif () - # ============================================================================= # 5. Scaler Frontend Executable # ============================================================================= diff --git a/device/struck_sis3820.c b/device/struck_sis3820.c index d625525..9788e6b 100644 --- a/device/struck_sis3820.c +++ b/device/struck_sis3820.c @@ -38,14 +38,7 @@ */ int sis3820_key_reset(int device, u_int32_t sis3820_base) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_write(device, sis3820_base+SIS3820_KEY_RESET, SIS3820_KEY_RESET); -#endif - return status; + return vme_A32D32_write(device, sis3820_base+SIS3820_KEY_RESET, SIS3820_KEY_RESET); } /*------ sis3820_key_enable -----------------------------------------------------*/ @@ -61,14 +54,7 @@ int sis3820_key_reset(int device, u_int32_t sis3820_base) */ int sis3820_key_enable(int device, u_int32_t sis3820_base) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_write(device, sis3820_base+SIS3820_KEY_OPERATION_ENABLE, SIS3820_KEY_OPERATION_ENABLE); -#endif - return status; + return vme_A32D32_write(device, sis3820_base+SIS3820_KEY_OPERATION_ENABLE, SIS3820_KEY_OPERATION_ENABLE); } /*------- sis3820_key_disable ----------------------------------------------------*/ @@ -83,27 +69,13 @@ int sis3820_key_enable(int device, u_int32_t sis3820_base) */ int sis3820_key_disable(int device, u_int32_t sis3820_base) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_write(device, sis3820_base+SIS3820_KEY_OPERATION_DISABLE, SIS3820_KEY_OPERATION_DISABLE); -#endif - return status; + return vme_A32D32_write(device, sis3820_base+SIS3820_KEY_OPERATION_DISABLE, SIS3820_KEY_OPERATION_DISABLE); } /*------------------------------------------------------------------------------*/ int sis3820_operation_mode_read(int device, u_int32_t sis3820_base, u_int32_t* mode) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_read(device, sis3820_base+SIS3820_OPERATION_MODE, mode); -#endif - return status; + return vme_A32D32_read(device, sis3820_base+SIS3820_OPERATION_MODE, mode); } /*------- sis3820_operation_mode_write -----------------------------------------*/ @@ -164,40 +136,19 @@ int sis3820_operation_mode_read(int device, u_int32_t sis3820_base, u_int32_t* m /*------------------------------------------------------------------------------*/ int sis3820_operation_mode_write(int device, u_int32_t sis3820_base, u_int32_t mode) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_write(device, sis3820_base+SIS3820_OPERATION_MODE, mode); -#endif - return status; + return vme_A32D32_write(device, sis3820_base+SIS3820_OPERATION_MODE, mode); } /*------------------------------------------------------------------------------*/ int sis3820_modid_read(int device, u_int32_t sis3820_base, u_int32_t* modid) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_read(device, sis3820_base+SIS3820_MODID, modid); -#endif - return status; + return vme_A32D32_read(device, sis3820_base+SIS3820_MODID, modid); } /*------------------------------------------------------------------------------*/ int sis3820_control_read(int device, u_int32_t sis3820_base, u_int32_t* control_status) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_read(device, sis3820_base+SIS3820_CONTROL_STATUS, control_status); -#endif - return status; + return vme_A32D32_read(device, sis3820_base+SIS3820_CONTROL_STATUS, control_status); } /*------- sis3820_control_write -----------------------------------------*/ @@ -228,14 +179,7 @@ int sis3820_control_read(int device, u_int32_t sis3820_base, u_int32_t* control_ *------------------------------------------------------------------------------*/ int sis3820_control_write(int device, u_int32_t sis3820_base, u_int32_t control_status) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_write(device, sis3820_base+SIS3820_CONTROL_STATUS, control_status); -#endif - return status; + return vme_A32D32_write(device, sis3820_base+SIS3820_CONTROL_STATUS, control_status); } /*------- sis3820_copy_disable_channel -------------------------------------------*/ @@ -252,14 +196,7 @@ int sis3820_control_write(int device, u_int32_t sis3820_base, u_int32_t control_ */ int sis3820_copy_disable_channel(int device, u_int32_t sis3820_base, u_int32_t channel_disable) { - int status; - -#ifdef HAVE_TEST_RUN - status = 0; -#else - status = vme_A32D32_write(device, sis3820_base+SIS3820_COPY_DISABLE, channel_disable); -#endif - return status; + return vme_A32D32_write(device, sis3820_base+SIS3820_COPY_DISABLE, channel_disable); } /*-------- sis3820_scaler_read ----------------------------------------------------*/ @@ -283,9 +220,6 @@ int sis3820_scaler_read(int device, u_int32_t sis3820_base, int mode, int nwords int status ; int gotwords; -#ifdef HAVE_TEST_RUN - status = 0; -#else status = -2; switch (mode) @@ -320,7 +254,6 @@ int sis3820_scaler_read(int device, u_int32_t sis3820_base, int mode, int nwords default: break; } -#endif return status; } diff --git a/frontend/struck_sis3820_fcfe.cxx b/frontend/struck_sis3820_fcfe.cxx index 88daab0..60d932d 100644 --- a/frontend/struck_sis3820_fcfe.cxx +++ b/frontend/struck_sis3820_fcfe.cxx @@ -200,9 +200,6 @@ INT frontend_init() flag_scaler_address_1 = FALSE;} /*--- VME initialization ---*/ -#ifdef HAVE_TEST_RUN - hdev = 0; -#else cm_msg(MINFO, "frontend_init","LINUX_VERSION = 0x%x",LINUX_VERSION_CODE); cm_yield(0); if (LINUX_VERSION_CODE < 0x20600) // for sis1100 drivers < V2, Linux kernel 2.4 @@ -216,7 +213,6 @@ INT frontend_init() cm_yield(0); return FE_ERR_HW; } -#endif //SIS3820 scaler initialization if (init_sis3820(SIS3820_ADDRESS_0) == FE_ERR_HW) @@ -427,11 +423,6 @@ INT interrupt_configure(INT cmd, INT source, PTYPE adr) *

Read out of scaler modules. *

* - *

If HAVE_TEST_RUN is defined scaler entries - * of about 100 are thrown. If not defined - * use the function sis3820_read_scaler - * to read out the VME scaler module. - * *

Return: * - bank size of scaler event * @@ -450,23 +441,6 @@ INT read_scaler_event(char *pevent, INT off) bk_create(pevent, "SCL0", TID_DWORD, (void**)&pdata); // read out scaler module / -#ifdef HAVE_TEST_RUN - int channel = 0; - for (i=0; i scaler_mode is called at begin_of_run. * It reads the ODB record /Equipment/Scaler/Settings * and checks if the variable @@ -758,8 +726,6 @@ INT scaler_sum( char *pevent) double *psrat; INT *pd; INT *psratio; - //RATE_BANK *prate; - //SRAT_BANK *psrat; double new_lem_events; int norm_time_ch; @@ -791,26 +757,9 @@ INT scaler_sum( char *pevent) /* --- create rate bank and calculate rates --- */ - //bk_create(pevent, "RATE", TID_STRUCT, (void **)&prate); bk_create(pevent, "RATE", TID_DOUBLE, (void **)&prate); - //pd = &prate->ip; // copy address of first element of structure to pointer pd - // this is useful if the structure contains n elements of same type, - // i.e. (double) in our case. If element names should be different - // then this offers a simple way to assign values to the elements - // without explicitly entering the element name. - // This will work with the statement - // *(pd+i) = rate[i]; see below - //not using a struct anymore. - for (i=0; i 0) { norm = (double)mask_scaler[norm_time_ch]/(double)scaler_param["rate_norm_time"]; @@ -818,41 +767,16 @@ INT scaler_sum( char *pevent) } else { rate[i] = -1; } -#endif - //prate->rat0[i] = rate[i]; - //*(pd+i) = rate[i]; // increment pointer address by the size of one double, assign - // value of rate[i] to new address, - // which is the ith entry of the structure prate prate[i] = rate[i]; } bk_close(pevent, prate+n); - /* - //TODO: TDC rate is already in odb. Not clear, why it should be duplicated here.? - // get LEM events from VME_STATS key in ODB - new_lem_events = 0.; - size = sizeof(lem_events); - //db_get_value(hDB, 0, "/Equipment/Trigger/VME_Statistics/SlowMuonEvents", &lem_events, &size, TID_DOUBLE, FALSE); - db_get_value(hDB, 0, "/Equipment/TDC/Vme_Statistics/Muon Good", &lem_events, &size, TID_DOUBLE, FALSE); - new_lem_events = lem_events - last_lem_events; - last_lem_events = lem_events; - if (new_lem_events < 0.0) - new_lem_events = 0.0; // this may happen at BOR - norm_time_ch=scaler_param["channel_norm_time"]; - if (mask_scaler[norm_time_ch] > 0) - rate[i] = (int) rint(new_lem_events/norm); - else - rate[i] = -1; - *(pd+i) = rate[i]; - - bk_close(pevent, prate+1);*/ /*---------------------------------------------------------------- calculate scaler ratios ---------------------------------------------------------------- */ /* create calculated bank */ - //bk_create(pevent, "SRAT", TID_STRUCT, (void **)&psrat); bk_create(pevent, "SRAT", TID_DOUBLE, (void **)&psrat); //psratio = &psrat->ip; // copy address of first element of structure to pointer psratio @@ -860,23 +784,13 @@ INT scaler_sum( char *pevent) //---- perform calculations --------------------------------------/ int ip_channel=scaler_param["ip_channel"]; if (rate[ip_channel] > scaler_param["ip_threshold_current_ua_"]*100) { -// psrat->ch1_ip = IpSCALE * (float) prate->rat0[0] / (float) prate->rat0[scaler_analysis_param.ip_channel]; -// psrat->ch1_ip = IpSCALE * (float) pd[0] / (float) pd[scaler_param.ip_channel]; for (i=0; icompbusy = 1. - (float) pscl0[hrates_param.lam2] / (float) pscl0[hrates_param.trig2]; - else -*/ bk_close(pevent, psrat+n); //fill ring buffer for Ip @@ -909,21 +823,6 @@ INT scaler_sum( char *pevent) bk_close(pevent, pmean_rate+1); // display scalers in terminal - /* - if (runinfo.online_mode == 1) - disp_scaler(N_SCALER);*/ - - // send the normalized PosM1 Rate to EPICS - - /* LEM alternative of feeding signal back to Hallensignale. - char cmd[512]; - int posM1 = *(psratio+52); // channel 52 is PosM1 - setenv("EPICS_CA_SERVER_PORT", "5062", 0); - setenv("EPICS_CA_ADDR_LIST", "hipa-cagw", 0); - setenv("EPICS_CA_AUTO_ADDR_LIST", "NO", 0); - snprintf(cmd, sizeof(cmd), "/usr/local/epics/base/bin/RHEL8-x86_64/caput ZMUE4-LEM:POSM1_RATE %d &> /dev/null", posM1); - system(cmd); - */ return SUCCESS; } -- 2.54.0 From 5dbb4f8133c03375235f05b09a1880badde586d7 Mon Sep 17 00:00:00 2001 From: Alexander Soederqvist Date: Mon, 7 Sep 2026 15:41:18 +0200 Subject: [PATCH 2/2] Fix and cleanup some more CMake things --- CMakeLists.txt | 67 ++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 276b5e3..bef8197 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,44 +71,41 @@ target_include_directories(sis3100scal set(_default_scaler_frontend_dir "${CMAKE_CURRENT_LIST_DIR}" CACHE INTERNAL "") function(default_scaler_frontend F_TARGET F_NAME F_EVENT_ID NUM_CHANNELS) -add_executable(${F_TARGET} - ${_default_scaler_frontend_dir}/frontend/struck_sis3820_fcfe.cxx - ${_default_scaler_frontend_dir}/device/struck_sis3820.c - ${DRIVERS} -) + add_executable(${F_TARGET} + ${_default_scaler_frontend_dir}/frontend/struck_sis3820_fcfe.cxx + ${_default_scaler_frontend_dir}/device/struck_sis3820.c + ) -target_compile_definitions(${F_TARGET} PUBLIC FRONTEND_NAME="${F_NAME}") -target_compile_definitions(${F_TARGET} PUBLIC N_SCALER=${NUM_CHANNELS}) -target_compile_definitions(${F_TARGET} PUBLIC F_EVENT_ID=${F_EVENT_ID}) + target_compile_definitions(${F_TARGET} PUBLIC FRONTEND_NAME="${F_NAME}") + target_compile_definitions(${F_TARGET} PUBLIC N_SCALER=${NUM_CHANNELS}) + target_compile_definitions(${F_TARGET} PUBLIC F_EVENT_ID=${F_EVENT_ID}) -target_include_directories(${F_TARGET} - PRIVATE - $ENV{MIDASSYS}/include - $ENV{MIDASSYS}/drivers/kernel - $ENV{MIDASSYS}/drivers/divers - ${_DEFAULT_SCALER_FRONTEND_DIR} - ${_DEFAULT_SCALER_FRONTEND_DIR}/mxml - ${_DEFAULT_SCALER_FRONTEND_DIR}/device - ${SIS1100_DIR} - ${SIS1100_DIR}/sis3100_calls -) + target_include_directories(${F_TARGET} + PRIVATE + $ENV{MIDASSYS}/include + $ENV{MIDASSYS}/drivers/kernel + $ENV{MIDASSYS}/drivers/divers + ${_default_scaler_frontend_dir}/ + ${SIS1100_DIR} + ${SIS1100_DIR}/sis3100_calls + ) -find_package(Midas REQUIRED) -target_link_libraries(${F_TARGET} - PRIVATE - sis3100scal - midas::mfe - midas::midas - midas::mscb - z pthread util rt dl m -) + find_package(Midas REQUIRED) + target_link_libraries(${F_TARGET} + PRIVATE + sis3100scal + midas::mfe + midas::midas + midas::mscb + z pthread util rt dl m + ) -# ============================================================================= -# 6. Installation -# ============================================================================= + # ============================================================================= + # 6. Installation + # ============================================================================= -install( - TARGETS ${F_TARGET} - RUNTIME DESTINATION bin -) + install( + TARGETS ${F_TARGET} + RUNTIME DESTINATION bin + ) endfunction() -- 2.54.0