From aa55d82c3facbcc2f92100db50b1dd9558f20c48 Mon Sep 17 00:00:00 2001 From: tomeichlersmith Date: Wed, 20 Sep 2023 10:15:22 -0500 Subject: [PATCH 1/4] unpack magnetic field at install time This helps avoid writing to the install location until the user asks for an install. Unfortunately, this CMake will _always_ unpack the tar ball even if the tar-ball didn't change and the unpacked file(s) already exist. --- CMakeLists.txt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c96e70e..dda1f35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.12) # Set the project name -project(MagFieldMap VERSION 2.1.0 +project(MagFieldMap VERSION 0.1.0 DESCRIPTION "Repository for LDMX magnetic field maps." ) @@ -14,14 +14,9 @@ file(GLOB fieldmap_files *.tar.gz) # Check if the fieldmap has already been extracted. If not, extract and install # the fieldmaps. +install(CODE "execute_process(COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX}/data/fieldmap)") foreach(fieldmap_path ${fieldmap_files}) - get_filename_component(fieldmap_file ${fieldmap_path} NAME) - string(REPLACE ".tar.gz" "" fieldmap_file_raw ${fieldmap_file}) - if (NOT EXISTS ${CMAKE_INSTALL_PREFIX}/data/fieldmap/${fieldmap_file_raw}) - configure_file(${fieldmap_path} ${CMAKE_INSTALL_PREFIX}/data/fieldmap/${fieldmap_file} COPYONLY) - execute_process(COMMAND tar -zxvf ${fieldmap_file} - WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/data/fieldmap - ) - file(REMOVE ${CMAKE_INSTALL_PREFIX}/data/fieldmap/${fieldmap_file}) - endif() + get_filename_component(fieldmap_file ${fieldmap_path} NAME) + install(CODE "message(STATUS \"unpacking ${fieldmap_file}\")") + install(CODE "execute_process(COMMAND tar -zxf ${fieldmap_path} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/data/fieldmap)") endforeach() From f3dd12079c9ea29d15af8cf4b008ce6b3630e226 Mon Sep 17 00:00:00 2001 From: tomeichlersmith Date: Wed, 11 Oct 2023 11:57:41 -0500 Subject: [PATCH 2/4] move install process to its own script we can then configure this script with the list of tar-balls to unpack and then run it at install time where it checks if the tar-balls need to be unpacked or not using a timestamp file and the existence of the expected data file --- CMakeLists.txt | 14 ++++---------- install.cmake.in | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 install.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index dda1f35..73803a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,14 +9,8 @@ project(MagFieldMap VERSION 0.1.0 message(STATUS "Installing all field map files.") -# Retrieve all of the fieldmap files +# retrieve list of the fieldmap files file(GLOB fieldmap_files *.tar.gz) - -# Check if the fieldmap has already been extracted. If not, extract and install -# the fieldmaps. -install(CODE "execute_process(COMMAND mkdir -p ${CMAKE_INSTALL_PREFIX}/data/fieldmap)") -foreach(fieldmap_path ${fieldmap_files}) - get_filename_component(fieldmap_file ${fieldmap_path} NAME) - install(CODE "message(STATUS \"unpacking ${fieldmap_file}\")") - install(CODE "execute_process(COMMAND tar -zxf ${fieldmap_path} WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/data/fieldmap)") -endforeach() +# pass this information to the install script +configure_file(install.cmake.in ${PROJECT_BINARY_DIR}/install.cmake @ONLY) +install(SCRIPT ${PROJECT_BINARY_DIR}/install.cmake) diff --git a/install.cmake.in b/install.cmake.in new file mode 100644 index 0000000..a8ceb2f --- /dev/null +++ b/install.cmake.in @@ -0,0 +1,38 @@ +# install magnetic fieldmaps only if the original tar-ball changes +# +# Assumptions +# - The magnetic fieldmaps are *.tar.gz files compressing a single file with the same name +# This assumption is necessary so that we can check for the existence of the unpacked +# file without having to inspect the contents of the tar-ball (only its file name). +# +# The fieldmaps are unpacked into the /data/fieldmap directory and a timestamp +# for when they were last installed is created within ${CMAKE_CURRENT_BINARY_DIRECTORY}/MagFieldMap +# If the installed filed exists, this timestamp file exists and is newer than the original tar-ball, the unpacking +# operation is not performed. +# This logic allows for the tar-ball to only be unpacked when it is necessary (the tar-ball changes +# due to e.g. a re-pull or the install hasn't happened yet). + +# retrieve list of the fieldmap files +set(fieldmap_files "@fieldmap_files@") + +# define directory in which the files will be installed +set(magfield_map_install $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/data/fieldmap) + +# make sure install location exists +execute_process(COMMAND mkdir -p ${magfield_map_install}) +foreach(fieldmap_path ${fieldmap_files}) + get_filename_component(fieldmap_file ${fieldmap_path} NAME) + string(REPLACE ".tar.gz" "" fieldmap_filename ${fieldmap_file}) + set(fieldmap_install ${magfield_map_install}/${fieldmap_filename}) + set(install_timestamp ${CMAKE_CURRENT_BINARY_DIR}/MagFieldMap/${fieldmap_filename}.stamp) + if (EXISTS ${fieldmap_install} AND EXISTS ${install_timestamp} AND ${install_timestamp} IS_NEWER_THAN ${fieldmap_path}) + message(STATUS "Up-to-date: ${fieldmap_install}") + else() + message(STATUS "Installing: ${fieldmap_install}") + execute_process( + COMMAND tar -zxf ${fieldmap_path} + COMMAND touch ${install_timestamp} + WORKING_DIRECTORY ${magfield_map_install} + ) + endif() +endforeach() From 4442b09de71fe0f802f8733f5c329e38ecfbb227 Mon Sep 17 00:00:00 2001 From: tomeichlersmith Date: Wed, 11 Oct 2023 12:01:19 -0500 Subject: [PATCH 3/4] add note about provenance of current fieldmap --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d8622d4..0221b82 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ # MagFieldMap Magnetic field maps for LDMX detectors + +### BmapCorrected3D_13k_unfolded_scaled_1.15384615385.dat.tar.gz +This fieldmap was taken from measurements of the dipole magnet used within HPS +and then scaled to match the specifications of the dipole magnet expected to be +used by LDMX. From e1b648e29c7304515196871564d376ef72281e42 Mon Sep 17 00:00:00 2001 From: tomeichlersmith Date: Wed, 11 Oct 2023 12:02:15 -0500 Subject: [PATCH 4/4] bump minor version for updated cmake install --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73803a8..fa12af9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.12) # Set the project name -project(MagFieldMap VERSION 0.1.0 +project(MagFieldMap VERSION 0.2.0 DESCRIPTION "Repository for LDMX magnetic field maps." )