From 0a8793c83eb26cbdb129dc2b27e0941d4c673d5d Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Mon, 22 Jan 2024 20:54:22 -0500 Subject: [PATCH 1/7] Add first a pkg-config search, then fallback. --- cmake/LZ4Config.cmake | 56 ++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/cmake/LZ4Config.cmake b/cmake/LZ4Config.cmake index 159807b..75f66db 100644 --- a/cmake/LZ4Config.cmake +++ b/cmake/LZ4Config.cmake @@ -1,29 +1,37 @@ # # Find the LZ4 library and include files and configure target for it. # -get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -find_path(LZ4_INCLUDE_DIR NAMES lz4.h) -find_library(LZ4_LIBRARY NAMES lz4) -if (LZ4_LIBRARY) - include(CheckCSourceRuns) - set(CMAKE_REQUIRED_INCLUDES ${LZ4_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${LZ4_LIBRARY}) - enable_language(C) - check_c_source_runs(" -#include -int main() { - int good = (LZ4_VERSION_MAJOR > 1) || - ((LZ4_VERSION_MAJOR == 1) && (LZ4_VERSION_MINOR >= 8)); -return !good; -}" LZ4_GOOD_VERSION) - set(CMAKE_REQUIRED_INCLUDES) - set(CMAKE_REQUIRED_LIBRARIES) -endif() +find_package(PkgConfig REQUIRED) +pkg_check_modules(LZ4 liblz4) +if(NOT LZ4_FOUND) + ### Alternate way of looking for liblz4 + get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + find_path(LZ4_INCLUDE_DIR NAMES lz4.h) + find_library(LZ4_LIBRARY NAMES lz4) + if (LZ4_LIBRARY) + include(CheckCSourceRuns) + set(CMAKE_REQUIRED_INCLUDES ${LZ4_INCLUDE_DIR}) + set(CMAKE_REQUIRED_LIBRARIES ${LZ4_LIBRARY}) + enable_language(C) + check_c_source_runs(" + #include + int main() { + int good = (LZ4_VERSION_MAJOR > 1) || + ((LZ4_VERSION_MAJOR == 1) && (LZ4_VERSION_MINOR >= 8)); + return !good; + }" LZ4_GOOD_VERSION) + set(CMAKE_REQUIRED_INCLUDES) + set(CMAKE_REQUIRED_LIBRARIES) + endif(LZ4_LIBRARY) -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( - LZ4 DEFAULT_MSG - LZ4_LIBRARY LZ4_INCLUDE_DIR LZ4_GOOD_VERSION) + include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS( + LZ4 DEFAULT_MSG + LZ4_LIBRARY LZ4_INCLUDE_DIR LZ4_GOOD_VERSION) + + set(LZ4_INCLUDE_DIRS ${LZ4_INCLUDE_DIR}) + set(LZ4_LIBRARIES ${LZ4_LIBRARY}) +endif(NOT LZ4_FOUND) if (NOT LZ4_FOUND) message(STATUS "No system version of LZ4 found.") @@ -34,8 +42,6 @@ else() INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIR}" ) endif() - message(STATUS "Found LZ4: ${LZ4_LIBRARY}") - set(LZ4_INCLUDE_DIRS ${LZ4_INCLUDE_DIR}) - set(LZ4_LIBRARIES ${LZ4_LIBRARY}) + message(STATUS "Found LZ4: ${LZ4_LIBRARIES}") mark_as_advanced(LZ4_INCLUDE_DIRS LZ4_INCLUDE_DIR LZ4_LIBRARIES LZ4_LIBRARY) endif (NOT LZ4_FOUND) From 13dca79713e570559ca823e34304f3c7f1ec025d Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Wed, 24 Jan 2024 17:19:39 -0500 Subject: [PATCH 2/7] Updated way to find and process lz4, thanks to Chris Dilks --- CMakeLists.txt | 19 ++++++++----------- cmake/LZ4Config.cmake | 38 +++----------------------------------- cmake/hipo4.pc.in | 1 + 3 files changed, 12 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40071d0..b305c7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,25 +60,22 @@ find_package(LZ4 QUIET CONFIG PATHS ${PROJECT_SOURCE_DIR}/cmake ) if(NOT LZ4_FOUND) message(STATUS "**LZ4********************************************************************") - message(STATUS "* We did not find a system LZ4 package -- We will build this locally. *") + message(STATUS "* We did not find a system (or local build) LZ4 package. *") + message(STATUS "* Please install lz4 (Centos: yum install lz4 MacOS: brew install lz4) *") + message(STATUS "* Or build lz4 from the included sources. *") + message(STATUS "* *") message(STATUS "* To make this possible, please make sure you initialized the submodule.*") message(STATUS "* If you did not include --recurse-submodules at initial clone do: *") message(STATUS "* git submodule init *") message(STATUS "* git submodule update *") + message(STATUS "* Then: 'cd lz4' followed by: *") + message(STATUS "* make PREFIX=${CMAKE_INSTALL_PREFIX} CFLAGS='-fPIC' install ") message(STATUS "*************************************************************************") - message("PROJECT_SOURCE_DIR = ${PROJECT_SOURCE_DIR}") - file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/include/hipo4) - add_custom_target(LZ4 ALL - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/lz4/lib - COMMAND make PREFIX=${CMAKE_INSTALL_PREFIX} CFLAGS="-fPIC" install - ) - - set(LZ4_INCLUDE_DIRS ${CMAKE_INSTALL_PREFIX}/include) - set(LZ4_LIBRARIES ${CMAKE_INSTALL_PREFIX}/lib/liblz4.a) + message(FATAL_ERROR "stop processing until lz4 is available") endif() add_compile_definitions(__LZ4__) -include_directories(${LZ4_INCLUDE_DIRS}) +# include_directories(${LZ4_INCLUDE_DIRS}) set(DATAFRAME_IN_MAIN TRUE) add_subdirectory(extensions/dataframes) diff --git a/cmake/LZ4Config.cmake b/cmake/LZ4Config.cmake index 75f66db..943bf59 100644 --- a/cmake/LZ4Config.cmake +++ b/cmake/LZ4Config.cmake @@ -1,47 +1,15 @@ # # Find the LZ4 library and include files and configure target for it. # +set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH}:${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") find_package(PkgConfig REQUIRED) pkg_check_modules(LZ4 liblz4) -if(NOT LZ4_FOUND) - ### Alternate way of looking for liblz4 - get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) - find_path(LZ4_INCLUDE_DIR NAMES lz4.h) - find_library(LZ4_LIBRARY NAMES lz4) - if (LZ4_LIBRARY) - include(CheckCSourceRuns) - set(CMAKE_REQUIRED_INCLUDES ${LZ4_INCLUDE_DIR}) - set(CMAKE_REQUIRED_LIBRARIES ${LZ4_LIBRARY}) - enable_language(C) - check_c_source_runs(" - #include - int main() { - int good = (LZ4_VERSION_MAJOR > 1) || - ((LZ4_VERSION_MAJOR == 1) && (LZ4_VERSION_MINOR >= 8)); - return !good; - }" LZ4_GOOD_VERSION) - set(CMAKE_REQUIRED_INCLUDES) - set(CMAKE_REQUIRED_LIBRARIES) - endif(LZ4_LIBRARY) - - include(FindPackageHandleStandardArgs) - FIND_PACKAGE_HANDLE_STANDARD_ARGS( - LZ4 DEFAULT_MSG - LZ4_LIBRARY LZ4_INCLUDE_DIR LZ4_GOOD_VERSION) - - set(LZ4_INCLUDE_DIRS ${LZ4_INCLUDE_DIR}) - set(LZ4_LIBRARIES ${LZ4_LIBRARY}) -endif(NOT LZ4_FOUND) if (NOT LZ4_FOUND) message(STATUS "No system version of LZ4 found.") else() - if(NOT TARGET LZ4) - add_library(LZ4 INTERFACE IMPORTED) - set_target_properties(LZ4 PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIR}" - ) - endif() + add_library(LZ4 INTERFACE IMPORTED) + set_target_properties(LZ4 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIR}") message(STATUS "Found LZ4: ${LZ4_LIBRARIES}") mark_as_advanced(LZ4_INCLUDE_DIRS LZ4_INCLUDE_DIR LZ4_LIBRARIES LZ4_LIBRARY) endif (NOT LZ4_FOUND) diff --git a/cmake/hipo4.pc.in b/cmake/hipo4.pc.in index dbe5726..3e61d3b 100644 --- a/cmake/hipo4.pc.in +++ b/cmake/hipo4.pc.in @@ -5,5 +5,6 @@ libdir=${prefix}/lib Name: hipo4 Description: High Performance Output data format for experimental physics Version: @HIPO_VERSION@ +Requires: liblz4 >= @LZ4_VERSION@ Libs: -L${libdir} -lhipo4 Cflags: -I${includedir} From f0d32877405b101c289ab8a9d126a305f398ee77 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Wed, 24 Jan 2024 18:12:26 -0500 Subject: [PATCH 3/7] Still need to include the lz4 dir. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b305c7e..2ce2c85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,7 @@ if(NOT LZ4_FOUND) endif() add_compile_definitions(__LZ4__) -# include_directories(${LZ4_INCLUDE_DIRS}) +include_directories(PkgConfig::LZ4) set(DATAFRAME_IN_MAIN TRUE) add_subdirectory(extensions/dataframes) From ab1fd4fb17c9eecda03388feabe2783372bd573d Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Tue, 6 Feb 2024 13:25:35 -0500 Subject: [PATCH 4/7] Minor update correcting bank names. --- extensions/dataframes/README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/extensions/dataframes/README.md b/extensions/dataframes/README.md index 66819f7..b8f2809 100644 --- a/extensions/dataframes/README.md +++ b/extensions/dataframes/README.md @@ -27,7 +27,7 @@ cd build cmake -DCMAKE_INSTALL_PREFIX=/path/to/install/location .. make -j8 install ``` -This will install the hipo4 library (both .a and .so) in +This will install the hipo4 and HipoDataFrame libraries in `/path/to/install/location/lib` You can now load the library into root with: @@ -42,7 +42,7 @@ root [0] .L libHipoDataFrame.so and the .so with .dylib) ***NOTE***: On a system where the default compiler is NOT c++17 compatible, i.e. Linux at JLab, -you want to specify the compiler to cmake. You can do so with the following lines: +you have to specify the compiler to cmake. You can do so with the following lines: ```bash module use /apps/modulefiles module load gcc/9.3.0 @@ -58,6 +58,9 @@ currently C++17 compatible, so use the ROOT version installed in `~holtrop/root` [See the ROOT documentation for RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) +***Note***: The names of the Hipo schema are mangled to avoid :: and . (period) in the name, since +these indicate C++ namespace and class member. So instead of :: and . we use underscores (_). + The basics: ```bash @@ -65,6 +68,11 @@ root root [0] .L libHipoDataFrame.so root [1] auto df = MakeHipoDataFrame("rec_clas_016214.evio.00000.hipo") root [2] df.GetColumnNames() // Shows what is in the file. -root [3] auto h_px = df.Histo1D("REC::Particle.px") +root [3] auto h_px = df.Histo1D("REC_Particle_px") root [4] h_px->DrawClone(); ``` +The result would be a histogram of the REC::Particle.px, i.e the x component of the particle momentum +for all particles in the events. + +The ROOT RDataFrame is very versatile and is intended by the ROOT team as the future of +data analysis. [See more details on the ROOT website](https://root.cern/doc/master/classROOT_1_1RDataFrame.html). \ No newline at end of file From 98d07bdac186453d1d6f094bd75118b884ba937a Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Fri, 9 Feb 2024 12:09:14 -0500 Subject: [PATCH 5/7] Try to fix the LZ4 stuff for different behaviors of cmake on different systems. ugh. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ce2c85..a776a6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -75,7 +75,6 @@ if(NOT LZ4_FOUND) endif() add_compile_definitions(__LZ4__) -include_directories(PkgConfig::LZ4) set(DATAFRAME_IN_MAIN TRUE) add_subdirectory(extensions/dataframes) @@ -141,8 +140,9 @@ target_include_directories(hipo4 PUBLIC $ ) -target_link_libraries(hipo4 PUBLIC ${LZ4_LIBRARIES} ) -target_link_libraries(hipo4_static PUBLIC ${LZ4_LIBRARIES}) +target_compile_options(hipo4_objs PUBLIC ${LZ4_CLFAGS} ${LZ4_CFLAGS_OTHER}) +target_link_libraries(hipo4 PUBLIC ${LZ4_LINK_LIBRARIES} ) +target_link_libraries(hipo4_static PUBLIC ${LZ4_LINK_LIBRARIES}) install(TARGETS hipo4 EXPORT hipo4-export From d220e0a7ae10d1cd836932f74ab458f18b44b3d8 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Fri, 9 Feb 2024 13:16:46 -0500 Subject: [PATCH 6/7] Testing on Intel Mac --- CMakeLists.txt | 17 ++++++++++++----- cmake/LZ4Config.cmake | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a776a6a..95394bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,12 +6,13 @@ ########################################################## # minimum version of CMake, which is determined by Geant4's requirements -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.20) project(HIPO VERSION 4.0.1) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) + # # Set a default build type if none was specified # @@ -75,6 +76,11 @@ if(NOT LZ4_FOUND) endif() add_compile_definitions(__LZ4__) +# Debug LZ4 section. +#include(/Users/maurik/cmake/cmake_debug_properties.cmake ) +#print_target_properties(PkgConfig::LZ4) +#include(CMakePrintHelpers) +#cmake_print_properties(TARGETS PkgConfig::LZ4 PROPERTIES NAME IMPORTED INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES) set(DATAFRAME_IN_MAIN TRUE) add_subdirectory(extensions/dataframes) @@ -125,7 +131,9 @@ set_target_properties(hipo4_static PROPERTIES OUTPUT_NAME hipo4) # So that the # Required on Unix OS family to be able to be linked into shared libraries. set_target_properties(hipo4_objs PROPERTIES POSITION_INDEPENDENT_CODE ON) -add_dependencies(hipo4_objs LZ4) +# Note: Neither add_dependencies(hipo4_objs PkgConfig::LZ4) nor target_include_directories(hipo4_objs PUBLIC PkgConfig::LZ4) +# work in an Intel Mac. +target_include_directories(hipo4_objs PUBLIC ${LZ4_INCLUDE_DIRS}) # Include the macros for creating export package. include(CMakePackageConfigHelpers) @@ -140,9 +148,8 @@ target_include_directories(hipo4 PUBLIC $ ) -target_compile_options(hipo4_objs PUBLIC ${LZ4_CLFAGS} ${LZ4_CFLAGS_OTHER}) -target_link_libraries(hipo4 PUBLIC ${LZ4_LINK_LIBRARIES} ) -target_link_libraries(hipo4_static PUBLIC ${LZ4_LINK_LIBRARIES}) +target_link_libraries(hipo4 PUBLIC PkgConfig::LZ4 ) +target_link_libraries(hipo4_static PUBLIC PkgConfig::LZ4) install(TARGETS hipo4 EXPORT hipo4-export diff --git a/cmake/LZ4Config.cmake b/cmake/LZ4Config.cmake index 943bf59..cfab0e3 100644 --- a/cmake/LZ4Config.cmake +++ b/cmake/LZ4Config.cmake @@ -3,7 +3,7 @@ # set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH}:${CMAKE_INSTALL_PREFIX}/lib/pkgconfig") find_package(PkgConfig REQUIRED) -pkg_check_modules(LZ4 liblz4) +pkg_check_modules(LZ4 IMPORTED_TARGET "liblz4") if (NOT LZ4_FOUND) message(STATUS "No system version of LZ4 found.") From 9f8f4f17dd7525b1aa70ee0a77c7015d9371b715 Mon Sep 17 00:00:00 2001 From: Maurik Holtrop Date: Fri, 9 Feb 2024 13:18:32 -0500 Subject: [PATCH 7/7] Cleanup. Seems to work in Intel Mac --- CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95394bf..14d730d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,11 +76,6 @@ if(NOT LZ4_FOUND) endif() add_compile_definitions(__LZ4__) -# Debug LZ4 section. -#include(/Users/maurik/cmake/cmake_debug_properties.cmake ) -#print_target_properties(PkgConfig::LZ4) -#include(CMakePrintHelpers) -#cmake_print_properties(TARGETS PkgConfig::LZ4 PROPERTIES NAME IMPORTED INTERFACE_INCLUDE_DIRECTORIES INTERFACE_LINK_LIBRARIES) set(DATAFRAME_IN_MAIN TRUE) add_subdirectory(extensions/dataframes)