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;\ 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..20b7edd 100644 --- a/k4ActsTracking/CMakeLists.txt +++ b/k4ActsTracking/CMakeLists.txt @@ -1,16 +1,31 @@ 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) + + + +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::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}) -set(GAUDI_GENCONF_DIR "genConfDir") 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}/genConfDir:$/../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..27ef2cc --- /dev/null +++ b/k4ActsTracking/src/dd4hepplugin/actsdd4hepplugin.cpp @@ -0,0 +1,83 @@ +#include +#include +#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, char**) { + const std::string LOG_SOURCE("AddActsExtensions"); + printout(PrintLevel::INFO, LOG_SOURCE, "Running plugin"); + + //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; + + 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(); + para->doubleParameters["SortingPolicy"] = 123; + } catch (...) { + para = new dd4hep::rec::DoubleParameters; + para->doubleParameters["SortingPolicy"] = 321; + ddsurf->detElement().addExtension(para); + } + if (counter > 1000) { + break; + } + } // for all surfaces + + return 42; + } + +} // namespace + +DECLARE_APPLY(k4acts_addActsExtensions, ::addActsExtensions)