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

feat: Decouple DD4hep detector construction from ACTS #1241

Merged
merged 22 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ jobs:
-DCMAKE_CXX_STANDARD=17
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
-DACTS_BUILD_EVERYTHING=ON
-DACTS_BUILD_ODD=ON
-DACTS_BUILD_EXAMPLES_PYTHON_BINDINGS=ON
-DACTS_FORCE_ASSERTIONS=ON

Expand Down Expand Up @@ -186,7 +187,9 @@ jobs:
run: mkdir build && tar xf build.tar.gz -C build

- name: Examples
run: ./CI/run_examples.sh
run: >
export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH
&& ./CI/run_examples.sh

- name: Python level tests
shell: bash
Expand All @@ -196,6 +199,7 @@ jobs:
&& source /usr/local/bin/thisdd4hep_only.sh
&& source /usr/local/bin/geant4.sh
&& source build/python/setup.sh
&& export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH
&& pip3 install -r Examples/Python/tests/requirements.txt
&& pytest -rFs

Expand Down Expand Up @@ -233,6 +237,7 @@ jobs:
&& source /usr/local/bin/thisdd4hep_only.sh
&& source /usr/local/bin/geant4.sh
&& source build/python/setup.sh
&& export LD_LIBRARY_PATH=$PWD/build/thirdparty/OpenDataDetector/factory:$LD_LIBRARY_PATH
&& echo "::endgroup::"
&& CI/physmon/phys_perf_mon.sh physmon

Expand Down Expand Up @@ -341,7 +346,11 @@ jobs:
env:
INSTALL_DIR: ${{ github.workspace }}/install
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
lfs: true

