From ee1bec50ef0e4d3cb3bfcd710d16571b0df3fabb Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Wed, 27 Oct 2021 16:35:07 +0200 Subject: [PATCH 1/5] Implement Dummy k4ActsAlgorithm that instantiates a DD4hepPlugin looping over surfaces --- CMakeLists.txt | 1 + README.md | 10 ++-- k4ActsTracking/CMakeLists.txt | 15 +++-- k4ActsTracking/options/run_acts_plugin.py | 21 +++++++ k4ActsTracking/src/components/ActsAlg.cpp | 30 ++++++++++ .../src/components/{EmptyAlg.h => ActsAlg.h} | 6 +- k4ActsTracking/src/components/EmptyAlg.cpp | 13 ----- .../src/dd4hepplugin/actsdd4hepplugin.cpp | 57 +++++++++++++++++++ 8 files changed, 128 insertions(+), 25 deletions(-) create mode 100644 k4ActsTracking/options/run_acts_plugin.py create mode 100644 k4ActsTracking/src/components/ActsAlg.cpp rename k4ActsTracking/src/components/{EmptyAlg.h => ActsAlg.h} (77%) delete mode 100644 k4ActsTracking/src/components/EmptyAlg.cpp create mode 100644 k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c57ce7..44b0d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,6 +6,7 @@ find_package(ROOT COMPONENTS RIO Tree) find_package(EDM4HEP) find_package(k4FWCore) find_package(Acts) +find_package(DD4hep) #--------------------------------------------------------------- # Load macros and functions for Gaudi-based projects diff --git a/README.md b/README.md index cedaab1..70a7dac 100644 --- a/README.md +++ b/README.md @@ -18,15 +18,15 @@ This repository contains the necessary tools to use ACTS functionality in Key4he * k4FWCore -## Installation +## Compilation and testing ``` +source /cvmfs/sw-nightlies.hsf.org/key4hep/setup.sh mkdir build install cd build; -cmake .. -DCMAKE_INSTALL_PREFIX=../install -make install - - +cmake .. -DCMAKE_INSTALL_PREFIX=../install -G Ninja +ninja +ctest ``` diff --git a/k4ActsTracking/CMakeLists.txt b/k4ActsTracking/CMakeLists.txt index c0ad234..1329ace 100644 --- a/k4ActsTracking/CMakeLists.txt +++ b/k4ActsTracking/CMakeLists.txt @@ -1,16 +1,23 @@ file(GLOB _plugin_sources src/components/*.cpp) gaudi_add_module(k4ActsTrackingPlugins SOURCES ${_plugin_sources} - LINK Gaudi::GaudiKernel Gaudi::GaudiAlgLib k4FWCore::k4FWCore EDM4HEP::edm4hep) + LINK Gaudi::GaudiKernel Gaudi::GaudiAlgLib DD4hep::DDCore) -set(GAUDI_GENCONF_DIR "genConfDir") + +file(GLOB _dd4hep_plugin_sources src/dd4hepplugin/*.cpp) +add_dd4hep_plugin(k4ActsDD4hepPlugin SHARED ${_dd4hep_plugin_sources}) +target_link_libraries(k4ActsDD4hepPlugin DD4hep::DDCore DD4hep::DDRec DD4hep::DDParsers) function(set_test_env _testname) set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT - LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$:$:$:$:$:$ENV{LD_LIBRARY_PATH} - PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/${GAUDI_GENCONF_DIR}:$/../python:$ENV{PYTHONPATH} + LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$:$:$:$:$:$:$ENV{LD_LIBRARY_PATH} + PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/genConf:$/../python:$ENV{PYTHONPATH} PATH=$/../bin:$ENV{PATH} K4ACTSTRACKING=${CMAKE_CURRENT_LIST_DIR}/ ) endfunction() +add_test(NAME ActsAlgTest + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND k4run k4ActsTracking/options/run_acts_plugin.py) +set_test_env(ActsAlgTest) diff --git a/k4ActsTracking/options/run_acts_plugin.py b/k4ActsTracking/options/run_acts_plugin.py new file mode 100644 index 0000000..4cd4970 --- /dev/null +++ b/k4ActsTracking/options/run_acts_plugin.py @@ -0,0 +1,21 @@ +import os +from pprint import pprint +from Gaudi.Configuration import * + +from Configurables import ActsAlg, GeoSvc +algList = [] + +geosvc = GeoSvc("GeoSvc") +# using this instead of CLIC_o3_v14 because it is much faster to instantiate +geosvc.detectors = [os.environ["LCGEO"]+"/CLIC/compact/CLIC_o2_v04/CLIC_o2_v04.xml"] + +a = ActsAlg("MyActsAlg") +algList.append(a) + +from Configurables import ApplicationMgr +ApplicationMgr( TopAlg = algList, + EvtSel = 'NONE', + EvtMax = 2, + ExtSvc = [geosvc], + OutputLevel=INFO + ) diff --git a/k4ActsTracking/src/components/ActsAlg.cpp b/k4ActsTracking/src/components/ActsAlg.cpp new file mode 100644 index 0000000..8943128 --- /dev/null +++ b/k4ActsTracking/src/components/ActsAlg.cpp @@ -0,0 +1,30 @@ +#include "ActsAlg.h" + +#include +#include + +DECLARE_COMPONENT(ActsAlg) + +ActsAlg::ActsAlg(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {} + +ActsAlg::~ActsAlg() {} + +StatusCode ActsAlg::initialize() { + info() << "Initializing the ACTS algorithm" << endmsg; + int argc = 0; + char* argv = {}; + dd4hep::PluginDebug dbg; + std::string name = "k4acts_addActsExtensions"; + long result = dd4hep::PluginService::Create(name, &dd4hep::Detector::getInstance(), argc, &argv); + if (0 == result) { + error() << "Failed to locate plugin " << name << "\n" << dbg.missingFactory(name) << endmsg; + return StatusCode::FAILURE; + } + + info() << "Successfully loaded the plugin!" << endmsg; + return StatusCode::SUCCESS; +} + +StatusCode ActsAlg::execute() { return StatusCode::SUCCESS; } + +StatusCode ActsAlg::finalize() { return StatusCode::SUCCESS; } diff --git a/k4ActsTracking/src/components/EmptyAlg.h b/k4ActsTracking/src/components/ActsAlg.h similarity index 77% rename from k4ActsTracking/src/components/EmptyAlg.h rename to k4ActsTracking/src/components/ActsAlg.h index e33e143..2963d98 100644 --- a/k4ActsTracking/src/components/EmptyAlg.h +++ b/k4ActsTracking/src/components/ActsAlg.h @@ -4,10 +4,10 @@ #include "Gaudi/Property.h" #include "GaudiAlg/GaudiAlgorithm.h" -class EmptyAlg : public GaudiAlgorithm { +class ActsAlg : public GaudiAlgorithm { public: - explicit EmptyAlg(const std::string&, ISvcLocator*); - virtual ~EmptyAlg(); + explicit ActsAlg(const std::string&, ISvcLocator*); + virtual ~ActsAlg(); /** Initialize. * @return status code */ diff --git a/k4ActsTracking/src/components/EmptyAlg.cpp b/k4ActsTracking/src/components/EmptyAlg.cpp deleted file mode 100644 index c656758..0000000 --- a/k4ActsTracking/src/components/EmptyAlg.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include "EmptyAlg.h" - -DECLARE_COMPONENT(EmptyAlg) - -EmptyAlg::EmptyAlg(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {} - -EmptyAlg::~EmptyAlg() {} - -StatusCode EmptyAlg::initialize() { return StatusCode::SUCCESS; } - -StatusCode EmptyAlg::execute() { return StatusCode::SUCCESS; } - -StatusCode EmptyAlg::finalize() { return StatusCode::SUCCESS; } diff --git a/k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp b/k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp new file mode 100644 index 0000000..f125bbc --- /dev/null +++ b/k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include + +#include +#include + +#include + +using dd4hep::DetElement; +using dd4hep::PrintLevel; + +namespace { + + /** Plugin for adding the ACTS Extensions to surface, or DetElements, or something + * + */ + + static long addActsExtensions(dd4hep::Detector& description, int argc, char** argv) { + const std::string LOG_SOURCE("AddActsExtensions"); + printout(PrintLevel::INFO, LOG_SOURCE, "Running extension"); + + dd4hep::rec::SurfaceHelper ds(description.world()); + dd4hep::rec::SurfaceList const& detSL = ds.surfaceList(); + + for (dd4hep::rec::ISurface* surf : detSL) { + dd4hep::Volume volume = ((dd4hep::rec::Surface*)surf)->volume(); + auto* ddsurf = ((dd4hep::rec::Surface*)surf); + auto const volumeName = std::string(volume->GetName()); + if (not ddsurf->detElement().isValid()) + continue; + std::string path = ddsurf->detElement().path(); + + //FIXME: replace this with the ACTS type to be used as an extension + dd4hep::rec::DoubleParameters* para = nullptr; + try { // use existing map, or create a new one + para = ddsurf->detElement().extension(); + para->doubleParameters["SortingPolicy"] = 123; + } catch (...) { + para = new dd4hep::rec::DoubleParameters; + para->doubleParameters["SortingPolicy"] = 321; + ddsurf->detElement().addExtension(para); + } + printout(PrintLevel::INFO, LOG_SOURCE, + "Added extension to %s" + " path %s, type %s, value %3.5f", + volumeName.c_str(), ddsurf->detElement().path().c_str(), ddsurf->detElement().type().c_str(), + para->doubleParameters["SortingPolicy"]); + } // for all surfaces + + return 0; // this return value isn't really returned from the plugin service + } + +} // namespace + +DECLARE_APPLY(k4acts_addActsExtensions, ::addActsExtensions) From ffb6e129bf61189dbe67c68ef1d8a4d0d9ed6d35 Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Wed, 27 Oct 2021 17:05:57 +0200 Subject: [PATCH 2/5] CI: use docker container from github registry --- .github/workflows/test.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80fc54e..b67daf4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,10 +14,7 @@ jobs: - uses: cvmfs-contrib/github-action-cvmfs@v2 - name: Start container run: | - docker run -it --name CI_container -v ${GITHUB_WORKSPACE}:/Package -v /cvmfs:/cvmfs:shared -d clicdp/cc7-lcg /bin/bash - - name: Setup container - run: | - docker exec CI_container /bin/bash -c " ln -s /usr/lib64/liblzma.so.5.2.2 /usr/lib64/liblzma.so;" + docker run -it --name CI_container -v ${GITHUB_WORKSPACE}:/Package -v /cvmfs:/cvmfs:shared -d ghcr.io/aidasoft/centos7:latest /bin/bash - name: CMake Configure run: | docker exec CI_container /bin/bash -c 'cd Package;\ From 484010e7206c6c8158b0455e3bd5c2ff2fd5b194 Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Fri, 29 Oct 2021 13:55:29 +0200 Subject: [PATCH 3/5] CMake: add compiler warnings --- k4ActsTracking/CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/k4ActsTracking/CMakeLists.txt b/k4ActsTracking/CMakeLists.txt index 1329ace..b91f1fa 100644 --- a/k4ActsTracking/CMakeLists.txt +++ b/k4ActsTracking/CMakeLists.txt @@ -4,9 +4,17 @@ gaudi_add_module(k4ActsTrackingPlugins LINK Gaudi::GaudiKernel Gaudi::GaudiAlgLib DD4hep::DDCore) + file(GLOB _dd4hep_plugin_sources src/dd4hepplugin/*.cpp) add_dd4hep_plugin(k4ActsDD4hepPlugin SHARED ${_dd4hep_plugin_sources}) -target_link_libraries(k4ActsDD4hepPlugin DD4hep::DDCore DD4hep::DDRec DD4hep::DDParsers) +target_link_libraries(k4ActsDD4hepPlugin DD4hep::DDCore DD4hep::DDRec DD4hep::DDG4 DD4hep::DDParsers) + + +SET(compile_flags -Wformat-security -Wno-long-long -Wdeprecated -fdiagnostics-color=auto -Wall -Wextra -pedantic) + +target_compile_options(k4ActsTrackingPlugins PUBLIC ${compile_flags}) +target_compile_options(k4ActsDD4hepPlugin PUBLIC ${compile_flags}) + function(set_test_env _testname) set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT From fbc1a2a0819f10e0782b7edccf4d9719a20dd4fc Mon Sep 17 00:00:00 2001 From: Andre Sailer Date: Fri, 29 Oct 2021 13:56:55 +0200 Subject: [PATCH 4/5] k4ActsPlugin: add some show casing of using cellIDcoder to identify layers --- .../src/dd4hepplugin/actsdd4hepplugin.cpp | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp b/k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp index f125bbc..27ef2cc 100644 --- a/k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp +++ b/k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp @@ -3,8 +3,11 @@ #include #include +#include + #include #include +#include #include @@ -17,22 +20,47 @@ namespace { * */ - static long addActsExtensions(dd4hep::Detector& description, int argc, char** argv) { + static long addActsExtensions(dd4hep::Detector& description, int, char**) { const std::string LOG_SOURCE("AddActsExtensions"); - printout(PrintLevel::INFO, LOG_SOURCE, "Running extension"); + printout(PrintLevel::INFO, LOG_SOURCE, "Running plugin"); - dd4hep::rec::SurfaceHelper ds(description.world()); - dd4hep::rec::SurfaceList const& detSL = ds.surfaceList(); + //Getting the surface manager + dd4hep::rec::SurfaceManager& surfMan = *description.extension(); + dd4hep::rec::SurfaceHelper ds(description.world()); + dd4hep::rec::SurfaceList const& detSL = ds.surfaceList(); + int counter = 0; for (dd4hep::rec::ISurface* surf : detSL) { dd4hep::Volume volume = ((dd4hep::rec::Surface*)surf)->volume(); auto* ddsurf = ((dd4hep::rec::Surface*)surf); auto const volumeName = std::string(volume->GetName()); if (not ddsurf->detElement().isValid()) continue; - std::string path = ddsurf->detElement().path(); - //FIXME: replace this with the ACTS type to be used as an extension + dd4hep::BitFieldCoder* cellIDcoder = nullptr; + if (ddsurf->type().isSensitive() and not ddsurf->type().isHelper()) { + // surface is sensitive, assuming it has a readout + auto detectorName = ddsurf->detElement().type(); + try { + auto theDetector = dd4hep::SensitiveDetector(description.sensitiveDetector(detectorName)); + cellIDcoder = theDetector.readout().idSpec().decoder(); + printout(PrintLevel::DEBUG, LOG_SOURCE, "The encoding string for detector %s is %s", detectorName.c_str(), + cellIDcoder->fieldDescription().c_str()); + } catch (...) { + printout(PrintLevel::INFO, LOG_SOURCE, "Not readout for detector %s", detectorName.c_str()); + continue; + } + } else { + continue; + } + counter++; + + std::string path = ddsurf->detElement().path(); + auto layerNumber = cellIDcoder->get(ddsurf->id(), "layer"); + printout(PrintLevel::INFO, LOG_SOURCE, "Found Surface at %s in layer %d at radius %3.2f mm", path.c_str(), + layerNumber, ddsurf->origin().rho()); + + //fixme: replace this with the ACTS type to be used as an extension dd4hep::rec::DoubleParameters* para = nullptr; try { // use existing map, or create a new one para = ddsurf->detElement().extension(); @@ -42,14 +70,12 @@ namespace { para->doubleParameters["SortingPolicy"] = 321; ddsurf->detElement().addExtension(para); } - printout(PrintLevel::INFO, LOG_SOURCE, - "Added extension to %s" - " path %s, type %s, value %3.5f", - volumeName.c_str(), ddsurf->detElement().path().c_str(), ddsurf->detElement().type().c_str(), - para->doubleParameters["SortingPolicy"]); + if (counter > 1000) { + break; + } } // for all surfaces - return 0; // this return value isn't really returned from the plugin service + return 42; } } // namespace From ba89a93ba7cbc71a1ddd055ff267b31aa2ad9898 Mon Sep 17 00:00:00 2001 From: Valentin Volkl Date: Wed, 1 Dec 2021 14:38:48 +0100 Subject: [PATCH 5/5] fix gaudi env var setup for ctest --- k4ActsTracking/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k4ActsTracking/CMakeLists.txt b/k4ActsTracking/CMakeLists.txt index b91f1fa..20b7edd 100644 --- a/k4ActsTracking/CMakeLists.txt +++ b/k4ActsTracking/CMakeLists.txt @@ -19,7 +19,7 @@ target_compile_options(k4ActsDD4hepPlugin PUBLIC ${compile_flags}) function(set_test_env _testname) set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$:$:$:$:$:$:$ENV{LD_LIBRARY_PATH} - PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/genConf:$/../python:$ENV{PYTHONPATH} + PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/genConfDir:$/../python:$ENV{PYTHONPATH} PATH=$/../bin:$ENV{PATH} K4ACTSTRACKING=${CMAKE_CURRENT_LIST_DIR}/ )