diff --git a/cmake/corsikaUtilities.cmake b/cmake/corsikaUtilities.cmake index cf8f1ef681a13f6545b613966f9f47f576e5d918..fb2c78684484321bc16d191c3fa6784b16d532b0 100644 --- a/cmake/corsikaUtilities.cmake +++ b/cmake/corsikaUtilities.cmake @@ -58,6 +58,7 @@ function (CORSIKA_ADD_TEST) add_executable (${name} ${sources}) target_link_libraries (${name} CORSIKA8 CONAN_PKG::catch2 CorsikaTestingCommon) + target_link_options (${name} PRIVATE "LINKER:--unresolved-symbols=ignore-in-shared-libs") target_compile_options (${name} PRIVATE -g) # do not skip asserts target_include_directories (${name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/test_outputs/) diff --git a/corsika/detail/framework/random/random_iterator/detail/uint128.inl b/corsika/detail/framework/random/random_iterator/detail/uint128.inl index 685d641a0927b52a8446e096775ff1dd101256a4..d3ee839f7e9d68a252df99029dbe1a1c5e740e39 100644 --- a/corsika/detail/framework/random/random_iterator/detail/uint128.inl +++ b/corsika/detail/framework/random/random_iterator/detail/uint128.inl @@ -211,11 +211,11 @@ namespace random_iterator { } inline bool uint128_t::operator>=(const uint128_t& rhs) const { - return ((*this > rhs) | (*this == rhs)); + return ((*this > rhs) || (*this == rhs)); } inline bool uint128_t::operator<=(const uint128_t& rhs) const { - return ((*this < rhs) | (*this == rhs)); + return ((*this < rhs) || (*this == rhs)); } inline uint128_t uint128_t::operator+(const uint128_t& rhs) const { diff --git a/modules/fluka/CMakeLists.txt b/modules/fluka/CMakeLists.txt index d3468ce4d7a9f55537cff3276095eaf85cedca16..3edf5a3e4de5e79523d423d32e145f6782a79233 100644 --- a/modules/fluka/CMakeLists.txt +++ b/modules/fluka/CMakeLists.txt @@ -1,13 +1,27 @@ -set(C8_FLUKALIB CACHE STRING "path to libflukahp.a") +set(C8_FLUKALIB CACHE FILEPATH "path to libflukahp.a") + +set(C8_FLUKALIB_ "") +if (EXISTS "$CACHE{C8_FLUKALIB}") + message("libflukahp.a found at ${C8_FLUKALIB} via C8_FLUKALIB") + set(C8_FLUKALIB_ "$CACHE{C8_FLUKALIB}") +elseif (EXISTS "$ENV{FLUPRO}/libflukahp.a") + message("libflukahp.a found in directory $ENV{FLUPRO} via FLUPRO environment variable") + set(C8_FLUKALIB_ "$ENV{FLUPRO}/libflukahp.a") +endif() + +if ("${C8_FLUKALIB_}" STREQUAL "") + message("C8_FLUKALIB not set/invalid and FLUPRO not set, building without FLUKA support") + set(C8_FLUKA_ENABLED "" CACHE INTERNAL "" FORCE) # makeshift global var +else() + message("FLUKA support is enabled.") + set(C8_FLUKA_ENABLED "enabled" CACHE INTERNAL "" FORCE) # makeshift global var -if (EXISTS "${C8_FLUKALIB}") - message("libflukahp.a found at ${C8_FLUKALIB}; FLUKA support is enabled.") set (input_dir ${PROJECT_SOURCE_DIR}/src/modules/fluka) # we remove flrndm_.o from the original libflukahp.a and save the result as libflukahp-norndm.a add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/libflukahp-norndm.a - COMMAND ${input_dir}/strip_flukahp.sh ${C8_FLUKALIB} ${CMAKE_CURRENT_BINARY_DIR} + COMMAND ${input_dir}/strip_flukahp.sh ${C8_FLUKALIB_} ${CMAKE_CURRENT_BINARY_DIR} ) add_custom_target(generate_libfluka-norndm DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/libflukahp-norndm.a) @@ -36,7 +50,7 @@ if (EXISTS "${C8_FLUKALIB}") install ( FILES - fluka.hpp + FLUKA.hpp DESTINATION include/corsika_modules/fluka ) @@ -50,6 +64,4 @@ if (EXISTS "${C8_FLUKALIB}") # add fluka to corsika8 build add_dependencies (CORSIKA8 fluka) target_link_libraries (CORSIKA8 INTERFACE fluka) -else() - message("C8_FLUKALIB not set/invalid, building without FLUKA support") endif() diff --git a/modules/fluka/FLUKA.hpp b/modules/fluka/FLUKA.hpp index 12b8a17562cee175314c8ba6c6ff0a5154eb683b..a1e2674e79ff1aeeae906c57a6d919d67c325e11 100644 --- a/modules/fluka/FLUKA.hpp +++ b/modules/fluka/FLUKA.hpp @@ -225,5 +225,8 @@ namespace fluka { //! random-number generator called from within FLUKA double flrndm_(); + + //! random-number generator called from within FLUKA, fills entire array + void flrnlp_(double* array, int const* N); } } // namespace fluka diff --git a/modules/fluka/fluka.cpp b/modules/fluka/fluka.cpp index 985bde38bd414cae76dd2113c4df266820578f16..00378c254c351d29605a395859551a23fb0c8c77 100644 --- a/modules/fluka/fluka.cpp +++ b/modules/fluka/fluka.cpp @@ -13,6 +13,9 @@ namespace fluka { extern "C" { double flrndm_() { return ::fluka::rndmPtr(); } + void flrnlp_(double* array, int const* N) { + for (int i = 0; i < *N; ++i) { array[i] = ::fluka::rndmPtr(); } + } //! overwrite function pointer to be used as FLUKA RNG (flrndm_()) void setFlukaRNG(double (*func)()) { ::fluka::rndmPtr = func; } diff --git a/src/modules/fluka/strip_flukahp.sh b/src/modules/fluka/strip_flukahp.sh index 0ee9693bfcb16c61d90d48929fa1b431031e4127..4a861800defe3eeb97ff7d00bf4623c184ef821c 100755 --- a/src/modules/fluka/strip_flukahp.sh +++ b/src/modules/fluka/strip_flukahp.sh @@ -8,29 +8,33 @@ # Licence version 3 (GPL Version 3). See file LICENSE for a full version of # the license. -# This script strips off flrndm() from the libflukahp.a so that we can provide our own -# implementation. +# This script strips off flrndm() and flrnlp() from libflukahp.a so that +# we can provide our own implementation. flukalibOrig=`realpath $1` target="$2" -if [ ! -r "$flukalibOrig" ]; then - echo "\"$flukalibOrig\" not readable" 1>&2 +if [ -d "$flukalibOrig" ]; then + echo "\"$flukalibOrig\" is a directory. Please specify full path to libflukahp.a?" 1>&2 exit 1 fi -tmpdir=`mktemp -d fluka_objectsXXXXXX` -workdir=`pwd` - -echo "extracting objects from $flukalibOrig into `realpath $tmpdir`..." -cd "$tmpdir" -ar x "$flukalibOrig" -cd "$workdir" -rm "$tmpdir/flrndm.o" +if [ ! -f "$flukalibOrig" ]; then + echo "\"$flukalibOrig\" is not a regular file. Did you specify the full path to libflukahp.a?" 1>&2 + exit 1 +fi -[ -f "libflukahp-norndm.a" ] && rm "libflukahp-norndm.a" +if [ ! -r "$flukalibOrig" ]; then + echo "\"$flukalibOrig\" not readable" 1>&2 + exit 1 +fi -echo "creating libflukahp-norndm.a..." -ar -rcs "$target/libflukahp-norndm.a" "$tmpdir"/*.o +# check if FLUKA has the required symbols. If not, it is an imcompatible +# version (e.g. CERN FLUKA or too old) +if ! ar t "$flukalibOrig" | grep ndmhep.o >/dev/null; then + echo "The provided libflukahp.a is incompatible." 1>&2 + exit 1 +fi -rm -r "$tmpdir" +cp "${flukalibOrig}" "${target}/libflukahp-norndm.a" && \ +ar -d "${target}/libflukahp-norndm.a" flrndm.o flrnlp.o diff --git a/tests/modules/CMakeLists.txt b/tests/modules/CMakeLists.txt index 16a0e66f0d34824f0ed173a5a66a759999dab17f..578eed167ed92c1c8737d7bf810d66a737c9676d 100644 --- a/tests/modules/CMakeLists.txt +++ b/tests/modules/CMakeLists.txt @@ -16,9 +16,10 @@ set (test_modules_sources testEMThinning.cpp testSophia.cpp ) - -if (EXISTS "${C8_FLUKALIB}") + +if (NOT "$CACHE{C8_FLUKA_ENABLED}" STREQUAL "") list(APPEND test_modules_sources "testFluka.cpp") + message("testFluka enabled") endif() CORSIKA_ADD_TEST (testModules SOURCES ${test_modules_sources}) diff --git a/tests/output/testWriterOff.cpp b/tests/output/testWriterOff.cpp index 1f572da3f42d19a69db53c72b72cb7758e8f6690..9d71be652f317bfbadf44cf0e8f3b97f8d6fa2b5 100644 --- a/tests/output/testWriterOff.cpp +++ b/tests/output/testWriterOff.cpp @@ -30,8 +30,8 @@ TEST_CASE("WriterOff") { logging::set_level(logging::level::info); - WriterOff test("irrelevant", 3); - WriterOff test2(); + WriterOff test{"irrelevant", 3}; + WriterOff test2{}; test.startOfLibrary("./output_dir_eloss"); test.startOfShower(0);