Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from LDMX-Software/unpack-at-install
Browse files Browse the repository at this point in the history
unpack magnetic field at install time
  • Loading branch information
tomeichlersmith authored Oct 11, 2023
2 parents 08e5aa5 + e1b648e commit 82ad441
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
21 changes: 5 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@
cmake_minimum_required(VERSION 3.12)

# Set the project name
project(MagFieldMap VERSION 2.1.0
project(MagFieldMap VERSION 0.2.0
DESCRIPTION "Repository for LDMX magnetic field maps."
)

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.
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()
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)
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
38 changes: 38 additions & 0 deletions install.cmake.in
Original file line number Diff line number Diff line change
@@ -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 <install-path>/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()

0 comments on commit 82ad441

Please sign in to comment.