Skip to content

Commit

Permalink
build: EDM4hep python bindings go to separate shared lib (#2996)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger authored Mar 1, 2024
1 parent 6ef4e4e commit 16e558f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 59 deletions.
27 changes: 15 additions & 12 deletions Examples/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ file(MAKE_DIRECTORY ${_python_dir}/acts)

set(_python_install_dir "python/acts")

pybind11_add_module(ActsPythonBindings
pybind11_add_module(ActsPythonBindings
src/ModuleEntry.cpp
src/Framework.cpp
src/Base.cpp
Expand All @@ -33,8 +33,8 @@ install(TARGETS ActsPythonBindings DESTINATION ${_python_install_dir})
set_target_properties(ActsPythonBindings PROPERTIES INSTALL_RPATH "\$ORIGIN/../../${CMAKE_INSTALL_LIBDIR}")
set_target_properties(ActsPythonBindings PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${_python_dir}/acts)

target_link_libraries(ActsPythonBindings PUBLIC
ActsCore
target_link_libraries(ActsPythonBindings PUBLIC
ActsCore
ActsPythonUtilities
ActsExamplesFramework
ActsExamplesGeometry
Expand All @@ -59,8 +59,8 @@ target_link_libraries(ActsPythonBindings PUBLIC
ActsExamplesAmbiguityResolution
)

set(py_files
__init__.py
set(py_files
__init__.py
examples/__init__.py
examples/simulation.py
examples/reconstruction.py
Expand All @@ -85,7 +85,7 @@ endif()

if(ACTS_BUILD_PLUGIN_DD4HEP AND ACTS_BUILD_EXAMPLES_DD4HEP)
pybind11_add_module(ActsPythonBindingsDD4hep src/DD4hepComponent.cpp)
target_link_libraries(ActsPythonBindingsDD4hep PUBLIC
target_link_libraries(ActsPythonBindingsDD4hep PUBLIC
ActsPythonUtilities
ActsExamplesDetectorDD4hep)
add_dependencies(ActsPythonBindings ActsPythonBindingsDD4hep)
Expand All @@ -112,7 +112,7 @@ endif()

if(ACTS_BUILD_EXAMPLES_GEANT4)
pybind11_add_module(ActsPythonBindingsGeant4 src/Geant4Component.cpp)
target_link_libraries(ActsPythonBindingsGeant4 PUBLIC
target_link_libraries(ActsPythonBindingsGeant4 PUBLIC
ActsExamplesGeant4 ActsExamplesDetectorGeant4
ActsPythonUtilities ActsExamplesMuonSpectrometerMockupDetector)
add_dependencies(ActsPythonBindings ActsPythonBindingsGeant4)
Expand All @@ -124,7 +124,7 @@ if(ACTS_BUILD_EXAMPLES_GEANT4)

if(ACTS_BUILD_PLUGIN_DD4HEP AND ACTS_BUILD_EXAMPLES_DD4HEP)
pybind11_add_module(ActsPythonBindingsDDG4 src/Geant4DD4hepComponent.cpp)
target_link_libraries(ActsPythonBindingsDDG4 PUBLIC
target_link_libraries(ActsPythonBindingsDDG4 PUBLIC
ActsPythonUtilities
ActsExamplesGeant4
ActsExamplesDetectorDD4hep)
Expand Down Expand Up @@ -162,11 +162,14 @@ else()
endif()

if(ACTS_BUILD_EXAMPLES_EDM4HEP)
target_link_libraries(ActsPythonBindings PUBLIC ActsExamplesIoEDM4hep)
target_sources(ActsPythonBindings PRIVATE src/EDM4hep.cpp)
pybind11_add_module(ActsPythonBindingsEDM4hep src/EDM4hepComponent.cpp)
target_link_libraries(ActsPythonBindingsEDM4hep PUBLIC
ActsPythonUtilities ActsExamplesIoEDM4hep)
add_dependencies(ActsPythonBindings ActsPythonBindingsEDM4hep)
install(TARGETS ActsPythonBindingsEDM4hep DESTINATION ${_python_install_dir})
set_target_properties(ActsPythonBindingsEDM4hep PROPERTIES INSTALL_RPATH "\$ORIGIN../../${CMAKE_INSTALL_LIBDIR}")
set_target_properties(ActsPythonBindingsEDM4hep PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${_python_dir}/acts)
list(APPEND py_files examples/edm4hep.py)
else()
target_sources(ActsPythonBindings PRIVATE src/EDM4hepStub.cpp)
endif()

if(ACTS_BUILD_PLUGIN_ONNX)
Expand Down
9 changes: 3 additions & 6 deletions Examples/Python/python/acts/examples/edm4hep.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
from acts._adapter import _patch_config
from acts import ActsPythonBindings
from acts import ActsPythonBindingsEDM4hep

if not hasattr(ActsPythonBindings._examples, "_edm4hep"):
raise ImportError("ActsPythonBindings._examples._edm4hep not found")
_patch_config(ActsPythonBindingsEDM4hep)

_patch_config(ActsPythonBindings._examples._edm4hep)

from acts.ActsPythonBindings._examples._edm4hep import *
from acts.ActsPythonBindingsEDM4hep import *
Original file line number Diff line number Diff line change
Expand Up @@ -26,48 +26,40 @@ namespace py = pybind11;
using namespace pybind11::literals;

using namespace Acts;
using namespace Acts::Python;

namespace Acts::Python {

void addEDM4hep(Context& ctx) {
auto mex = ctx.get("examples");
auto edm4hep = mex.def_submodule("_edm4hep");

PYBIND11_MODULE(ActsPythonBindingsEDM4hep, m) {
ACTS_PYTHON_DECLARE_READER(
ActsExamples::EDM4hepReader, edm4hep, "EDM4hepReader", inputPath,
ActsExamples::EDM4hepReader, m, "EDM4hepReader", inputPath,
inputParticles, inputSimHits, outputParticlesInitial,
outputParticlesFinal, outputParticlesGenerator, outputSimHits,
graphvizOutput, dd4hepDetector, trackingGeometry, sortSimHitsInTime);

ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepSimHitWriter, edm4hep,
"EDM4hepSimHitWriter", inputSimHits,
inputParticles, outputPath, outputParticles,
outputSimTrackerHits);
ACTS_PYTHON_DECLARE_WRITER(
ActsExamples::EDM4hepSimHitWriter, m, "EDM4hepSimHitWriter", inputSimHits,
inputParticles, outputPath, outputParticles, outputSimTrackerHits);

ACTS_PYTHON_DECLARE_READER(ActsExamples::EDM4hepMeasurementReader, edm4hep,
ACTS_PYTHON_DECLARE_READER(ActsExamples::EDM4hepMeasurementReader, m,
"EDM4hepMeasurementReader", inputPath,
outputMeasurements, outputMeasurementSimHitsMap,
outputSourceLinks, outputClusters);

ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepMeasurementWriter, edm4hep,
ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepMeasurementWriter, m,
"EDM4hepMeasurementWriter", inputMeasurements,
inputClusters, outputPath);

ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepParticleWriter, edm4hep,
ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepParticleWriter, m,
"EDM4hepParticleWriter", inputParticles,
outputPath, outputParticles);

ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepMultiTrajectoryWriter,
edm4hep, "EDM4hepMultiTrajectoryWriter",
inputTrajectories, inputMeasurementParticlesMap,
outputPath, Bz);
ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepMultiTrajectoryWriter, m,
"EDM4hepMultiTrajectoryWriter", inputTrajectories,
inputMeasurementParticlesMap, outputPath, Bz);

ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepTrackWriter, edm4hep,
ACTS_PYTHON_DECLARE_WRITER(ActsExamples::EDM4hepTrackWriter, m,
"EDM4hepTrackWriter", inputTracks, outputPath, Bz);

ACTS_PYTHON_DECLARE_READER(ActsExamples::EDM4hepTrackReader, edm4hep,
ACTS_PYTHON_DECLARE_READER(ActsExamples::EDM4hepTrackReader, m,
"EDM4hepTrackReader", inputTracks, outputTracks,
inputPath, Bz);
}

} // namespace Acts::Python
17 changes: 0 additions & 17 deletions Examples/Python/src/EDM4hepStub.cpp

This file was deleted.

2 changes: 0 additions & 2 deletions Examples/Python/src/ModuleEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ void addPythia8(Context& ctx);
void addJson(Context& ctx);
void addHepMC3(Context& ctx);
void addExaTrkXTrackFinding(Context& ctx);
void addEDM4hep(Context& ctx);
void addSvg(Context& ctx);
void addObj(Context& ctx);
void addOnnx(Context& ctx);
Expand Down Expand Up @@ -122,7 +121,6 @@ PYBIND11_MODULE(ActsPythonBindings, m) {
addJson(ctx);
addHepMC3(ctx);
addExaTrkXTrackFinding(ctx);
addEDM4hep(ctx);
addObj(ctx);
addSvg(ctx);
addOnnx(ctx);
Expand Down

0 comments on commit 16e558f

Please sign in to comment.