- name: Install dependencies
run: >
brew install cmake eigen ninja ccache
Expand Down Expand Up @@ -371,6 +380,7 @@ jobs:
-DCMAKE_INSTALL_PREFIX="${INSTALL_DIR}"
-DCMAKE_PREFIX_PATH=/usr/local/acts
-DACTS_BUILD_EVERYTHING=ON
-DACTS_BUILD_ODD=ON
-DACTS_LOG_FAILURE_THRESHOLD=WARNING
-DACTS_FORCE_ASSERTIONS=ON
- name: Build
Expand Down
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ option(ACTS_USE_SYSTEM_AUTODIFF "Use autodiff provided by the system instead of
option(ACTS_BUILD_PLUGIN_CUDA "Build CUDA plugin" OFF)
option(ACTS_BUILD_PLUGIN_DD4HEP "Build DD4hep plugin" OFF)
option(ACTS_BUILD_PLUGIN_EXATRKX "Build the Exa.TrkX plugin" OFF)
option(ACTS_USE_SYSTEM_ACTSDD4HEP "Use the ActsDD4hep glue library provided by the system instead of building it" OFF)
option(ACTS_BUILD_PLUGIN_IDENTIFICATION "Build Identification plugin" OFF)
option(ACTS_BUILD_PLUGIN_JSON "Build json plugin" OFF)
option(ACTS_USE_SYSTEM_NLOHMANN_JSON "Use nlohmann::json provided by the system instead of the bundled version" OFF)
Expand Down Expand Up @@ -67,6 +68,7 @@ option(ACTS_SETUP_BOOST "Explicitly set up Boost for the project" ON)
option(ACTS_USE_SYSTEM_BOOST "Use a system-provided boost" ON)
option(ACTS_SETUP_EIGEN3 "Explicitly set up Eigen3 for the project" ON)
option(ACTS_USE_SYSTEM_EIGEN3 "Use a system-provided eigen3" ON)
option(ACTS_BUILD_ODD "Build the OpenDataDetector" OFF)

# handle option inter-dependencies and the everything flag
# NOTE: ordering is important here. dependencies must come before dependees
Expand Down Expand Up @@ -151,6 +153,7 @@ endif()
set(_acts_autodiff_version 0.6)
set(_acts_boost_version 1.71.0)
set(_acts_dd4hep_version 1.11)
set(_acts_actsdd4hep_version 1.0.0)
set(_acts_doxygen_version 1.8.15)
set(_acts_eigen3_version 3.3.7)
set(_acts_hepmc3_version 3.2.1)
Expand Down Expand Up @@ -239,6 +242,12 @@ if(ACTS_BUILD_PLUGIN_CUDA)
endif()
if(ACTS_BUILD_PLUGIN_DD4HEP)
find_package(DD4hep ${_acts_dd4hep_version} REQUIRED CONFIG COMPONENTS DDCore DDDetectors)
if(ACTS_USE_SYSTEM_ACTSDD4HEP)
find_package(ActsDD4hep ${_acts_actsdd4hep_version} CONFIG REQUIRED)
else()
add_subdirectory(thirdparty/actsdd4hep)
endif()

endif()
if(ACTS_BUILD_PLUGIN_JSON)
if(ACTS_USE_SYSTEM_NLOHMANN_JSON)
Expand Down Expand Up @@ -314,6 +323,16 @@ add_subdirectory(Plugins)
add_component_if(Fatras Fatras ACTS_BUILD_FATRAS)
add_component_if(Alignment Alignment ACTS_BUILD_ALIGNMENT)

if(ACTS_BUILD_ODD)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/thirdparty/OpenDataDetector/CMakeLists.txt")
add_subdirectory_if(thirdparty/OpenDataDetector ACTS_BUILD_ODD)
else()
message(FATAL_ERROR "ODD build was requested, but the ODD directory seems not to be present. "
"Did you init and update the submodule?")
endif()
endif()


# examples
add_subdirectory_if(Examples ACTS_BUILD_EXAMPLES)

Expand Down
7 changes: 0 additions & 7 deletions Examples/Detectors/DD4hepDetector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ add_library(
src/DD4hepGeometryService.cpp
src/DetUtils.cpp)

file(GLOB _odd "${CMAKE_SOURCE_DIR}/thirdparty/OpenDataDetector/factory/tracker/*")
if(NOT _odd)
message(WARNING "The ODD directory seems not to be present. Did you run init the submodule?")
else()
target_compile_definitions(ActsExamplesDetectorDD4hep PUBLIC ODD_ACTS_EXTENSION)
endif()
target_sources(ActsExamplesDetectorDD4hep PUBLIC ${_odd})

target_include_directories(
ActsExamplesDetectorDD4hep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "Acts/Plugins/DD4hep/ConvertDD4hepMaterial.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"

Expand Down
4 changes: 4 additions & 0 deletions Examples/Detectors/DD4hepDetector/src/DD4hepDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ auto DD4hepDetector::finalize(
std::make_shared<ActsExamples::DD4hep::DD4hepGeometryService>(config);
TrackingGeometryPtr dd4tGeometry =
geometrySvc->trackingGeometry(dd4HepContext);
if (!dd4tGeometry) {
throw std::runtime_error{
"Did not receive tracking geometry from DD4hep geometry service"};
}
ContextDecorators dd4ContextDeocrators = {};
// return the pair of geometry and empty decorators
return std::make_pair<TrackingGeometryPtr, ContextDecorators>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "Acts/Plugins/DD4hep/ConvertDD4hepMaterial.hpp"
#include "ActsDD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ConvertMaterial.hpp"

#include <string>
#include <vector>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "../DetUtils.h"
#include "DD4hep/DetFactoryHelper.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "../DetUtils.h"
#include "DD4hep/DetFactoryHelper.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Author : F.Gaede
//
//====================================================================
#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"
#include "ActsExamples/DD4hepDetector/DD4hepDetectorHelper.hpp"

#include "DD4hep/DetFactoryHelper.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"
#include "ActsExamples/DD4hepDetector/DD4hepDetectorHelper.hpp"

#include "DD4hep/DetFactoryHelper.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

#include "DD4hep/DetFactoryHelper.h"
#include "XML/XMLElements.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace dd4hep;
// using namespace DDSurfaces;

#include "Acts/Definitions/Units.hpp"
#include "Acts/Plugins/DD4hep/ActsExtension.hpp"
#include "ActsDD4hep/ActsExtension.hpp"

static Ref_t create_element(Detector& lcdd, xml_h e, SensitiveDetector sens) {
xml_det_t x_det = e;
Expand Down
7 changes: 6 additions & 1 deletion Examples/Python/tests/helpers/hash_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ def hash_root_file(path: Path, ordering_invariant: bool = True) -> str:
for tree_name in sorted(rf.keys()):
gh.update(tree_name.encode("utf8"))

tree = rf[tree_name]
try:
tree = rf[tree_name]
if not isinstance(tree, uproot.TTree):
continue
except NotImplementedError:
continue
keys = list(sorted(tree.keys()))

branches = tree.arrays(library="ak")
Expand Down
10 changes: 2 additions & 8 deletions Examples/Python/tests/test_detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest

from helpers import dd4hepEnabled
from common import getOpenDataDetectorDirectory
from common import getOpenDataDetector

import acts.examples

Expand Down Expand Up @@ -32,12 +32,6 @@ def test_generic_geometry():

@pytest.mark.skipif(not dd4hepEnabled, reason="DD4hep is not set up")
def test_odd():
from acts.examples.dd4hep import DD4hepGeometryService, DD4hepDetector

dd4hepConfig = DD4hepGeometryService.Config(
xmlFileNames=[str(getOpenDataDetectorDirectory() / "xml/OpenDataDetector.xml")]
)
detector = DD4hepDetector()

config = acts.MaterialMapJsonConverter.Config()
matDeco = acts.JsonMaterialDecorator(
Expand All @@ -46,7 +40,7 @@ def test_odd():
level=acts.logging.WARNING,
)

geo, _ = detector.finalize(dd4hepConfig, matDeco)
detector, geo, _ = getOpenDataDetector(matDeco)

assert count_surfaces(geo) == 18824

Expand Down
2 changes: 2 additions & 0 deletions Examples/Python/tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,8 @@ def test_vertex_fitting_reading(
@pytest.mark.skipif(not dd4hepEnabled, reason="DD4hep not set up")
def test_full_chain_odd_example(tmp_path):
# This test literally only ensures that the full chain example can run without erroring out
getOpenDataDetector() # just to make sure it can build

script = (
Path(__file__).parent.parent.parent.parent
/ "Examples"
Expand Down
38 changes: 35 additions & 3 deletions Examples/Scripts/Python/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import acts
import acts.examples
import os
import sys


from pathlib import Path

Expand All @@ -11,12 +14,41 @@ def getOpenDataDetectorDirectory():


def getOpenDataDetector(mdecorator=None):
import acts.examples.dd4hep

odd_dir = getOpenDataDetectorDirectory()

odd_xml = odd_dir / "xml" / "OpenDataDetector.xml"
if not odd_xml.exists():
raise RuntimeError(f"OpenDataDetector.xml not found at {odd_xml}")

env_vars = []
map_name = "libOpenDataDetector.components"
lib_name = None
if sys.platform == "linux":
env_vars = ["LD_LIBRARY_PATH"]
lib_name = "libOpenDataDetector.so"
elif sys.platform == "darwin":
env_vars = ["DYLD_LIBRARY_PATH", "DD4HEP_LIBRARY_PATH"]
lib_name = "libOpenDataDetector.dyld"

if lib_name is not None and len(env_vars) > 0:
found = False
for env_var in env_vars:
for lib_dir in os.environ.get(env_var, "").split(":"):
lib_dir = Path(lib_dir)
if (lib_dir / map_name).exists() and (lib_dir / lib_name).exists():
found = True
break
if not found:
msg = (
"Unable to find OpenDataDetector factory library. "
f"You might need to point {'/'.join(env_vars)} at it"
)
raise RuntimeError(msg)

import acts.examples.dd4hep

dd4hepConfig = acts.examples.dd4hep.DD4hepGeometryService.Config(
xmlFileNames=[str(odd_dir / "xml/OpenDataDetector.xml")]
xmlFileNames=[str(odd_xml)]
)
detector = acts.examples.dd4hep.DD4hepDetector()

Expand Down
5 changes: 3 additions & 2 deletions Plugins/DD4hep/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include(FetchContent)

add_library(
ActsPluginDD4hep SHARED
src/ActsExtension.cpp
src/ConvertDD4hepDetector.cpp
src/ConvertDD4hepMaterial.cpp
src/DD4hepDetectorElement.cpp
Expand All @@ -13,7 +14,7 @@ target_include_directories(
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_link_libraries(
ActsPluginDD4hep
PUBLIC ActsCore ActsPluginTGeo)
PUBLIC ActsCore ActsPluginTGeo ActsDD4hep::ActsDD4hep)

if(${DD4hep_VERSION} VERSION_LESS 1.11)
target_include_directories(ActsPluginDD4hep PUBLIC ${DD4hep_INCLUDE_DIRS})
Expand Down
Loading