From 82e4905e0eab1fa6dca50ad02a9eb0575e39ba52 Mon Sep 17 00:00:00 2001 From: Austin Schneider Date: Wed, 23 Oct 2024 14:47:33 -0400 Subject: [PATCH] Dev/serialization (#85) * Injector serialization via pickle working * Remove cruft * Undo addition to DecaySignature * Remove printouts in DetectorModel serialization * Remove unnecessary cereal macros * Revert changes to link ordering * Remove comments * Don't need global FPIC now that it is handled with an INTERFACE target * Attempt to perform explicit template instantiation for interpolator templates * CMake fixes * Improve logic for finding cfitsio. Make an IMPORT target for cfitsio * Use lists for find_path * Search all paths in secondary searches * Remove printouts * Remove redundant paths for find_library * Link photospline with CFITSIO. Use generator expressions for -s and -stdlib=libc++ * Set policies for macos * Use photospline from icecube git repo. Update photospline and cereal * Remove printouts * Upgrade pybind11 * Use shared_ptr for compatibility of classes without a default constructor * Pickle weighter * Move external headers * pybind11 used in pickle serialization * Pickle serialization for dataclasses * Revert "Upgrade pybind11" This reverts commit add5a6a35600d407e73350b6df7d2869b6fc41ee. --- .gitmodules | 2 +- CMakeLists.txt | 91 +++++++---- cmake/Packages/CFITSIO.cmake | 152 ++++++++++++------ projects/dataclasses/CMakeLists.txt | 5 +- .../private/pybindings/dataclasses.cxx | 23 +++ .../dataclasses/public/SIREN/dataclasses.h | 12 ++ .../public/SIREN/dataclasses/serializable.h | 12 ++ projects/detector/CMakeLists.txt | 16 +- projects/detector/private/Axis1D.cxx | 3 + projects/detector/private/CartesianAxis1D.cxx | 3 + .../CartesianAxisDensityDistribution.cxx | 4 + ...sianAxisExponentialDensityDistribution.cxx | 4 + ...esianAxisPolynomialDensityDistribution.cxx | 4 + .../private/ConstantDensityDistribution.cxx | 9 ++ .../private/ConstantDistribution1D.cxx | 3 + .../detector/private/DensityDistribution.cxx | 3 + .../private/DensityDistribution1D.cxx | 4 + projects/detector/private/DetectorModel.cxx | 3 + projects/detector/private/Distribution1D.cxx | 3 + .../private/ExponentialDistribution1D.cxx | 3 + projects/detector/private/MaterialModel.cxx | 3 + .../private/PolynomialDistribution1D.cxx | 3 + projects/detector/private/RadialAxis1D.cxx | 3 + ...dialAxisExponentialDensityDistribution.cxx | 4 + ...adialAxisPolynomialDensityDistribution.cxx | 9 ++ projects/detector/public/SIREN/detector.h | 26 +++ .../detector/public/SIREN/detector/Axis1D.h | 9 +- .../public/SIREN/detector/CartesianAxis1D.h | 2 + .../CartesianAxisDensityDistribution.h | 7 +- ...tesianAxisExponentialDensityDistribution.h | 2 + ...rtesianAxisPolynomialDensityDistribution.h | 2 + .../detector/ConstantDensityDistribution.h | 9 +- .../SIREN/detector/ConstantDistribution1D.h | 8 +- .../SIREN/detector/DensityDistribution.h | 9 +- .../SIREN/detector/DensityDistribution1D.h | 10 +- .../public/SIREN/detector/DetectorModel.h | 2 + .../public/SIREN/detector/Distribution1D.h | 11 +- .../detector/ExponentialDistribution1D.h | 8 +- .../public/SIREN/detector/MaterialModel.h | 4 +- .../SIREN/detector/PolynomialDistribution1D.h | 8 +- .../public/SIREN/detector/RadialAxis1D.h | 2 + ...RadialAxisExponentialDensityDistribution.h | 2 + .../RadialAxisPolynomialDensityDistribution.h | 7 +- .../public/SIREN/detector/serializable.h | 23 +++ projects/distributions/CMakeLists.txt | 5 +- .../public/SIREN/distributions.h | 37 +++++ .../public/SIREN/distributions/serializable.h | 37 +++++ projects/geometry/CMakeLists.txt | 7 +- projects/geometry/private/Geometry.cxx | 3 + projects/geometry/private/Sphere.cxx | 3 + projects/geometry/public/SIREN/geometry.h | 13 ++ .../geometry/public/SIREN/geometry/Geometry.h | 3 + .../geometry/public/SIREN/geometry/Sphere.h | 4 +- .../public/SIREN/geometry/serializable.h | 12 ++ projects/injection/CMakeLists.txt | 11 +- .../private/pybindings/injection.cxx | 35 +++- projects/injection/public/SIREN/injection.h | 9 ++ .../public/SIREN/injection/Injector.h | 2 - .../public/SIREN/injection/Weighter.h | 7 +- .../public/SIREN/injection/serializable.h | 8 + projects/interactions/CMakeLists.txt | 5 +- .../interactions/public/SIREN/interactions.h | 21 +++ .../public/SIREN/interactions/HNLDecay.h | 2 +- .../public/SIREN/interactions/serializable.h | 16 ++ projects/math/CMakeLists.txt | 6 +- projects/math/public/SIREN/math.h | 13 ++ .../math/public/SIREN/math/serializable.h | 11 ++ projects/serialization/CMakeLists.txt | 14 +- .../serialization/private/serialization.cxx | 11 ++ .../public/SIREN/serialization/ByteString.h | 104 ++++++++++++ projects/utilities/CMakeLists.txt | 5 +- projects/utilities/private/Interpolator.cxx | 19 +++ projects/utilities/public/SIREN/utilities.h | 13 ++ .../public/SIREN/utilities/Interpolator.h | 17 +- .../public/SIREN/utilities/serializable.h | 5 + python/Injector.py | 31 +++- python/Weighter.py | 4 +- python/__init__.py | 6 +- vendor/cereal | 2 +- vendor/photospline | 2 +- 80 files changed, 861 insertions(+), 174 deletions(-) create mode 100644 projects/dataclasses/public/SIREN/dataclasses.h create mode 100644 projects/dataclasses/public/SIREN/dataclasses/serializable.h create mode 100644 projects/detector/private/CartesianAxisDensityDistribution.cxx create mode 100644 projects/detector/private/CartesianAxisExponentialDensityDistribution.cxx create mode 100644 projects/detector/private/CartesianAxisPolynomialDensityDistribution.cxx create mode 100644 projects/detector/private/ConstantDensityDistribution.cxx create mode 100644 projects/detector/private/DensityDistribution1D.cxx create mode 100644 projects/detector/private/RadialAxisExponentialDensityDistribution.cxx create mode 100644 projects/detector/private/RadialAxisPolynomialDensityDistribution.cxx create mode 100644 projects/detector/public/SIREN/detector.h create mode 100644 projects/detector/public/SIREN/detector/serializable.h create mode 100644 projects/distributions/public/SIREN/distributions.h create mode 100644 projects/distributions/public/SIREN/distributions/serializable.h create mode 100644 projects/geometry/public/SIREN/geometry.h create mode 100644 projects/geometry/public/SIREN/geometry/serializable.h create mode 100644 projects/injection/public/SIREN/injection.h create mode 100644 projects/injection/public/SIREN/injection/serializable.h create mode 100644 projects/interactions/public/SIREN/interactions.h create mode 100644 projects/interactions/public/SIREN/interactions/serializable.h create mode 100644 projects/math/public/SIREN/math.h create mode 100644 projects/math/public/SIREN/math/serializable.h create mode 100644 projects/serialization/private/serialization.cxx create mode 100644 projects/serialization/public/SIREN/serialization/ByteString.h create mode 100644 projects/utilities/public/SIREN/utilities.h create mode 100644 projects/utilities/public/SIREN/utilities/serializable.h diff --git a/.gitmodules b/.gitmodules index fd9eb6b5f..1ef853744 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,7 +13,7 @@ url = https://github.com/austinschneider/delabella.git [submodule "vendor/photospline"] path = vendor/photospline - url = https://github.com/austinschneider/photospline.git + url = https://github.com/icecube/photospline.git [submodule "vendor/NamedType"] path = vendor/NamedType url = https://github.com/joboccara/NamedType.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 6dcf03d54..1e22a18ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR) cmake_policy(VERSION 3.20) if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") + set(CMAKE_POLICY_DEFAULT_CMP0042 NEW) + cmake_policy(SET CMP0042 NEW) + set(CMAKE_POLICY_DEFAULT_CMP0068 NEW) + cmake_policy(SET CMP0068 NEW) set(MACOSX TRUE) endif() @@ -36,24 +40,50 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") endif() -# Create an interface library for SIREN compile options -add_library(siren_compile_options INTERFACE) +function(apply_siren_compile_options target) + # Check if the target is an INTERFACE target + get_target_property(target_type ${target} TYPE) + get_target_property(target_imported ${target} IMPORTED) -# Specify the compile options -target_compile_options(siren_compile_options INTERFACE - -O2 - -Wall - -fPIC - $<$:-g> - $<$:-O0> - $<$:-O2> - $<$:-s> -) + if("${target_type}" STREQUAL "INTERFACE_LIBRARY") + # Apply compile options to INTERFACE target + target_compile_options(${target} INTERFACE + -O2 + -Wall + -fPIC + $<$:-g> + $<$:-O0> + $<$:-O2> + $<$,$>:-s> + $<$:-stdlib=libc++> + ) + elseif(target_imported) + # Apply compile options to non-INTERFACE target (PRIVATE or PUBLIC) + target_compile_options(${target} INTERFACE + -O2 + -Wall + -fPIC + $<$:-g> + $<$:-O0> + $<$:-O2> + $<$,$>:-s> + $<$:-stdlib=libc++> + ) + else() + # Apply compile options to non-INTERFACE target (PRIVATE or PUBLIC) + target_compile_options(${target} PRIVATE + -O2 + -Wall + -fPIC + $<$:-g> + $<$:-O0> + $<$:-O2> + $<$,$>:-s> + $<$:-stdlib=libc++> + ) + endif() +endfunction() -# Conditionally add -stdlib=libc++ for Clang -if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(siren_compile_options INTERFACE -stdlib=libc++) -endif() # override install locations when building python extensions if(DEFINED SKBUILD_PLATLIB_DIR) @@ -75,40 +105,44 @@ include(pybind11) # load project dependencies include(rk) if(TARGET rk_static) - target_link_libraries(rk_static INTERFACE siren_compile_options) + apply_siren_compile_options(rk_static) endif() if(TARGET rk_shared) - target_link_libraries(rk_shared INTERFACE siren_compile_options) + apply_siren_compile_options(rk_shared) endif() include(cereal) if(TARGET cereal) - target_link_libraries(cereal INTERFACE siren_compile_options) + apply_siren_compile_options(cereal) endif() include(delabella) if(TARGET delabella_static) - target_link_libraries(delabella_static INTERFACE siren_compile_options) + apply_siren_compile_options(delabella_static) endif() if(TARGET delabella_shared) - target_link_libraries(delabella_shared INTERFACE siren_compile_options) + apply_siren_compile_options(delabella_shared) endif() include(CFITSIO) +if(TARGET CFITSIO) + apply_siren_compile_options(CFITSIO) +endif() include(photospline) if(TARGET photospline) - target_link_libraries(photospline INTERFACE siren_compile_options) + apply_siren_compile_options(photospline) + target_link_libraries(photospline PUBLIC CFITSIO) endif() include(googletest) if(TARGET gtest) - target_link_libraries(gtest INTERFACE siren_compile_options) + apply_siren_compile_options(gtest) endif() if(TARGET gtest_main) - target_link_libraries(gtest_main INTERFACE siren_compile_options) + apply_siren_compile_options(gtest_main) endif() if(TARGET gmock) - target_link_libraries(gmock INTERFACE siren_compile_options) + apply_siren_compile_options(gmock) endif() include(NamedType) if(TARGET NamedType) - target_link_libraries(NamedType INTERFACE siren_compile_options) + apply_siren_compile_options(NamedType) endif() # load macros for googletest @@ -128,7 +162,7 @@ add_subdirectory(projects/injection) # define the target library add_library(SIREN SHARED) set_property(TARGET SIREN PROPERTY POSITION_INDEPENDENT_CODE ON) -target_link_libraries(SIREN INTERFACE siren_compile_options) +apply_siren_compile_options(SIREN) if(DEFINED MACOSX AND MACOSX) if(CMAKE_VERSION VERSION_LESS 3.13) @@ -169,9 +203,6 @@ target_link_libraries(SIREN ) endif() -# Export siren_compile_options -install(TARGETS siren_compile_options EXPORT ${PROJECT_NAME}Config) - # define the install path normally or for python package if(DEFINED SKBUILD_PLATLIB_DIR) set_target_properties(SIREN PROPERTIES diff --git a/cmake/Packages/CFITSIO.cmake b/cmake/Packages/CFITSIO.cmake index 1ac0bdaae..4edcad79b 100644 --- a/cmake/Packages/CFITSIO.cmake +++ b/cmake/Packages/CFITSIO.cmake @@ -12,55 +12,105 @@ # CFITSIO_LDFLAGS # ################################################################################ -SET (CFITSIO_FIND_QUIETLY TRUE) -SET (CFITSIO_FIND_REQUIRED TRUE) - -IF (NOT CFITSIO_FOUND) - - # Search user environment for headers, then default paths; extract version - FIND_PATH (CFITSIO_INCLUDE_DIR fitsio.h - PATHS $ENV{CFITSIOROOT}/include - NO_DEFAULT_PATH) - FIND_PATH (CFITSIO_INCLUDE_DIR fitsio.h) - if(CFITSIO_INCLUDE_DIR) - GET_FILENAME_COMPONENT (CFITSIOROOT ${CFITSIO_INCLUDE_DIR} PATH) - else() - FIND_PATH (CFITSIO_INCLUDE_DIR cfitsio/fitsio.h - PATHS $ENV{CFITSIOROOT}/include - ) - SET(CFITSIO_INCLUDE_DIR "${CFITSIO_INCLUDE_DIR}/cfitsio" CACHE PATH "Path to cfitsio headers" FORCE) - endif() - - SET (CFITSIO_VERSION 0) - IF (CFITSIO_INCLUDE_DIR) - FILE (READ "${CFITSIO_INCLUDE_DIR}/fitsio.h" _cfitsio_VERSION) - STRING (REGEX REPLACE ".*define CFITSIO_VERSION ([0-9]+\\.[0-9]+).*" "\\1" - CFITSIO_VERSION "${_cfitsio_VERSION}") - ENDIF (CFITSIO_INCLUDE_DIR) - - # Search user environment for libraries, then default paths - FIND_LIBRARY (CFITSIO_LIBRARIES NAMES cfitsio - PATHS $ENV{CFITSIOROOT}/lib - NO_DEFAULT_PATH) - FIND_LIBRARY (CFITSIO_LIBRARIES NAMES cfitsio) - GET_FILENAME_COMPONENT (CFITSIO_LIB_DIR ${CFITSIO_LIBRARIES} PATH) - - # Set CFITSIO_FOUND and error out if cfitsio is not found - INCLUDE (FindPackageHandleStandardArgs) - FIND_PACKAGE_HANDLE_STANDARD_ARGS (CFITSIO - DEFAULT_MSG CFITSIO_LIBRARIES CFITSIO_INCLUDE_DIR) - ADD_DEFINITIONS ("-I${CFITSIO_INCLUDE_DIR}") - - IF (CFITSIO_FOUND) - # Set flags and print a status message - MESSAGE (STATUS "CFITSIO version ${CFITSIO_VERSION} found:") - - SET (CFITSIO_CPPFLAGS "-I${CFITSIO_INCLUDE_DIR}") - SET (CFITSIO_LDFLAGS "${CFITSIO_LIBRARIES}") - - MESSAGE (STATUS " * includes: ${CFITSIO_INCLUDE_DIR}") - MESSAGE (STATUS " * libs: ${CFITSIO_LIBRARIES}") - ENDIF (CFITSIO_FOUND) - -ENDIF (NOT CFITSIO_FOUND) +include(FindPackageHandleStandardArgs) + +set(CFITSIO_FIND_QUIETLY TRUE) +set(CFITSIO_FIND_REQUIRED TRUE) + +if (NOT CFITSIO_FOUND) + # Manually parse CPLUS_INCLUDE_PATH to add paths to search + if (DEFINED ENV{CPLUS_INCLUDE_PATH}) + string(REPLACE ":" ";" CFITSIO_INCLUDE_SEARCH_PATH_LIST "$ENV{CPLUS_INCLUDE_PATH}") + else() + set(CFITSIO_INCLUDE_SEARCH_PATH_LIST "") + endif() + + list(PREPEND CFITSIO_INCLUDE_SEARCH_PATH_LIST + $ENV{CFITSIOROOT}/include + ) + + # Search user environment for headers, then default paths; extract version + find_path(CFITSIO_INCLUDE_DIR fitsio.h + PATHS ${CFITSIO_INCLUDE_SEARCH_PATH_LIST} + NO_DEFAULT_PATH + ) + if(NOT CFITSIO_INCLUDE_DIR) + unset(CFITSIO_INCLUDE_DIR) + find_path(CFITSIO_INCLUDE_DIR fitsio.h) + endif() + + if(NOT CFITSIO_INCLUDE_DIR) + unset(CFITSIO_INCLUDE_DIR) + find_path(CFITSIO_INCLUDE_DIR cfitsio/fitsio.h + PATHS ${CFITSIO_INCLUDE_SEARCH_PATH_LIST} + NO_DEFAULT_PATH + ) + if(CFITSIO_INCLUDE_DIR) + set(CFITSIO_INCLUDE_DIR "${CFITSIO_INCLUDE_DIR}/cfitsio" CACHE PATH "Path to cfitsio headers" FORCE) + endif() + endif() + + if(NOT CFITSIO_INCLUDE_DIR) + unset(CFITSIO_INCLUDE_DIR) + find_path(CFITSIO_INCLUDE_DIR cfitsio/fitsio.h) + if(CFITSIO_INCLUDE_DIR) + set(CFITSIO_INCLUDE_DIR "${CFITSIO_INCLUDE_DIR}/cfitsio" CACHE PATH "Path to cfitsio headers" FORCE) + endif() + endif() + + if (CFITSIO_INCLUDE_DIR AND EXISTS "${CFITSIO_INCLUDE_DIR}/fitsio.h") + get_filename_component(CFITSIOROOT ${CFITSIO_INCLUDE_DIR} PATH) + set(CFITSIO_VERSION 0) + file(STRINGS "${CFITSIO_INCLUDE_DIR}/fitsio.h" _cfitsio_VERSION REGEX "#define CFITSIO_VERSION[ \t]+([0-9]+\.[0-9]+)") + string(REGEX REPLACE ".*#define CFITSIO_VERSION[ \t]+([0-9]+\.[0-9]+).*" "\\1" CFITSIO_VERSION "${_cfitsio_VERSION}") + else() + set(CFITSIO_INCLUDE_DIR "CFITSIO_INCLUDE_DIR-NOTFOUND") + endif() + + if (DEFINED ENV{LD_LIBRARY_PATH}) + string(REPLACE ":" ";" CFITSIO_LIBRARY_SEARCH_PATH_LIST "$ENV{LD_LIBRARY_PATH}") + else() + set(CFITSIO_LIBRARY_SEARCH_PATH_LIST "") + endif() + + # Search user environment for libraries, then default paths + find_library(CFITSIO_LIBRARIES cfitsio + PATHS ${CFITSIO_LIBRARY_SEARCH_PATH_LIST} + NO_DEFAULT_PATH + ) + + if(NOT CFITSIO_LIBRARIES) + find_library(CFITSIO_LIBRARIES NAMES cfitsio) + endif() + + if (CFITSIO_LIBRARIES) + get_filename_component(CFITSIO_LIB_DIR ${CFITSIO_LIBRARIES} PATH) + else() + set(CFITSIO_LIBRARIES "CFITSIO_LIBRARIES-NOTFOUND") + endif() + + # Set CFITSIO_FOUND and error out if cfitsio is not found + find_package_handle_standard_args(CFITSIO + REQUIRED_VARS CFITSIO_LIBRARIES CFITSIO_INCLUDE_DIR + VERSION_VAR CFITSIO_VERSION + ) + + if (CFITSIO_FOUND) + # Set flags and print a status message + message(STATUS "CFITSIO version ${CFITSIO_VERSION} found:") + + set(CFITSIO_CPPFLAGS "-I${CFITSIO_INCLUDE_DIR}") + set(CFITSIO_LDFLAGS "${CFITSIO_LIBRARIES}") + + message(STATUS " * includes: ${CFITSIO_INCLUDE_DIR}") + message(STATUS " * libs: ${CFITSIO_LIBRARIES}") + + add_library(CFITSIO SHARED IMPORTED) + target_include_directories(CFITSIO INTERFACE ${CFITSIO_INCLUDE_DIR}) + set_target_properties(CFITSIO PROPERTIES + IMPORTED_LOCATION ${CFITSIO_LIBRARIES}) + else() + message(WARNING "CFITSIO not found. Please ensure CFITSIO is installed and the environment variables CFITSIOROOT, CPLUS_INCLUDE_PATH, LIBRARY_PATH, and LD_LIBRARY_PATH are set correctly.") + endif() +endif() diff --git a/projects/dataclasses/CMakeLists.txt b/projects/dataclasses/CMakeLists.txt index 9a5448565..6575de97f 100644 --- a/projects/dataclasses/CMakeLists.txt +++ b/projects/dataclasses/CMakeLists.txt @@ -17,14 +17,13 @@ target_include_directories(SIREN_dataclasses PUBLIC ) target_link_libraries(SIREN_dataclasses - INTERFACE - siren_compile_options PUBLIC photospline - SIREN_serialization SIREN_utilities + SIREN_serialization SIREN_math ) +apply_siren_compile_options(SIREN_dataclasses) install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/dataclasses/public/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} diff --git a/projects/dataclasses/private/pybindings/dataclasses.cxx b/projects/dataclasses/private/pybindings/dataclasses.cxx index 8687aead6..353dadeb7 100644 --- a/projects/dataclasses/private/pybindings/dataclasses.cxx +++ b/projects/dataclasses/private/pybindings/dataclasses.cxx @@ -8,6 +8,9 @@ #include "../../public/SIREN/dataclasses/InteractionSignature.h" #include "../../public/SIREN/dataclasses/InteractionRecord.h" #include "../../public/SIREN/dataclasses/InteractionTree.h" +#include "../../../serialization/public/SIREN/serialization/ByteString.h" + +#include "SIREN/dataclasses/serializable.h" #include #include @@ -52,6 +55,10 @@ PYBIND11_MODULE(dataclasses, m) { .def_readwrite("length",&Particle::length) .def_readwrite("helicity",&Particle::helicity) .def("generate_id",&Particle::GenerateID) + .def(pybind11::pickle( + &(siren::serialization::pickle_save), + &(siren::serialization::pickle_load) + )) ; py::enum_(m, "ParticleType", py::arithmetic()) @@ -67,6 +74,10 @@ PYBIND11_MODULE(dataclasses, m) { .def_readwrite("primary_type",&InteractionSignature::primary_type) .def_readwrite("target_type",&InteractionSignature::target_type) .def_readwrite("secondary_types",&InteractionSignature::secondary_types) + .def(pybind11::pickle( + &(siren::serialization::pickle_save), + &(siren::serialization::pickle_load) + )) ; py::class_>(m, "PrimaryDistributionRecord") @@ -174,6 +185,10 @@ PYBIND11_MODULE(dataclasses, m) { .def_readwrite("secondary_momenta",&InteractionRecord::secondary_momenta) .def_readwrite("secondary_helicities",&InteractionRecord::secondary_helicities) .def_readwrite("interaction_parameters",&InteractionRecord::interaction_parameters) + .def(pybind11::pickle( + &(siren::serialization::pickle_save), + &(siren::serialization::pickle_load) + )) ; py::class_>(m, "InteractionTreeDatum") @@ -182,6 +197,10 @@ PYBIND11_MODULE(dataclasses, m) { .def_readwrite("parent",&InteractionTreeDatum::parent) .def_readwrite("daughters",&InteractionTreeDatum::daughters) .def("depth",&InteractionTreeDatum::depth) + .def(pybind11::pickle( + &(siren::serialization::pickle_save), + &(siren::serialization::pickle_load) + )) ; py::class_>(m, "InteractionTree") @@ -189,6 +208,10 @@ PYBIND11_MODULE(dataclasses, m) { .def_readwrite("tree",&InteractionTree::tree) .def("add_entry",static_cast (InteractionTree::*)(InteractionTreeDatum&,std::shared_ptr)>(&InteractionTree::add_entry)) .def("add_entry",static_cast (InteractionTree::*)(InteractionRecord&,std::shared_ptr)>(&InteractionTree::add_entry)) + .def(pybind11::pickle( + &(siren::serialization::pickle_save), + &(siren::serialization::pickle_load) + )) ; m.def("SaveInteractionTrees",&SaveInteractionTrees); diff --git a/projects/dataclasses/public/SIREN/dataclasses.h b/projects/dataclasses/public/SIREN/dataclasses.h new file mode 100644 index 000000000..6c12dcbcb --- /dev/null +++ b/projects/dataclasses/public/SIREN/dataclasses.h @@ -0,0 +1,12 @@ +#ifndef SIREN_dataclasses_dataclasses_H +#define SIREN_dataclasses_dataclasses_H + +#include "SIREN/dataclasses/DecaySignature.h" +#include "SIREN/dataclasses/InteractionRecord.h" +#include "SIREN/dataclasses/InteractionSignature.h" +#include "SIREN/dataclasses/InteractionTree.h" +#include "SIREN/dataclasses/Particle.h" +#include "SIREN/dataclasses/ParticleID.h" +#include "SIREN/dataclasses/ParticleType.h" + +#endif // SIREN_dataclasses_dataclasses_H diff --git a/projects/dataclasses/public/SIREN/dataclasses/serializable.h b/projects/dataclasses/public/SIREN/dataclasses/serializable.h new file mode 100644 index 000000000..bc3108097 --- /dev/null +++ b/projects/dataclasses/public/SIREN/dataclasses/serializable.h @@ -0,0 +1,12 @@ +#ifndef SIREN_dataclasses_serializable_H +#define SIREN_dataclasses_serializable_H + +#include "SIREN/dataclasses/DecaySignature.h" +#include "SIREN/dataclasses/InteractionRecord.h" +#include "SIREN/dataclasses/InteractionSignature.h" +#include "SIREN/dataclasses/InteractionTree.h" +#include "SIREN/dataclasses/Particle.h" +#include "SIREN/dataclasses/ParticleID.h" +#include "SIREN/dataclasses/ParticleType.h" + +#endif // SIREN_dataclasses_serializable_H diff --git a/projects/detector/CMakeLists.txt b/projects/detector/CMakeLists.txt index 4a132bd7c..8f00cee83 100644 --- a/projects/detector/CMakeLists.txt +++ b/projects/detector/CMakeLists.txt @@ -13,6 +13,13 @@ LIST (APPEND detector_SOURCES ${PROJECT_SOURCE_DIR}/projects/detector/private/ExponentialDistribution1D.cxx ${PROJECT_SOURCE_DIR}/projects/detector/private/DensityDistribution.cxx + ${PROJECT_SOURCE_DIR}/projects/detector/private/DensityDistribution1D.cxx + ${PROJECT_SOURCE_DIR}/projects/detector/private/ConstantDensityDistribution.cxx + ${PROJECT_SOURCE_DIR}/projects/detector/private/CartesianAxisDensityDistribution.cxx + ${PROJECT_SOURCE_DIR}/projects/detector/private/CartesianAxisPolynomialDensityDistribution.cxx + ${PROJECT_SOURCE_DIR}/projects/detector/private/CartesianAxisExponentialDensityDistribution.cxx + ${PROJECT_SOURCE_DIR}/projects/detector/private/RadialAxisPolynomialDensityDistribution.cxx + ${PROJECT_SOURCE_DIR}/projects/detector/private/RadialAxisExponentialDensityDistribution.cxx ${PROJECT_SOURCE_DIR}/projects/detector/private/DetectorModel.cxx ${PROJECT_SOURCE_DIR}/projects/detector/private/MaterialModel.cxx ${PROJECT_SOURCE_DIR}/projects/detector/private/Path.cxx @@ -25,18 +32,17 @@ target_include_directories(SIREN_detector PUBLIC ) target_link_libraries(SIREN_detector - INTERFACE - siren_compile_options - PRIVATE - $ PUBLIC photospline - SIREN_serialization SIREN_utilities + SIREN_serialization SIREN_math SIREN_dataclasses SIREN_geometry + PRIVATE + $ ) +apply_siren_compile_options(SIREN_detector) install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/detector/public/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} diff --git a/projects/detector/private/Axis1D.cxx b/projects/detector/private/Axis1D.cxx index edaa27a63..600d512f4 100644 --- a/projects/detector/private/Axis1D.cxx +++ b/projects/detector/private/Axis1D.cxx @@ -27,3 +27,6 @@ bool Axis1D::operator!=(const Axis1D& axis) const { } // namespace siren } // namespace detector + +CEREAL_REGISTER_DYNAMIC_INIT(siren_Axis1D); + diff --git a/projects/detector/private/CartesianAxis1D.cxx b/projects/detector/private/CartesianAxis1D.cxx index d74e96265..a4d13de32 100644 --- a/projects/detector/private/CartesianAxis1D.cxx +++ b/projects/detector/private/CartesianAxis1D.cxx @@ -39,3 +39,6 @@ double CartesianAxis1D::GetdX(const math::Vector3D& xi, const math::Vector3D& di } // namespace siren } // namespace detector + +CEREAL_REGISTER_DYNAMIC_INIT(siren_CartesianAxis1D); + diff --git a/projects/detector/private/CartesianAxisDensityDistribution.cxx b/projects/detector/private/CartesianAxisDensityDistribution.cxx new file mode 100644 index 000000000..682cdda29 --- /dev/null +++ b/projects/detector/private/CartesianAxisDensityDistribution.cxx @@ -0,0 +1,4 @@ +#include "SIREN/detector/CartesianAxisDensityDistribution.h" + +CEREAL_REGISTER_DYNAMIC_INIT(siren_CartesianAxisDensityDistribution); + diff --git a/projects/detector/private/CartesianAxisExponentialDensityDistribution.cxx b/projects/detector/private/CartesianAxisExponentialDensityDistribution.cxx new file mode 100644 index 000000000..18c162e75 --- /dev/null +++ b/projects/detector/private/CartesianAxisExponentialDensityDistribution.cxx @@ -0,0 +1,4 @@ +#include "SIREN/detector/CartesianAxisExponentialDensityDistribution.h" + +CEREAL_REGISTER_DYNAMIC_INIT(siren_CartesianAxisExponentialDensityDistribution); + diff --git a/projects/detector/private/CartesianAxisPolynomialDensityDistribution.cxx b/projects/detector/private/CartesianAxisPolynomialDensityDistribution.cxx new file mode 100644 index 000000000..097c7de13 --- /dev/null +++ b/projects/detector/private/CartesianAxisPolynomialDensityDistribution.cxx @@ -0,0 +1,4 @@ +#include "SIREN/detector/CartesianAxisPolynomialDensityDistribution.h" + +CEREAL_REGISTER_DYNAMIC_INIT(siren_CartesianAxisPolynomialDensityDistribution); + diff --git a/projects/detector/private/ConstantDensityDistribution.cxx b/projects/detector/private/ConstantDensityDistribution.cxx new file mode 100644 index 000000000..d6a9ff984 --- /dev/null +++ b/projects/detector/private/ConstantDensityDistribution.cxx @@ -0,0 +1,9 @@ +#include "SIREN/detector/ConstantDensityDistribution.h" + +// Explicit template instantiation +template class siren::detector::DensityDistribution1D< + siren::detector::CartesianAxis1D, + siren::detector::ConstantDistribution1D>; + +CEREAL_REGISTER_DYNAMIC_INIT(siren_ConstantDensityDistribution); + diff --git a/projects/detector/private/ConstantDistribution1D.cxx b/projects/detector/private/ConstantDistribution1D.cxx index 513af79bb..88fe291fb 100644 --- a/projects/detector/private/ConstantDistribution1D.cxx +++ b/projects/detector/private/ConstantDistribution1D.cxx @@ -41,3 +41,6 @@ double ConstantDistribution1D::Evaluate(double x) const { } // namespace siren } // namespace detector + +CEREAL_REGISTER_DYNAMIC_INIT(siren_ConstantDistribution1D); + diff --git a/projects/detector/private/DensityDistribution.cxx b/projects/detector/private/DensityDistribution.cxx index 8d8743108..873bd0fda 100644 --- a/projects/detector/private/DensityDistribution.cxx +++ b/projects/detector/private/DensityDistribution.cxx @@ -21,3 +21,6 @@ bool DensityDistribution::operator!=(const DensityDistribution& dens_distr) cons } // namespace siren } // namespace detector + +CEREAL_REGISTER_DYNAMIC_INIT(siren_DensityDistribution); + diff --git a/projects/detector/private/DensityDistribution1D.cxx b/projects/detector/private/DensityDistribution1D.cxx new file mode 100644 index 000000000..d65683390 --- /dev/null +++ b/projects/detector/private/DensityDistribution1D.cxx @@ -0,0 +1,4 @@ +#include "SIREN/detector/DensityDistribution1D.h" + +CEREAL_REGISTER_DYNAMIC_INIT(siren_DensityDistribution1D); + diff --git a/projects/detector/private/DetectorModel.cxx b/projects/detector/private/DetectorModel.cxx index 3bdc63051..3a19ea23d 100644 --- a/projects/detector/private/DetectorModel.cxx +++ b/projects/detector/private/DetectorModel.cxx @@ -1757,3 +1757,6 @@ double DetectorModel::GetTargetMass(siren::dataclasses::ParticleType target) con double molar_mass = materials_.GetMolarMass(target); // grams per mole return molar_mass * siren::utilities::Constants::GeV_per_amu; } + +CEREAL_REGISTER_DYNAMIC_INIT(siren_DetectorModel); + diff --git a/projects/detector/private/Distribution1D.cxx b/projects/detector/private/Distribution1D.cxx index f6478801c..c2e0f1ef3 100644 --- a/projects/detector/private/Distribution1D.cxx +++ b/projects/detector/private/Distribution1D.cxx @@ -19,3 +19,6 @@ bool Distribution1D::operator!=(const Distribution1D& dist) const { } // namespace siren } // namespace detector + +CEREAL_REGISTER_DYNAMIC_INIT(siren_Distribution1D); + diff --git a/projects/detector/private/ExponentialDistribution1D.cxx b/projects/detector/private/ExponentialDistribution1D.cxx index d9c231e1c..f20663942 100644 --- a/projects/detector/private/ExponentialDistribution1D.cxx +++ b/projects/detector/private/ExponentialDistribution1D.cxx @@ -41,3 +41,6 @@ double ExponentialDistribution1D::Evaluate(double x) const { } // namespace siren } // namespace detector + +CEREAL_REGISTER_DYNAMIC_INIT(siren_ExponentialDistribution1D); + diff --git a/projects/detector/private/MaterialModel.cxx b/projects/detector/private/MaterialModel.cxx index f19ed8f45..871abb59d 100644 --- a/projects/detector/private/MaterialModel.cxx +++ b/projects/detector/private/MaterialModel.cxx @@ -495,3 +495,6 @@ double MaterialModel::GetEmpericalNuclearBindingEnergy(int strange_count, int ne + L * (c0 * lambda0_mass - c1 - c2 * std::abs(S) / std::pow(A, 2.0/3.0)); return binding_energy_in_MeV * 1e-3; // GeV } + +CEREAL_REGISTER_DYNAMIC_INIT(siren_MaterialModel); + diff --git a/projects/detector/private/PolynomialDistribution1D.cxx b/projects/detector/private/PolynomialDistribution1D.cxx index f86a6c3ef..1a5552ec6 100644 --- a/projects/detector/private/PolynomialDistribution1D.cxx +++ b/projects/detector/private/PolynomialDistribution1D.cxx @@ -54,3 +54,6 @@ double PolynomialDistribution1D::Evaluate(double x) const { } // namespace siren } // namespace detector + +CEREAL_REGISTER_DYNAMIC_INIT(siren_PolynomialDistribution1D); + diff --git a/projects/detector/private/RadialAxis1D.cxx b/projects/detector/private/RadialAxis1D.cxx index fadcd199f..a66dbea6a 100644 --- a/projects/detector/private/RadialAxis1D.cxx +++ b/projects/detector/private/RadialAxis1D.cxx @@ -40,3 +40,6 @@ double RadialAxis1D::GetdX(const math::Vector3D& xi, const math::Vector3D& direc } // namespace siren } // namespace detector + +CEREAL_REGISTER_DYNAMIC_INIT(siren_RadialAxis1D); + diff --git a/projects/detector/private/RadialAxisExponentialDensityDistribution.cxx b/projects/detector/private/RadialAxisExponentialDensityDistribution.cxx new file mode 100644 index 000000000..d15219120 --- /dev/null +++ b/projects/detector/private/RadialAxisExponentialDensityDistribution.cxx @@ -0,0 +1,4 @@ +#include "SIREN/detector/RadialAxisExponentialDensityDistribution.h" + +CEREAL_REGISTER_DYNAMIC_INIT(siren_RadialAxisExponentialDensityDistribution); + diff --git a/projects/detector/private/RadialAxisPolynomialDensityDistribution.cxx b/projects/detector/private/RadialAxisPolynomialDensityDistribution.cxx new file mode 100644 index 000000000..16835d4e1 --- /dev/null +++ b/projects/detector/private/RadialAxisPolynomialDensityDistribution.cxx @@ -0,0 +1,9 @@ +#include "SIREN/detector/RadialAxisPolynomialDensityDistribution.h" + +// Explicit template instantiation +template class siren::detector::DensityDistribution1D< + siren::detector::RadialAxis1D, + siren::detector::PolynomialDistribution1D>; + +CEREAL_REGISTER_DYNAMIC_INIT(siren_RadialAxisPolynomialDensityDistribution); + diff --git a/projects/detector/public/SIREN/detector.h b/projects/detector/public/SIREN/detector.h new file mode 100644 index 000000000..9fc8dafd2 --- /dev/null +++ b/projects/detector/public/SIREN/detector.h @@ -0,0 +1,26 @@ +#ifndef SIREN_detector_detector_H +#define SIREN_detector_detector_H + +#include "SIREN/detector/Axis1D.h" +#include "SIREN/detector/CartesianAxis1D.h" +#include "SIREN/detector/CartesianAxisDensityDistribution.h" +#include "SIREN/detector/CartesianAxisExponentialDensityDistribution.h" +#include "SIREN/detector/CartesianAxisPolynomialDensityDistribution.h" +#include "SIREN/detector/ConstantDensityDistribution.h" +#include "SIREN/detector/ConstantDistribution1D.h" +#include "SIREN/detector/Coordinates.h" +#include "SIREN/detector/DensityDistribution.h" +#include "SIREN/detector/DensityDistribution1D.h" +#include "SIREN/detector/DetectorModel.h" +#include "SIREN/detector/DetectorModel.tcc" +#include "SIREN/detector/Distribution1D.h" +#include "SIREN/detector/ExponentialDistribution1D.h" +#include "SIREN/detector/MaterialModel.h" +#include "SIREN/detector/MaterialModel.tcc" +#include "SIREN/detector/Path.h" +#include "SIREN/detector/PolynomialDistribution1D.h" +#include "SIREN/detector/RadialAxis1D.h" +#include "SIREN/detector/RadialAxisExponentialDensityDistribution.h" +#include "SIREN/detector/RadialAxisPolynomialDensityDistribution.h" + +#endif // SIREN_detector_detector_H diff --git a/projects/detector/public/SIREN/detector/Axis1D.h b/projects/detector/public/SIREN/detector/Axis1D.h index d4e393152..bc9170234 100644 --- a/projects/detector/public/SIREN/detector/Axis1D.h +++ b/projects/detector/public/SIREN/detector/Axis1D.h @@ -1,6 +1,6 @@ #pragma once -#ifndef SIREN_Axis1D_H -#define SIREN_Axis1D_H +#ifndef SIREN_detector_Axis1D_H +#define SIREN_detector_Axis1D_H #include // for shared_ptr #include // for uint32_t @@ -57,5 +57,8 @@ friend cereal::access; } // namespace siren CEREAL_CLASS_VERSION(siren::detector::Axis1D, 0); +CEREAL_REGISTER_TYPE(siren::detector::Axis1D); -#endif // SIREN_Axis1D_H +CEREAL_FORCE_DYNAMIC_INIT(siren_Axis1D); + +#endif // SIREN_detector_Axis1D_H diff --git a/projects/detector/public/SIREN/detector/CartesianAxis1D.h b/projects/detector/public/SIREN/detector/CartesianAxis1D.h index 9734d3a98..095cc7c67 100644 --- a/projects/detector/public/SIREN/detector/CartesianAxis1D.h +++ b/projects/detector/public/SIREN/detector/CartesianAxis1D.h @@ -53,4 +53,6 @@ CEREAL_CLASS_VERSION(siren::detector::CartesianAxis1D, 0); CEREAL_REGISTER_TYPE(siren::detector::CartesianAxis1D); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::detector::Axis1D, siren::detector::CartesianAxis1D); +CEREAL_FORCE_DYNAMIC_INIT(siren_CartesianAxis1D); + #endif // SIREN_CartesianAxis1D_H diff --git a/projects/detector/public/SIREN/detector/CartesianAxisDensityDistribution.h b/projects/detector/public/SIREN/detector/CartesianAxisDensityDistribution.h index c5d07e837..13b697ee1 100644 --- a/projects/detector/public/SIREN/detector/CartesianAxisDensityDistribution.h +++ b/projects/detector/public/SIREN/detector/CartesianAxisDensityDistribution.h @@ -18,6 +18,7 @@ #include "SIREN/detector/CartesianAxis1D.h" #include "SIREN/detector/DensityDistribution.h" #include "SIREN/detector/DensityDistribution1D.h" +#include "SIREN/detector/ConstantDistribution1D.h" namespace siren { namespace detector { @@ -46,8 +47,8 @@ class DensityDistribution1D create() override { - return std::shared_ptr(new T(*this)); + std::shared_ptr create() const override { + return std::shared_ptr(new T(*this)); }; double Derivative(const math::Vector3D& xi, @@ -157,4 +158,6 @@ class DensityDistribution1D #include +#include #include #include -#include #include #include "SIREN/math/Vector3D.h" @@ -121,6 +121,9 @@ class DensityDistribution1D; + // Define the specialization that we plan to use typedef DensityDistribution1D ConstantDensityDistribution; @@ -134,4 +137,6 @@ CEREAL_CLASS_VERSION(siren::detector::ConstantDensityDistribution, 0); CEREAL_REGISTER_TYPE(siren::detector::ConstantDensityDistribution); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::detector::DensityDistribution, siren::detector::ConstantDensityDistribution); -#endif // SIREN_ConstantDensityDistribution.h +CEREAL_FORCE_DYNAMIC_INIT(siren_ConstantDensityDistribution); + +#endif // SIREN_ConstantDensityDistribution_H diff --git a/projects/detector/public/SIREN/detector/ConstantDistribution1D.h b/projects/detector/public/SIREN/detector/ConstantDistribution1D.h index 279a00d96..0b422aadb 100644 --- a/projects/detector/public/SIREN/detector/ConstantDistribution1D.h +++ b/projects/detector/public/SIREN/detector/ConstantDistribution1D.h @@ -1,6 +1,6 @@ #pragma once -#ifndef SIREN_ConstantDistribution1D_H -#define SIREN_ConstantDistribution1D_H +#ifndef SIREN_detector_ConstantDistribution1D_H +#define SIREN_detector_ConstantDistribution1D_H #include // for shared_ptr #include // for uint32_t @@ -50,4 +50,6 @@ CEREAL_CLASS_VERSION(siren::detector::ConstantDistribution1D, 0); CEREAL_REGISTER_TYPE(siren::detector::ConstantDistribution1D); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::detector::Distribution1D, siren::detector::ConstantDistribution1D); -#endif // SIREN_ConstantDistribution1D_H +CEREAL_FORCE_DYNAMIC_INIT(siren_ConstantDistribution1D); + +#endif // SIREN_detector_ConstantDistribution1D_H diff --git a/projects/detector/public/SIREN/detector/DensityDistribution.h b/projects/detector/public/SIREN/detector/DensityDistribution.h index 054052833..4bb006923 100644 --- a/projects/detector/public/SIREN/detector/DensityDistribution.h +++ b/projects/detector/public/SIREN/detector/DensityDistribution.h @@ -26,8 +26,8 @@ ******************************************************************************/ #pragma once -#ifndef SIREN_DensityDistribution_H -#define SIREN_DensityDistribution_H +#ifndef SIREN_detector_DensityDistribution_H +#define SIREN_detector_DensityDistribution_H #include // for basic_string #include // for shared_ptr @@ -97,6 +97,9 @@ friend cereal::access; } // namespace siren CEREAL_CLASS_VERSION(siren::detector::DensityDistribution, 0); +CEREAL_REGISTER_TYPE(siren::detector::DensityDistribution) -#endif // SIREN_DensityDistribution_H +CEREAL_FORCE_DYNAMIC_INIT(siren_DensityDistribution); + +#endif // SIREN_detector_DensityDistribution_H diff --git a/projects/detector/public/SIREN/detector/DensityDistribution1D.h b/projects/detector/public/SIREN/detector/DensityDistribution1D.h index 4c3ea0539..4df1a1fba 100644 --- a/projects/detector/public/SIREN/detector/DensityDistribution1D.h +++ b/projects/detector/public/SIREN/detector/DensityDistribution1D.h @@ -7,25 +7,27 @@ #include #include +#include #include #include -#include #include #include "SIREN/math/Vector3D.h" #include "SIREN/math/Polynomial.h" #include "SIREN/detector/Axis1D.h" +#include "SIREN/detector/CartesianAxis1D.h" #include "SIREN/detector/Distribution1D.h" #include "SIREN/detector/DensityDistribution.h" +#include "SIREN/detector/ConstantDistribution1D.h" #include "SIREN/utilities/Integration.h" namespace siren { namespace detector { -template ::value && std::is_base_of::value>::type> -class DensityDistribution1D +template ::value && std::is_base_of::value && not (std::is_same::value && std::is_same::value)>::type> +class __attribute__((visibility("default"))) DensityDistribution1D : public DensityDistribution { using T = DensityDistribution1D; private: @@ -150,4 +152,6 @@ class DensityDistribution1D } // namespace detector } // namespace siren +CEREAL_FORCE_DYNAMIC_INIT(siren_DensityDistribution1D); + #endif // SIREN_DensityDistribution1D.h diff --git a/projects/detector/public/SIREN/detector/DetectorModel.h b/projects/detector/public/SIREN/detector/DetectorModel.h index 7b63ae2d1..58db1e35b 100644 --- a/projects/detector/public/SIREN/detector/DetectorModel.h +++ b/projects/detector/public/SIREN/detector/DetectorModel.h @@ -296,4 +296,6 @@ std::ostream& operator<<(std::ostream& oss, siren::detector::DetectorSector & bc CEREAL_CLASS_VERSION(siren::detector::DetectorModel, 0); +CEREAL_FORCE_DYNAMIC_INIT(siren_DetectorModel); + #endif // SIREN_DetectorModel_H diff --git a/projects/detector/public/SIREN/detector/Distribution1D.h b/projects/detector/public/SIREN/detector/Distribution1D.h index 8ae41bb5a..757319ad8 100644 --- a/projects/detector/public/SIREN/detector/Distribution1D.h +++ b/projects/detector/public/SIREN/detector/Distribution1D.h @@ -1,12 +1,14 @@ #pragma once -#ifndef SIREN_Distribution1D_H -#define SIREN_Distribution1D_H +#ifndef SIREN_detector_Distribution1D_H +#define SIREN_detector_Distribution1D_H #include // for shared_ptr #include // for uint32_t #include #include #include +#include +#include namespace siren { namespace detector { @@ -32,5 +34,8 @@ friend cereal::access; } // namespace siren CEREAL_CLASS_VERSION(siren::detector::Distribution1D, 0); +CEREAL_REGISTER_TYPE(siren::detector::Distribution1D); -#endif // SIREN_Distribution1D_H +CEREAL_FORCE_DYNAMIC_INIT(siren_Distribution1D); + +#endif // SIREN_detector_Distribution1D_H diff --git a/projects/detector/public/SIREN/detector/ExponentialDistribution1D.h b/projects/detector/public/SIREN/detector/ExponentialDistribution1D.h index a2b7a14ec..b2aaff071 100644 --- a/projects/detector/public/SIREN/detector/ExponentialDistribution1D.h +++ b/projects/detector/public/SIREN/detector/ExponentialDistribution1D.h @@ -1,6 +1,6 @@ #pragma once -#ifndef SIREN_ExponentialDistribution1D_H -#define SIREN_ExponentialDistribution1D_H +#ifndef SIREN_detector_ExponentialDistribution1D_H +#define SIREN_detector_ExponentialDistribution1D_H #include // for shared_ptr #include // for uint32_t @@ -51,4 +51,6 @@ CEREAL_CLASS_VERSION(siren::detector::ExponentialDistribution1D, 0); CEREAL_REGISTER_TYPE(siren::detector::ExponentialDistribution1D); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::detector::Distribution1D, siren::detector::ExponentialDistribution1D); -#endif // SIREN_ExponentialDistribution1D_H +CEREAL_FORCE_DYNAMIC_INIT(siren_ExponentialDistribution1D); + +#endif // SIREN_detector_ExponentialDistribution1D_H diff --git a/projects/detector/public/SIREN/detector/MaterialModel.h b/projects/detector/public/SIREN/detector/MaterialModel.h index 66ba9573e..51d3a3a68 100644 --- a/projects/detector/public/SIREN/detector/MaterialModel.h +++ b/projects/detector/public/SIREN/detector/MaterialModel.h @@ -153,11 +153,13 @@ class MaterialModel { } // namespace detector } // namespace siren +#include "SIREN/detector/MaterialModel.tcc" + CEREAL_CLASS_VERSION(siren::detector::MaterialModel, 0); CEREAL_CLASS_VERSION(siren::detector::MaterialModel::Component, 0); CEREAL_CLASS_VERSION(siren::detector::MaterialModel::MaterialComponent, 0); -#include "SIREN/detector/MaterialModel.tcc" +CEREAL_FORCE_DYNAMIC_INIT(siren_MaterialModel); # endif // SIREN_MaterialModel_H diff --git a/projects/detector/public/SIREN/detector/PolynomialDistribution1D.h b/projects/detector/public/SIREN/detector/PolynomialDistribution1D.h index 5e7fcb25c..ef8981ba9 100644 --- a/projects/detector/public/SIREN/detector/PolynomialDistribution1D.h +++ b/projects/detector/public/SIREN/detector/PolynomialDistribution1D.h @@ -1,6 +1,6 @@ #pragma once -#ifndef SIREN_PolynomialDistribution1D_H -#define SIREN_PolynomialDistribution1D_H +#ifndef SIREN_detector_PolynomialDistribution1D_H +#define SIREN_detector_PolynomialDistribution1D_H #include // for shared_ptr #include // for vector @@ -60,4 +60,6 @@ CEREAL_CLASS_VERSION(siren::detector::PolynomialDistribution1D, 0); CEREAL_REGISTER_TYPE(siren::detector::PolynomialDistribution1D); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::detector::Distribution1D, siren::detector::PolynomialDistribution1D); -#endif // SIREN_PolynomialDistribution1D_H +CEREAL_FORCE_DYNAMIC_INIT(siren_PolynomialDistribution1D); + +#endif // SIREN_detector_PolynomialDistribution1D_H diff --git a/projects/detector/public/SIREN/detector/RadialAxis1D.h b/projects/detector/public/SIREN/detector/RadialAxis1D.h index c66882136..8b77faa17 100644 --- a/projects/detector/public/SIREN/detector/RadialAxis1D.h +++ b/projects/detector/public/SIREN/detector/RadialAxis1D.h @@ -54,4 +54,6 @@ CEREAL_CLASS_VERSION(siren::detector::RadialAxis1D, 0); CEREAL_REGISTER_TYPE(siren::detector::RadialAxis1D); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::detector::Axis1D, siren::detector::RadialAxis1D); +CEREAL_FORCE_DYNAMIC_INIT(siren_RadialAxis1D); + #endif // SIREN_RadialAxis1D_H diff --git a/projects/detector/public/SIREN/detector/RadialAxisExponentialDensityDistribution.h b/projects/detector/public/SIREN/detector/RadialAxisExponentialDensityDistribution.h index 04faffafa..dac04be7a 100644 --- a/projects/detector/public/SIREN/detector/RadialAxisExponentialDensityDistribution.h +++ b/projects/detector/public/SIREN/detector/RadialAxisExponentialDensityDistribution.h @@ -32,5 +32,7 @@ CEREAL_CLASS_VERSION(siren::detector::RadialAxisExponentialDensityDistribution, CEREAL_REGISTER_TYPE(siren::detector::RadialAxisExponentialDensityDistribution); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::detector::DensityDistribution, siren::detector::RadialAxisExponentialDensityDistribution); +CEREAL_FORCE_DYNAMIC_INIT(siren_RadialAxisExponentialDensityDistribution); + #endif // SIREN_RadialAxisExponentialDensityDistribution.h diff --git a/projects/detector/public/SIREN/detector/RadialAxisPolynomialDensityDistribution.h b/projects/detector/public/SIREN/detector/RadialAxisPolynomialDensityDistribution.h index 10b6bf907..888ba8fb3 100644 --- a/projects/detector/public/SIREN/detector/RadialAxisPolynomialDensityDistribution.h +++ b/projects/detector/public/SIREN/detector/RadialAxisPolynomialDensityDistribution.h @@ -158,7 +158,10 @@ class DensityDistribution1D }; */ -typedef DensityDistribution1D RadialAxisPolynomialDensityDistribution; +// Declare the explicit specialization (but do not instantiate) +extern template class DensityDistribution1D; + +typedef DensityDistribution1D RadialAxisPolynomialDensityDistribution; } // namespace detector } // namespace siren @@ -167,4 +170,6 @@ CEREAL_CLASS_VERSION(siren::detector::RadialAxisPolynomialDensityDistribution, 0 CEREAL_REGISTER_TYPE(siren::detector::RadialAxisPolynomialDensityDistribution); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::detector::DensityDistribution, siren::detector::RadialAxisPolynomialDensityDistribution); +CEREAL_FORCE_DYNAMIC_INIT(siren_RadialAxisPolynomialDensityDistribution); + #endif // SIREN_RadialAxisPolynomialDensityDistribution.h diff --git a/projects/detector/public/SIREN/detector/serializable.h b/projects/detector/public/SIREN/detector/serializable.h new file mode 100644 index 000000000..432f9e4f9 --- /dev/null +++ b/projects/detector/public/SIREN/detector/serializable.h @@ -0,0 +1,23 @@ +#ifndef SIREN_detector_serializable_H +#define SIREN_detector_serializable_H + +#include "SIREN/detector/DensityDistribution.h" +#include "SIREN/detector/Distribution1D.h" +#include "SIREN/detector/ConstantDistribution1D.h" +#include "SIREN/detector/PolynomialDistribution1D.h" +#include "SIREN/detector/ExponentialDistribution1D.h" +#include "SIREN/detector/Axis1D.h" +#include "SIREN/detector/RadialAxis1D.h" +#include "SIREN/detector/CartesianAxis1D.h" +#include "SIREN/detector/DensityDistribution1D.h" +#include "SIREN/detector/ConstantDensityDistribution.h" +#include "SIREN/detector/CartesianAxisDensityDistribution.h" +#include "SIREN/detector/CartesianAxisPolynomialDensityDistribution.h" +#include "SIREN/detector/CartesianAxisExponentialDensityDistribution.h" +#include "SIREN/detector/RadialAxisPolynomialDensityDistribution.h" +#include "SIREN/detector/RadialAxisExponentialDensityDistribution.h" +#include "SIREN/detector/MaterialModel.h" +#include "SIREN/detector/DetectorModel.h" +#include "SIREN/detector/Path.h" + +#endif // SIREN_detector_serializable_H diff --git a/projects/distributions/CMakeLists.txt b/projects/distributions/CMakeLists.txt index 897821a6f..1b73519ce 100644 --- a/projects/distributions/CMakeLists.txt +++ b/projects/distributions/CMakeLists.txt @@ -42,21 +42,20 @@ target_include_directories(SIREN_distributions PUBLIC ) target_link_libraries(SIREN_distributions - INTERFACE - siren_compile_options PRIVATE $ pybind11::embed PUBLIC photospline - SIREN_serialization SIREN_utilities + SIREN_serialization SIREN_math SIREN_dataclasses SIREN_geometry SIREN_detector SIREN_interactions ) +apply_siren_compile_options(SIREN_distributions) install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/distributions/public/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} diff --git a/projects/distributions/public/SIREN/distributions.h b/projects/distributions/public/SIREN/distributions.h new file mode 100644 index 000000000..62dbf397f --- /dev/null +++ b/projects/distributions/public/SIREN/distributions.h @@ -0,0 +1,37 @@ +#ifndef SIREN_distributions_distributions_H +#define SIREN_distributions_distributions_H + +#include "SIREN/distributions/Distributions.h" + +#include "SIREN/distributions/primary/direction/PrimaryDirectionDistribution.h" +#include "SIREN/distributions/primary/direction/Cone.h" +#include "SIREN/distributions/primary/direction/FixedDirection.h" +#include "SIREN/distributions/primary/direction/IsotropicDirection.h" + +#include "SIREN/distributions/primary/energy/PrimaryEnergyDistribution.h" +#include "SIREN/distributions/primary/energy/ModifiedMoyalPlusExponentialEnergyDistribution.h" +#include "SIREN/distributions/primary/energy/Monoenergetic.h" +#include "SIREN/distributions/primary/energy/PowerLaw.h" +#include "SIREN/distributions/primary/energy/TabulatedFluxDistribution.h" + +#include "SIREN/distributions/primary/helicity/PrimaryNeutrinoHelicityDistribution.h" + +#include "SIREN/distributions/primary/mass/PrimaryMass.h" + +#include "SIREN/distributions/primary/vertex/VertexPositionDistribution.h" +#include "SIREN/distributions/primary/vertex/ColumnDepthPositionDistribution.h" +#include "SIREN/distributions/primary/vertex/CylinderVolumePositionDistribution.h" +#include "SIREN/distributions/primary/vertex/DecayRangeFunction.h" +#include "SIREN/distributions/primary/vertex/DecayRangePositionDistribution.h" +#include "SIREN/distributions/primary/vertex/DepthFunction.h" +#include "SIREN/distributions/primary/vertex/LeptonDepthFunction.h" +#include "SIREN/distributions/primary/vertex/OrientedCylinderPositionDistribution.h" +#include "SIREN/distributions/primary/vertex/PointSourcePositionDistribution.h" +#include "SIREN/distributions/primary/vertex/RangeFunction.h" +#include "SIREN/distributions/primary/vertex/RangePositionDistribution.h" + +#include "SIREN/distributions/secondary/vertex/SecondaryVertexPositionDistribution.h" +#include "SIREN/distributions/secondary/vertex/SecondaryBoundedVertexDistribution.h" +#include "SIREN/distributions/secondary/vertex/SecondaryPhysicalVertexDistribution.h" + +#endif // SIREN_distributions_distributions_H diff --git a/projects/distributions/public/SIREN/distributions/serializable.h b/projects/distributions/public/SIREN/distributions/serializable.h new file mode 100644 index 000000000..0fa9a2da0 --- /dev/null +++ b/projects/distributions/public/SIREN/distributions/serializable.h @@ -0,0 +1,37 @@ +#ifndef SIREN_distributions_serializable_H +#define SIREN_distributions_serializable_H + +#include "SIREN/distributions/Distributions.h" + +#include "SIREN/distributions/primary/direction/PrimaryDirectionDistribution.h" +#include "SIREN/distributions/primary/direction/Cone.h" +#include "SIREN/distributions/primary/direction/FixedDirection.h" +#include "SIREN/distributions/primary/direction/IsotropicDirection.h" + +#include "SIREN/distributions/primary/energy/PrimaryEnergyDistribution.h" +#include "SIREN/distributions/primary/energy/ModifiedMoyalPlusExponentialEnergyDistribution.h" +#include "SIREN/distributions/primary/energy/Monoenergetic.h" +#include "SIREN/distributions/primary/energy/PowerLaw.h" +#include "SIREN/distributions/primary/energy/TabulatedFluxDistribution.h" + +#include "SIREN/distributions/primary/helicity/PrimaryNeutrinoHelicityDistribution.h" + +#include "SIREN/distributions/primary/mass/PrimaryMass.h" + +#include "SIREN/distributions/primary/vertex/VertexPositionDistribution.h" +#include "SIREN/distributions/primary/vertex/ColumnDepthPositionDistribution.h" +#include "SIREN/distributions/primary/vertex/CylinderVolumePositionDistribution.h" +#include "SIREN/distributions/primary/vertex/DecayRangeFunction.h" +#include "SIREN/distributions/primary/vertex/DecayRangePositionDistribution.h" +#include "SIREN/distributions/primary/vertex/DepthFunction.h" +#include "SIREN/distributions/primary/vertex/LeptonDepthFunction.h" +#include "SIREN/distributions/primary/vertex/OrientedCylinderPositionDistribution.h" +#include "SIREN/distributions/primary/vertex/PointSourcePositionDistribution.h" +#include "SIREN/distributions/primary/vertex/RangeFunction.h" +#include "SIREN/distributions/primary/vertex/RangePositionDistribution.h" + +#include "SIREN/distributions/secondary/vertex/SecondaryVertexPositionDistribution.h" +#include "SIREN/distributions/secondary/vertex/SecondaryBoundedVertexDistribution.h" +#include "SIREN/distributions/secondary/vertex/SecondaryPhysicalVertexDistribution.h" + +#endif // SIREN_distributions_serializable_H diff --git a/projects/geometry/CMakeLists.txt b/projects/geometry/CMakeLists.txt index 62b4c0dff..b884c6b50 100644 --- a/projects/geometry/CMakeLists.txt +++ b/projects/geometry/CMakeLists.txt @@ -18,15 +18,14 @@ target_include_directories(SIREN_geometry PUBLIC ) target_link_libraries(SIREN_geometry - INTERFACE - siren_compile_options - PRIVATE - $ PUBLIC photospline SIREN_serialization SIREN_math + PRIVATE + $ ) +apply_siren_compile_options(SIREN_geometry) install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/geometry/public/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} diff --git a/projects/geometry/private/Geometry.cxx b/projects/geometry/private/Geometry.cxx index 67475750a..538fcb286 100644 --- a/projects/geometry/private/Geometry.cxx +++ b/projects/geometry/private/Geometry.cxx @@ -206,3 +206,6 @@ std::vector Geometry::Intersections(siren::math::Vector3 } // namespace geometry } // namespace siren + +CEREAL_REGISTER_DYNAMIC_INIT(siren_Geometry); + diff --git a/projects/geometry/private/Sphere.cxx b/projects/geometry/private/Sphere.cxx index 6bcfac142..2b107945d 100644 --- a/projects/geometry/private/Sphere.cxx +++ b/projects/geometry/private/Sphere.cxx @@ -326,3 +326,6 @@ std::pair Sphere::ComputeDistanceToBorder(const siren::math::Vec } // namespace geometry } // namespace siren + +CEREAL_REGISTER_DYNAMIC_INIT(siren_Sphere); + diff --git a/projects/geometry/public/SIREN/geometry.h b/projects/geometry/public/SIREN/geometry.h new file mode 100644 index 000000000..4853a33ed --- /dev/null +++ b/projects/geometry/public/SIREN/geometry.h @@ -0,0 +1,13 @@ +#ifndef SIREN_geometry_geometry_H +#define SIREN_geometry_geometry_H + +#include "SIREN/geometry/Box.h" +#include "SIREN/geometry/Cylinder.h" +#include "SIREN/geometry/ExtrPoly.h" +#include "SIREN/geometry/Geometry.h" +#include "SIREN/geometry/GeometryMesh.h" +#include "SIREN/geometry/MeshBuilder.h" +#include "SIREN/geometry/Placement.h" +#include "SIREN/geometry/Sphere.h" + +#endif // SIREN_geometry_geometry_H diff --git a/projects/geometry/public/SIREN/geometry/Geometry.h b/projects/geometry/public/SIREN/geometry/Geometry.h index 7dec7874f..9742e3867 100644 --- a/projects/geometry/public/SIREN/geometry/Geometry.h +++ b/projects/geometry/public/SIREN/geometry/Geometry.h @@ -213,7 +213,10 @@ const std::array Geometry_Name = { "sphere", "box", "cylinder", } // namespace siren CEREAL_CLASS_VERSION(siren::geometry::Geometry, 0); +CEREAL_REGISTER_TYPE(siren::geometry::Geometry) CEREAL_CLASS_VERSION(siren::geometry::Geometry::Intersection, 0); CEREAL_CLASS_VERSION(siren::geometry::Geometry::IntersectionList, 0); +CEREAL_FORCE_DYNAMIC_INIT(siren_Geometry); + #endif // SIREN_Geometry_H diff --git a/projects/geometry/public/SIREN/geometry/Sphere.h b/projects/geometry/public/SIREN/geometry/Sphere.h index b97bf9e0a..351291849 100644 --- a/projects/geometry/public/SIREN/geometry/Sphere.h +++ b/projects/geometry/public/SIREN/geometry/Sphere.h @@ -77,7 +77,9 @@ class Sphere : public Geometry { } // namespace siren CEREAL_CLASS_VERSION(siren::geometry::Sphere, 0); -CEREAL_REGISTER_TYPE(siren::geometry::Sphere) +CEREAL_REGISTER_TYPE(siren::geometry::Sphere); CEREAL_REGISTER_POLYMORPHIC_RELATION(siren::geometry::Geometry, siren::geometry::Sphere); +CEREAL_FORCE_DYNAMIC_INIT(siren_Sphere); + #endif // SIREN_Sphere_H diff --git a/projects/geometry/public/SIREN/geometry/serializable.h b/projects/geometry/public/SIREN/geometry/serializable.h new file mode 100644 index 000000000..d5672094c --- /dev/null +++ b/projects/geometry/public/SIREN/geometry/serializable.h @@ -0,0 +1,12 @@ +#ifndef SIREN_geometry_serializable_H +#define SIREN_geometry_serializable_H + +#include "SIREN/geometry/Box.h" +#include "SIREN/geometry/GeometryMesh.h" +#include "SIREN/geometry/Sphere.h" +#include "SIREN/geometry/Placement.h" +#include "SIREN/geometry/Cylinder.h" +#include "SIREN/geometry/ExtrPoly.h" +#include "SIREN/geometry/Geometry.h" + +#endif // SIREN_geometry_serializable_H diff --git a/projects/injection/CMakeLists.txt b/projects/injection/CMakeLists.txt index d8e91a2b7..900fecf72 100644 --- a/projects/injection/CMakeLists.txt +++ b/projects/injection/CMakeLists.txt @@ -14,22 +14,21 @@ target_include_directories(SIREN_injection PUBLIC ) target_link_libraries(SIREN_injection - INTERFACE - siren_compile_options - PRIVATE - $ - pybind11::embed PUBLIC photospline - SIREN_serialization SIREN_utilities + SIREN_serialization SIREN_math SIREN_dataclasses SIREN_geometry SIREN_detector SIREN_interactions SIREN_distributions + PRIVATE + $ + pybind11::embed ) +apply_siren_compile_options(SIREN_injection) install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/injection/public/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} diff --git a/projects/injection/private/pybindings/injection.cxx b/projects/injection/private/pybindings/injection.cxx index 6cba39685..8cb3232b6 100644 --- a/projects/injection/private/pybindings/injection.cxx +++ b/projects/injection/private/pybindings/injection.cxx @@ -1,6 +1,15 @@ #include +#include +#include +#include +#include + +#include +#include +#include + #include "../../public/SIREN/injection/Process.h" #include "../../public/SIREN/injection/Injector.h" #include "../../public/SIREN/injection/Weighter.h" @@ -14,17 +23,18 @@ #include "../../../interactions/public/SIREN/interactions/pyDarkNewsCrossSection.h" #include "../../../interactions/public/SIREN/interactions/pyDarkNewsDecay.h" -#include -#include -#include -#include +#include "../../../serialization/public/SIREN/serialization/ByteString.h" -#include -#include -#include +#include "SIREN/dataclasses/serializable.h" +#include "SIREN/detector/serializable.h" +#include "SIREN/distributions/serializable.h" +#include "SIREN/geometry/serializable.h" +#include "SIREN/injection/serializable.h" +#include "SIREN/interactions/serializable.h" +#include "SIREN/math/serializable.h" +#include "SIREN/utilities/serializable.h" PYBIND11_DECLARE_HOLDER_TYPE(T__,std::shared_ptr); -//CEREAL_FORCE_DYNAMIC_INIT(pyDarkNewsCrossSection); using namespace pybind11; @@ -94,6 +104,10 @@ PYBIND11_MODULE(injection,m) { .def("ResetInjectedEvents",&Injector::ResetInjectedEvents) .def("SaveInjector",&Injector::SaveInjector) .def("LoadInjector",&Injector::LoadInjector) + .def(pybind11::pickle( + &(siren::serialization::pickle_save), + &(siren::serialization::pickle_load) + )) ; // class_, Injector>(m, "RangedSIREN") @@ -141,5 +155,10 @@ PYBIND11_MODULE(injection,m) { .def("EventWeight",&Weighter::EventWeight) .def("SaveWeighter",&Weighter::SaveWeighter) .def("LoadWeighter",&Weighter::LoadWeighter) + .def(pybind11::pickle( + &(siren::serialization::pickle_save), + &(siren::serialization::pickle_load) + )) ; } + diff --git a/projects/injection/public/SIREN/injection.h b/projects/injection/public/SIREN/injection.h new file mode 100644 index 000000000..392e665b3 --- /dev/null +++ b/projects/injection/public/SIREN/injection.h @@ -0,0 +1,9 @@ +#ifndef SIREN_injection_injection_H +#define SIREN_injection_injection_H + +#include "SIREN/injection/Injector.h" +#include "SIREN/injection/Process.h" +#include "SIREN/injection/Weighter.h" +#include "SIREN/injection/WeightingUtils.h" + +#endif // SIREN_injection_injection_H diff --git a/projects/injection/public/SIREN/injection/Injector.h b/projects/injection/public/SIREN/injection/Injector.h index bd82e28bf..602c8f756 100644 --- a/projects/injection/public/SIREN/injection/Injector.h +++ b/projects/injection/public/SIREN/injection/Injector.h @@ -121,7 +121,6 @@ friend cereal::access; archive(::cereal::make_nvp("InjectedEvents", injected_events)); archive(::cereal::make_nvp("DetectorModel", detector_model)); // archive(::cereal::make_nvp("SIRENRandom", random)); - // std::cout << "saved SIRENRandom\n"; archive(::cereal::make_nvp("PrimaryProcess", primary_process)); archive(::cereal::make_nvp("SecondaryProcesses", secondary_processes)); } else { @@ -139,7 +138,6 @@ friend cereal::access; archive(::cereal::make_nvp("InjectedEvents", injected_events)); archive(::cereal::make_nvp("DetectorModel", detector_model)); // archive(::cereal::make_nvp("SIRENRandom", random)); - // std::cout << "loaded SIRENRandom\n"; archive(::cereal::make_nvp("PrimaryProcess", _primary_process)); archive(::cereal::make_nvp("SecondaryProcesses", _secondary_processes)); SetPrimaryProcess(_primary_process); diff --git a/projects/injection/public/SIREN/injection/Weighter.h b/projects/injection/public/SIREN/injection/Weighter.h index 93e845cb7..4b8daf857 100644 --- a/projects/injection/public/SIREN/injection/Weighter.h +++ b/projects/injection/public/SIREN/injection/Weighter.h @@ -102,12 +102,17 @@ class Weighter { } template - void load(Archive & archive, std::uint32_t const version) const { + static void load_and_construct(Archive & archive, cereal::construct & construct, std::uint32_t const version) { if(version == 0) { + std::vector> injectors; + std::shared_ptr detector_model; + std::shared_ptr primary_physical_process; + std::vector> secondary_physical_processes; archive(::cereal::make_nvp("Injectors", injectors)); archive(::cereal::make_nvp("DetectorModel", detector_model)); archive(::cereal::make_nvp("PrimaryPhysicalProcess", primary_physical_process)); archive(::cereal::make_nvp("SecondaryPhysicalProcesses", secondary_physical_processes)); + construct(injectors, detector_model, primary_physical_process, secondary_physical_processes); } else { throw std::runtime_error("Weighter only supports version <= 0!"); } diff --git a/projects/injection/public/SIREN/injection/serializable.h b/projects/injection/public/SIREN/injection/serializable.h new file mode 100644 index 000000000..ad1c10b73 --- /dev/null +++ b/projects/injection/public/SIREN/injection/serializable.h @@ -0,0 +1,8 @@ +#ifndef SIREN_injection_serializable_H +#define SIREN_injection_serializable_H + +#include "SIREN/injection/Weighter.h" +#include "SIREN/injection/Process.h" +#include "SIREN/injection/Injector.h" + +#endif // SIREN_injection_serializable_H diff --git a/projects/interactions/CMakeLists.txt b/projects/interactions/CMakeLists.txt index 4c0b6505b..a482fcfce 100644 --- a/projects/interactions/CMakeLists.txt +++ b/projects/interactions/CMakeLists.txt @@ -26,19 +26,18 @@ target_include_directories(SIREN_interactions PUBLIC ) target_link_libraries(SIREN_interactions - INTERFACE - siren_compile_options PRIVATE $ pybind11::embed PUBLIC photospline - SIREN_serialization SIREN_utilities + SIREN_serialization SIREN_math SIREN_dataclasses SIREN_detector ) +apply_siren_compile_options(SIREN_interactions) install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/interactions/public/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} diff --git a/projects/interactions/public/SIREN/interactions.h b/projects/interactions/public/SIREN/interactions.h new file mode 100644 index 000000000..5db738aab --- /dev/null +++ b/projects/interactions/public/SIREN/interactions.h @@ -0,0 +1,21 @@ +#ifndef SIREN_interactions_interactions_H +#define SIREN_interactions_interactions_H + +#include "SIREN/interactions/CrossSection.h" +#include "SIREN/interactions/DISFromSpline.h" +#include "SIREN/interactions/DarkNewsCrossSection.h" +#include "SIREN/interactions/DarkNewsDecay.h" +#include "SIREN/interactions/Decay.h" +#include "SIREN/interactions/DipoleFromTable.h" +#include "SIREN/interactions/DummyCrossSection.h" +#include "SIREN/interactions/ElasticScattering.h" +#include "SIREN/interactions/HNLFromSpline.h" +#include "SIREN/interactions/Interaction.h" +#include "SIREN/interactions/InteractionCollection.h" +#include "SIREN/interactions/NeutrissimoDecay.h" +#include "SIREN/interactions/pyCrossSection.h" +#include "SIREN/interactions/pyDarkNewsCrossSection.h" +#include "SIREN/interactions/pyDarkNewsDecay.h" +#include "SIREN/interactions/pyDecay.h" + +#endif // SIREN_interactions_interactions_H diff --git a/projects/interactions/public/SIREN/interactions/HNLDecay.h b/projects/interactions/public/SIREN/interactions/HNLDecay.h index b66714e99..d70fcea53 100644 --- a/projects/interactions/public/SIREN/interactions/HNLDecay.h +++ b/projects/interactions/public/SIREN/interactions/HNLDecay.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include #include #include diff --git a/projects/interactions/public/SIREN/interactions/serializable.h b/projects/interactions/public/SIREN/interactions/serializable.h new file mode 100644 index 000000000..daf4e5aa6 --- /dev/null +++ b/projects/interactions/public/SIREN/interactions/serializable.h @@ -0,0 +1,16 @@ +#ifndef SIREN_serializable_H +#define SIREN_serializable_H + +#include "SIREN/interactions/DarkNewsCrossSection.h" +#include "SIREN/interactions/NeutrissimoDecay.h" +#include "SIREN/interactions/DarkNewsDecay.h" +#include "SIREN/interactions/HNLFromSpline.h" +#include "SIREN/interactions/Decay.h" +#include "SIREN/interactions/DummyCrossSection.h" +#include "SIREN/interactions/InteractionCollection.h" +#include "SIREN/interactions/DISFromSpline.h" +#include "SIREN/interactions/ElasticScattering.h" +#include "SIREN/interactions/DipoleFromTable.h" +#include "SIREN/interactions/CrossSection.h" + +#endif // SIREN_serializable_H diff --git a/projects/math/CMakeLists.txt b/projects/math/CMakeLists.txt index 1bde95e3a..520079fe8 100644 --- a/projects/math/CMakeLists.txt +++ b/projects/math/CMakeLists.txt @@ -17,8 +17,6 @@ target_include_directories(SIREN_math PUBLIC if(${MACOSX}) target_link_libraries(SIREN_math - INTERFACE - siren_compile_options PUBLIC photospline delabella_shared @@ -28,8 +26,6 @@ target_link_libraries(SIREN_math ) else() target_link_libraries(SIREN_math - INTERFACE - siren_compile_options PUBLIC photospline delabella_shared @@ -41,6 +37,8 @@ target_link_libraries(SIREN_math ) endif() +apply_siren_compile_options(SIREN_math) + install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/math/public/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING diff --git a/projects/math/public/SIREN/math.h b/projects/math/public/SIREN/math.h new file mode 100644 index 000000000..3c37c8825 --- /dev/null +++ b/projects/math/public/SIREN/math.h @@ -0,0 +1,13 @@ +#ifndef SIREN_math_math_H +#define SIREN_math_math_H + +#include "SIREN/math/Conversions.h" +#include "SIREN/math/EulerAngles.h" +#include "SIREN/math/EulerQuaternionConversions.h" +#include "SIREN/math/Interpolation.h" +#include "SIREN/math/Matrix3D.h" +#include "SIREN/math/Polynomial.h" +#include "SIREN/math/Quaternion.h" +#include "SIREN/math/Vector3D.h" + +#endif // SIREN_math_math_H diff --git a/projects/math/public/SIREN/math/serializable.h b/projects/math/public/SIREN/math/serializable.h new file mode 100644 index 000000000..8a88a1a65 --- /dev/null +++ b/projects/math/public/SIREN/math/serializable.h @@ -0,0 +1,11 @@ +#ifndef SIREN_math_serializable_H +#define SIREN_math_serializable_H + +#include "SIREN/math/EulerAngles.h" +#include "SIREN/math/Polynomial.h" +#include "SIREN/math/Interpolation.h" +#include "SIREN/math/Quaternion.h" +#include "SIREN/math/Vector3D.h" +#include "SIREN/math/Matrix3D.h" + +#endif // SIREN_math_serializable_H diff --git a/projects/serialization/CMakeLists.txt b/projects/serialization/CMakeLists.txt index c7983051b..ea58132ba 100644 --- a/projects/serialization/CMakeLists.txt +++ b/projects/serialization/CMakeLists.txt @@ -1,13 +1,15 @@ -add_library(SIREN_serialization INTERFACE) -target_include_directories(SIREN_serialization INTERFACE + +LIST (APPEND serialization_SOURCES + ${PROJECT_SOURCE_DIR}/projects/serialization/private/serialization.cxx +) + +add_library(SIREN_serialization OBJECT ${serialization_SOURCES}) +target_include_directories(SIREN_serialization PUBLIC $ $ ) -target_link_libraries(SIREN_serialization - INTERFACE - siren_compile_options -) +apply_siren_compile_options(SIREN_serialization) install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/serialization/public/" EXPORT ${PROJECT_NAME}Config diff --git a/projects/serialization/private/serialization.cxx b/projects/serialization/private/serialization.cxx new file mode 100644 index 000000000..838790387 --- /dev/null +++ b/projects/serialization/private/serialization.cxx @@ -0,0 +1,11 @@ +// serialization.cxx +#include +#include + +// Register the archives +CEREAL_REGISTER_ARCHIVE(cereal::BinaryOutputArchive); +CEREAL_REGISTER_ARCHIVE(cereal::BinaryInputArchive); + +// Ensure dynamic initialization is not optimized away +CEREAL_REGISTER_DYNAMIC_INIT(siren); +CEREAL_FORCE_DYNAMIC_INIT(siren); diff --git a/projects/serialization/public/SIREN/serialization/ByteString.h b/projects/serialization/public/SIREN/serialization/ByteString.h new file mode 100644 index 000000000..28dc6685a --- /dev/null +++ b/projects/serialization/public/SIREN/serialization/ByteString.h @@ -0,0 +1,104 @@ +#ifndef SIREN_serialization_ByteString_H +#define SIREN_serialization_ByteString_H + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace siren { +namespace serialization { + +template +std::vector to_byte_string(std::shared_ptr obj) { + std::ostringstream oss(std::ios::binary); + { + cereal::BinaryOutputArchive oarchive(oss); + oarchive(obj); + } + size_t n_bytes = oss.tellp(); + std::string str = oss.str(); + if(not (str.size() == n_bytes)) + throw std::runtime_error("str.size() != n_bytes"); + std::vector vec(str.begin(), str.end()); + if(not (vec.size() == n_bytes)) + throw std::runtime_error("vec.size() != n_bytes"); + return vec; +} + +std::string bytes_to_hex_string(std::vector const & bytes) { + std::ostringstream oss; + oss << std::hex << std::setfill('0'); + for (char const & byte : bytes) { + oss << std::setw(2) << (unsigned int)std::uint8_t(byte); + } + std::string s = oss.str(); + if(not (s.size() % 2 == 0)) + throw std::runtime_error("s.size() % 2 != 0"); + if(not (s.size() == 2 * bytes.size())) + throw std::runtime_error("s.size() != 2 * bytes.size()"); + return s; +} + +template +std::shared_ptr from_byte_string(std::vector const & byte_string) { + std::string str(byte_string.begin(), byte_string.end()); + if(not (str.size() == byte_string.size())) + throw std::runtime_error("str.size() != byte_string.size()"); + std::istringstream iss(str, std::ios::binary); + std::shared_ptr obj; + { + cereal::BinaryInputArchive iarchive(iss); + iarchive(obj); + } + size_t n_bytes = iss.tellg(); + if(not (n_bytes == str.size())) + throw std::runtime_error("n_bytes != str.size()"); + return obj; +} + +std::vector hex_string_to_bytes(std::string const & hex_string) { + std::vector bytes; + for (size_t i = 0; i < hex_string.size(); i += 2) { + std::string byte_string = hex_string.substr(i, 2); + char byte = static_cast(std::stoi(byte_string, nullptr, 16)); + bytes.push_back(byte); + } + if(not (bytes.size() == hex_string.size() / 2)) + throw std::runtime_error("bytes.size() != hex_string.size() / 2"); + return bytes; +} + +template +pybind11::tuple pickle_save(std::shared_ptr cpp_obj) { + std::vector byte_string = to_byte_string(cpp_obj); + std::string hex_string = bytes_to_hex_string(byte_string); + return pybind11::make_tuple(hex_string); +} + +template +std::shared_ptr pickle_load(pybind11::tuple t) { + if (t.size() != 1) { + throw std::runtime_error("Invalid state!"); + } + std::string hex_string = t[0].cast(); + std::vector byte_string = hex_string_to_bytes(hex_string); + std::shared_ptr res = from_byte_string(byte_string); + return res; +} + +} // namespace serialization +} // namespace siren + +#endif // SIREN_serialization_ByteString_H diff --git a/projects/utilities/CMakeLists.txt b/projects/utilities/CMakeLists.txt index a8c9c11af..c31d09389 100644 --- a/projects/utilities/CMakeLists.txt +++ b/projects/utilities/CMakeLists.txt @@ -12,10 +12,7 @@ target_include_directories(SIREN_utilities PUBLIC $ ) -target_link_libraries(SIREN_utilities - INTERFACE - siren_compile_options -) +apply_siren_compile_options(SIREN_utilities) install(DIRECTORY "${PROJECT_SOURCE_DIR}/projects/utilities/public/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} diff --git a/projects/utilities/private/Interpolator.cxx b/projects/utilities/private/Interpolator.cxx index 57646d175..b7a52da8a 100644 --- a/projects/utilities/private/Interpolator.cxx +++ b/projects/utilities/private/Interpolator.cxx @@ -3,6 +3,15 @@ #include #include +// Explicit template instantiation +template struct siren::utilities::TableData1D; +template struct siren::utilities::TableData2D; +template struct siren::utilities::IndexFinderRegular; +template struct siren::utilities::IndexFinderIrregular; +template struct siren::utilities::Indexer1D; +template struct siren::utilities::Interpolator1D; +template struct siren::utilities::Interpolator2D; + using namespace siren::utilities; template<> @@ -29,3 +38,13 @@ bool Interpolator2D::operator==(Interpolator2D const & o return original_table == other.original_table; } +CEREAL_CLASS_VERSION(siren::utilities::TableData1D, 0); +CEREAL_CLASS_VERSION(siren::utilities::TableData2D, 0); +CEREAL_CLASS_VERSION(siren::utilities::IndexFinderRegular, 0); +CEREAL_CLASS_VERSION(siren::utilities::IndexFinderIrregular, 0); +CEREAL_CLASS_VERSION(siren::utilities::Indexer1D, 0); +CEREAL_CLASS_VERSION(siren::utilities::Interpolator1D, 0); +CEREAL_CLASS_VERSION(siren::utilities::Interpolator2D, 0); + +CEREAL_REGISTER_DYNAMIC_INIT(siren_Interpolator); + diff --git a/projects/utilities/public/SIREN/utilities.h b/projects/utilities/public/SIREN/utilities.h new file mode 100644 index 000000000..3bbc257ee --- /dev/null +++ b/projects/utilities/public/SIREN/utilities.h @@ -0,0 +1,13 @@ +#pragma once +#ifndef SIREN_utilities_utilities_H +#define SIREN_utilities_utilities_H + +#include "SIREN/utilities/Constants.h" +#include "SIREN/utilities/Errors.h" +#include "SIREN/utilities/Integration.h" +#include "SIREN/utilities/Interpolator.h" +#include "SIREN/utilities/Pybind11Trampoline.h" +#include "SIREN/utilities/Random.h" +#include "SIREN/utilities/StringManipulation.h" + +#endif // SIREN_utilities_utilities_H diff --git a/projects/utilities/public/SIREN/utilities/Interpolator.h b/projects/utilities/public/SIREN/utilities/Interpolator.h index 6ce95541f..4d1491f9f 100644 --- a/projects/utilities/public/SIREN/utilities/Interpolator.h +++ b/projects/utilities/public/SIREN/utilities/Interpolator.h @@ -702,15 +702,18 @@ struct Interpolator2D { } }; +// Declare the explicit specialization (but do not instantiate) +extern template struct TableData1D; +extern template struct TableData2D; +extern template struct IndexFinderRegular; +extern template struct IndexFinderIrregular; +extern template struct Indexer1D; +extern template struct Interpolator1D; +extern template struct Interpolator2D; + } // namespace utilities } // namespace siren -CEREAL_CLASS_VERSION(siren::utilities::TableData1D, 0); -CEREAL_CLASS_VERSION(siren::utilities::TableData2D, 0); -CEREAL_CLASS_VERSION(siren::utilities::IndexFinderRegular, 0); -CEREAL_CLASS_VERSION(siren::utilities::IndexFinderIrregular, 0); -CEREAL_CLASS_VERSION(siren::utilities::Indexer1D, 0); -CEREAL_CLASS_VERSION(siren::utilities::Interpolator1D, 0); -CEREAL_CLASS_VERSION(siren::utilities::Interpolator2D, 0); +CEREAL_FORCE_DYNAMIC_INIT(siren_Interpolator); #endif // SIREN_Interpolator_H diff --git a/projects/utilities/public/SIREN/utilities/serializable.h b/projects/utilities/public/SIREN/utilities/serializable.h new file mode 100644 index 000000000..136eeb324 --- /dev/null +++ b/projects/utilities/public/SIREN/utilities/serializable.h @@ -0,0 +1,5 @@ +#pragma once +#ifndef SIREN_utilities_serializable_H +#define SIREN_utilities_serializable_H + +#endif // SIREN_utilities_serializable_H diff --git a/python/Injector.py b/python/Injector.py index d7096b594..ed0a7c8d1 100644 --- a/python/Injector.py +++ b/python/Injector.py @@ -16,7 +16,7 @@ if TYPE_CHECKING: import siren -_Injector = _injection.Injector +_Injector = _injection._Injector ParticleType = _dataclasses.ParticleType CrossSection = _interactions.CrossSection @@ -137,6 +137,35 @@ def __initialize_injector(self): if self.__stopping_condition is not None: self.__injector.SetStoppingCondition(self.__stopping_condition) + # Custom method to retrieve the internal state for pickling + def __getstate__(self): + # The seed and stopping condition are the only things we cannot serialize + state = (self.__seed, self.__stopping_condition, self.__injector.__getstate__()) + return state + + # Custom method to restore the state from a pickle + def __setstate__(self, state): + + self.__seed, self.__stopping_condition, injector_state = state + + # Create a new instance of the C++ class and restore its state + self.__injector = _Injector.__new__(_Injector) # Create an empty instance + if self.__injector is None: + raise TypeError("Failed to create C++ Injector object") + self.__injector.__setstate__(injector_state) + self.__number_of_events = self.__injector.EventsToInject() + self.__detector_model = self.__injector.GetDetectorModel() + primary_process = self.__injector.GetPrimaryProcess() + self.__primary_type = primary_process.primary_type + self.__primary_interactions = list(primary_process.interactions.GetCrossSections()) + list(primary_process.interactions.GetDecays()) + self.__primary_injection_distributions = list(primary_process.distributions) + + self.__secondary_interactions = {} + self.__secondary_injection_distributions = {} + for secondary_type, secondary_process in self.__injector.GetSecondaryProcessMap(): + self.__secondary_interactions[secondary_type] = list(secondary_process.interactions.GetCrossSections()) + list(secondary_process.interactions.GetDecays()) + self.__secondary_injection_distributions[secondary_type] = list(secondary_process.distributions) + @property def seed(self): return self.__seed diff --git a/python/Weighter.py b/python/Weighter.py index 145080bda..69f8c4280 100644 --- a/python/Weighter.py +++ b/python/Weighter.py @@ -14,8 +14,8 @@ if TYPE_CHECKING: import siren -_Injector = _injection.Injector -_Weighter = _injection.Weighter +_Injector = _injection._Injector +_Weighter = _injection._Weighter _PyInjector = _Injector_module.Injector diff --git a/python/__init__.py b/python/__init__.py index 950ddd621..e59cd934b 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -8,8 +8,6 @@ from . import injection from . import _util -from . import Injector -from . import Weighter from . import resources # Intropspect package version @@ -34,11 +32,15 @@ # Override the Injector with the python wrapper injection._Injector = injection.Injector +del injection.Injector +from . import Injector injection.Injector = Injector.Injector del Injector # Override the Weighter with the python wrapper injection._Weighter = injection.Weighter +del injection.Weighter +from . import Weighter injection.Weighter = Weighter.Weighter del Weighter diff --git a/vendor/cereal b/vendor/cereal index 02eace19a..d1fcec807 160000 --- a/vendor/cereal +++ b/vendor/cereal @@ -1 +1 @@ -Subproject commit 02eace19a99ce3cd564ca4e379753d69af08c2c8 +Subproject commit d1fcec807b372f04e4c1041b3058e11c12853e6e diff --git a/vendor/photospline b/vendor/photospline index bb68658a8..c6fb3ea9a 160000 --- a/vendor/photospline +++ b/vendor/photospline @@ -1 +1 @@ -Subproject commit bb68658a8776b9dabba8c3d3332b4294474d20c3 +Subproject commit c6fb3ea9a98f93705bc07b288b7f9264e621ac18