Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addons refactoring #194

Merged
merged 6 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 3 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,6 @@ if(WITH_ACTS)
endif()


if(WITH_ONNX)
find_package(ONNXRuntime)
find_package(nlohmann_json)
if(ONNXRuntime_FOUND AND nlohmann_json_FOUND)
message(STATUS "includes-------------------------- dataframe onnxruntime: ${ONNXRUNTIME_INCLUDE_DIRS}")
message(STATUS "includes-------------------------- dataframe nlohmann_json")
elseif(WITH_ONNX STREQUAL AUTO)
message(WARNING "ONNXRuntime and/or nlohmann's JSON libraries not found. Skipping ONNX-dependent analyzers.")
set(WITH_ONNX OFF)
else()
message(FATAL_ERROR "Failed to locate ONNXRuntime and/or nlohmann's JSON library!")
endif()
endif()


if(WITH_DD4HEP)
find_package(DD4hep)
if(DD4hep_FOUND)
Expand Down Expand Up @@ -124,7 +109,7 @@ endif()

#--- add CMake infrastructure --------------------------------------------------
include(cmake/FCCAnalysesCreateConfig.cmake)

include(cmake/FCCAnalysesFunctions.cmake)

file(COPY bin/fccanalysis
DESTINATION ${CMAKE_BINARY_DIR}
Expand Down Expand Up @@ -156,9 +141,10 @@ message(STATUS "Library---------------------- main: ${AWKWARD_LIBRARIES}")

#--- Descend into subdirectories ----------------------------------------------

set(ADDONS_LIBRARIES CACHE STRING "List of external libraries the RDF utilities will be linked against")
add_subdirectory(addons)
add_subdirectory(analyzers/dataframe)


if(FCCANALYSES_CASESTUDIES)
add_subdirectory(analyzers/dataframe/case-studies FCCANALYSES_CASESTUDIES)
endif()
Expand Down
4 changes: 4 additions & 0 deletions addons/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_subdirectory(ONNXRuntime)

set(ADDONS_LIBRARIES ${ADDONS_LIBRARIES} PARENT_SCOPE)
message(STATUS ">>> list of additional libraries: ${ADDONS_LIBRARIES}")
49 changes: 49 additions & 0 deletions addons/ONNXRuntime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
if(WITH_ONNX STREQUAL OFF)
return()
endif()

find_package(ONNXRuntime)
find_package(nlohmann_json)
find_package(ROOT COMPONENTS ROOTVecOps)
if(ONNXRuntime_FOUND AND nlohmann_json_FOUND)
message(STATUS "includes-------------------------- onnxruntime: ${ONNXRUNTIME_INCLUDE_DIRS}")
elseif(WITH_ONNX STREQUAL AUTO)
message(WARNING "ONNXRuntime and/or nlohmann's JSON libraries not found. Skipping ONNX-dependent analyzers.")
set(WITH_ONNX OFF)
return()
else()
message(FATAL_ERROR "Failed to locate ONNXRuntime and/or nlohmann's JSON library!")
endif()

file(GLOB sources src/*.cc)
file(GLOB headers *.h)

add_library(ONNXRuntime SHARED ${sources} ${headers})
target_link_libraries(ONNXRuntime PUBLIC ROOT::ROOTVecOps ${ONNXRUNTIME_LIBRARIES} nlohmann_json::nlohmann_json)
target_include_directories(ONNXRuntime PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/addons> ${ONNXRUNTIME_INCLUDE_DIRS})
list(APPEND ADDONS_LIBRARIES ONNXRuntime)
set(ADDONS_LIBRARIES ${ADDONS_LIBRARIES} PARENT_SCOPE)
install(TARGETS ONNXRuntime
EXPORT FCCAnalysesTargets
RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin
LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT shlib
PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/ONNXRuntime"
COMPONENT onnxruntime)

find_catch_instance()
if(Catch2_FOUND)
# add all unit tests
add_executable(onnxruntime-unittest test/onnxtest.cpp)
target_link_libraries(onnxruntime-unittest PUBLIC FCCAnalyses gfortran PRIVATE Catch2::Catch2WithMain ONNXRuntime)
target_include_directories(onnxruntime-unittest PUBLIC ${VDT_INCLUDE_DIR} ${ONNXRUNTIME_INCLUDE_DIRS})
target_compile_definitions(onnxruntime-unittest PUBLIC "-DTEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}")
include(Catch)
catch_discover_tests(onnxruntime-unittest
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
TEST_PREFIX "UT_" # make it possible to filter easily with -R ^UT
TEST_SPEC ${filter_tests} # discover only tests that are known to not fail
)
endif()

# add all integration tests
add_integration_test("examples/FCCee/test/weaver_inference.py")
forthommel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef FCCAnalyses_ONNXRuntime_h
#define FCCAnalyses_ONNXRuntime_h
#ifndef ONNXRuntime_ONNXRuntime_h
#define ONNXRuntime_ONNXRuntime_h

#include <string>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef FCCAnalyses_WeaverInterface_h
#define FCCAnalyses_WeaverInterface_h
#ifndef ONNXRuntime_WeaverInterface_h
#define ONNXRuntime_WeaverInterface_h

#include "FCCAnalyses/ONNXRuntime.h"
#include "ONNXRuntime/ONNXRuntime.h"
#include "ROOT/RVec.hxx"

namespace FCCAnalyses {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "FCCAnalyses/ONNXRuntime.h"
#include "ONNXRuntime/ONNXRuntime.h"

#include "onnxruntime/core/session/experimental_onnxruntime_cxx_api.h"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "FCCAnalyses/WeaverInterface.h"
#include "ONNXRuntime/WeaverInterface.h"

#include "nlohmann/json.hpp"
#include <fstream>
Expand Down
File renamed without changes.
25 changes: 6 additions & 19 deletions analyzers/dataframe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,10 @@
find_package(Vdt)


message(STATUS "includes-------------------------- dataframe awkward: ${AWKWARD_INCLUDE}")
message(STATUS "includes-------------------------- dataframe edm4hep: ${EDM4HEP_INCLUDE_DIRS}")
message(STATUS "includes-------------------------- dataframe podio : ${podio_INCLUDE_DIR}")
message(STATUS "includes-------------------------- dataframe fastjet: ${FASTJET_INCLUDE_DIRS}")

set(EXTRA_INCLUDE_DIRS)
set(EXTRA_LIBRARIES)

if(WITH_ONNX)
list(APPEND EXTRA_INCLUDE_DIRS ${ONNXRUNTIME_INCLUDE_DIRS})
list(APPEND EXTRA_LIBRARIES ${ONNXRUNTIME_LIBRARIES} nlohmann_json::nlohmann_json)
include_directories(${ONNXRUNTIME_INCLUDE_DIRS})
endif()
message(STATUS "includes-------------------------- dataframe awkward: ${AWKWARD_INCLUDE}")
message(STATUS "includes-------------------------- dataframe edm4hep: ${EDM4HEP_INCLUDE_DIRS}")
message(STATUS "includes-------------------------- dataframe podio : ${podio_INCLUDE_DIR}")
message(STATUS "includes-------------------------- dataframe fastjet: ${FASTJET_INCLUDE_DIRS}")


file(GLOB sources src/*.cc)
Expand All @@ -31,10 +22,6 @@ if(NOT WITH_DD4HEP)
list(FILTER sources EXCLUDE REGEX "CaloNtupleizer.cc")
endif()
if(NOT WITH_ONNX)
list(FILTER headers EXCLUDE REGEX "JetFlavourUtils.h")
list(FILTER sources EXCLUDE REGEX "JetFlavourUtils.cc")
list(FILTER headers EXCLUDE REGEX "ONNXRuntime.h")
list(FILTER sources EXCLUDE REGEX "ONNXRuntime.cc")
list(FILTER headers EXCLUDE REGEX "WeaverInterface.h")
list(FILTER sources EXCLUDE REGEX "WeaverInterface.cc")
endif()
Expand All @@ -53,11 +40,11 @@ message(STATUS "CMAKE_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR}")
add_library(FCCAnalyses SHARED ${sources} ${headers} )
target_include_directories(FCCAnalyses PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/addons>
$<INSTALL_INTERFACE:include>
${FASTJET_INCLUDE_DIR}
${VDT_INCLUDE_DIR}
${AWKWARD_INCLUDE}
${EXTRA_INCLUDE_DIRS}
)


Expand All @@ -76,7 +63,7 @@ target_link_libraries(FCCAnalyses
${LIBAWKWARD}
${CPU-KERNELS}
${LIBDL}
${EXTRA_LIBRARIES}
${ADDONS_LIBRARIES}
gfortran # todo: why necessary?
)

Expand Down
2 changes: 1 addition & 1 deletion analyzers/dataframe/src/JetFlavourUtils.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "FCCAnalyses/JetFlavourUtils.h"
#include "FCCAnalyses/WeaverInterface.h"
#include "ONNXRuntime/WeaverInterface.h"

#include <memory>

Expand Down
60 changes: 60 additions & 0 deletions cmake/FCCAnalysesFunctions.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
macro(find_catch_instance)
if(USE_EXTERNAL_CATCH2)
find_package(Catch2 REQUIRED)
else()
message(STATUS "Fetching local copy of Catch2 library for unit-tests...")
# Build Catch2 with the default flags, to avoid generating warnings when we
# build it
set(CXX_FLAGS_CMAKE_USED ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_CMAKE_DEFAULTS})
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 037ddbc75cc5e58b93cf5a010a94b32333ad824d
)
FetchContent_MakeAvailable(Catch2)
set(CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras ${CMAKE_MODULE_PATH})
# Disable clang-tidy on external contents
set_target_properties(Catch2 PROPERTIES CXX_CLANG_TIDY "")

# Hack around the fact, that the include directories are not declared as
# SYSTEM for the targets defined this way. Otherwise warnings can still occur
# in Catch2 code when templates are evaluated (which happens quite a bit)
get_target_property(CATCH2_IF_INC_DIRS Catch2 INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(Catch2 PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${CATCH2_IF_INC_DIRS}")

# Reset the flags
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_CMAKE_USED})
endif()
endmacro()

function(add_integration_test _testname)

add_test(NAME ${_testname}
COMMAND python config/FCCAnalysisRun.py ${_testname} --test --nevents 100 --bench
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/analyzers/dataframe:$ENV{LD_LIBRARY_PATH}
PYTHONPATH=${CMAKE_SOURCE_DIR}:$ENV{PYTHONPATH}
ROOT_INCLUDE_PATH=${CMAKE_SOURCE_DIR}/analyzers/dataframe:$ENV{ROOT_INCLUDE_PATH}
TEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}
)
endfunction()

function(add_integration_test_2 _testname)

add_test(NAME fccanalysisrun_${_testname}
# todo: figure out how to make ctest pick fccanalysis up from PATH
COMMAND ${CMAKE_SOURCE_DIR}/bin/fccanalysis run ${_testname} --test --nevents 100 --bench
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_property(TEST fccanalysisrun_${_testname} APPEND PROPERTY ENVIRONMENT
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/analyzers/dataframe:$ENV{LD_LIBRARY_PATH}
PYTHONPATH=${CMAKE_SOURCE_DIR}:$ENV{PYTHONPATH}
PATH=${CMAKE_SOURCE_DIR}/bin:$CMAKE_BINARY_DIR:$ENV{PATH}
ROOT_INCLUDE_PATH=${CMAKE_SOURCE_DIR}/analyzers/dataframe:$ENV{ROOT_INCLUDE_PATH}
TEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}
)
endfunction()
33 changes: 0 additions & 33 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,9 @@ add_subdirectory(unittest)

add_subdirectory(benchmark)

function(add_integration_test _testname)

add_test(NAME ${_testname}
COMMAND python config/FCCAnalysisRun.py ${_testname} --test --nevents 100 --bench
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/analyzers/dataframe:$ENV{LD_LIBRARY_PATH}
PYTHONPATH=${CMAKE_SOURCE_DIR}:$ENV{PYTHONPATH}
ROOT_INCLUDE_PATH=${CMAKE_SOURCE_DIR}/analyzers/dataframe:$ENV{ROOT_INCLUDE_PATH}
TEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}
)
endfunction()

function(add_integration_test_2 _testname)

add_test(NAME fccanalysisrun_${_testname}
# todo: figure out how to make ctest pick fccanalysis up from PATH
COMMAND ${CMAKE_SOURCE_DIR}/bin/fccanalysis run ${_testname} --test --nevents 100 --bench
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
set_property(TEST fccanalysisrun_${_testname} APPEND PROPERTY ENVIRONMENT
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/analyzers/dataframe:$ENV{LD_LIBRARY_PATH}
PYTHONPATH=${CMAKE_SOURCE_DIR}:$ENV{PYTHONPATH}
PATH=${CMAKE_SOURCE_DIR}/bin:$CMAKE_BINARY_DIR:$ENV{PATH}
ROOT_INCLUDE_PATH=${CMAKE_SOURCE_DIR}/analyzers/dataframe:$ENV{ROOT_INCLUDE_PATH}
TEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}
)
endfunction()


add_integration_test_2("examples/FCCee/higgs/mH-recoil/mumu/analysis_stage1.py")

add_integration_test("examples/FCCee/higgs/mH-recoil/mumu/analysis_stage1.py")
add_integration_test("examples/FCCee/flavour/Bc2TauNu/analysis_B2TauNu_truth.py")
add_integration_test("examples/FCCee/test/jet_constituents.py")
if(${WITH_ONNX})
add_integration_test("examples/FCCee/test/weaver_inference.py")
endif()
47 changes: 4 additions & 43 deletions tests/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,12 @@

if(USE_EXTERNAL_CATCH2)
find_package(Catch2 REQUIRED)
else()
message(STATUS "Fetching local copy of Catch2 library for unit-tests...")
# Build Catch2 with the default flags, to avoid generating warnings when we
# build it
set(CXX_FLAGS_CMAKE_USED ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_CMAKE_DEFAULTS})
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 037ddbc75cc5e58b93cf5a010a94b32333ad824d
)
FetchContent_MakeAvailable(Catch2)
set(CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras ${CMAKE_MODULE_PATH})
# Disable clang-tidy on external contents
set_target_properties(Catch2 PROPERTIES CXX_CLANG_TIDY "")

# Hack around the fact, that the include directories are not declared as
# SYSTEM for the targets defined this way. Otherwise warnings can still occur
# in Catch2 code when templates are evaluated (which happens quite a bit)
get_target_property(CATCH2_IF_INC_DIRS Catch2 INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(Catch2 PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${CATCH2_IF_INC_DIRS}")

# Reset the flags
set(CMAKE_CXX_FLAGS ${CXX_FLAGS_CMAKE_USED})

endif()

find_catch_instance()

# The unittests are a bit better and they are labelled so we can put together a
# list of labels that we want to ignore
set(filter_tests "")

set(EXTRA_TESTS)
set(EXTRA_INCLUDE_DIRS)
set(EXTRA_LIBRARIES)
if(${WITH_ONNX})
list(APPEND EXTRA_TESTS onnxtest.cpp)
list(APPEND EXTRA_INCLUDE_DIRS ${ONNXRUNTIME_INCLUDE_DIRS})
list(APPEND EXTRA_LIBRARIES ${ONNXRUNTIME_LIBRARIES} nlohmann_json::nlohmann_json)
endif()

add_executable(unittest unittest.cpp myutils.cpp algorithms.cpp ${EXTRA_TESTS})
target_link_libraries(unittest PUBLIC FCCAnalyses gfortran PRIVATE Catch2::Catch2WithMain ${EXTRA_LIBRARIES})
target_include_directories(unittest PUBLIC ${VDT_INCLUDE_DIR} ${EXTRA_INCLUDE_DIRS})
add_executable(unittest unittest.cpp myutils.cpp algorithms.cpp)
target_link_libraries(unittest PUBLIC FCCAnalyses gfortran PRIVATE Catch2::Catch2WithMain)
target_include_directories(unittest PUBLIC ${VDT_INCLUDE_DIR})
target_compile_definitions(unittest PUBLIC "-DTEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}")
include(Catch)
catch_discover_tests(unittest
Expand Down