-
Notifications
You must be signed in to change notification settings - Fork 11
Add example for creating DD4hepPlugin #3
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
Draft
andresailer
wants to merge
5
commits into
main
Choose a base branch
from
dd4hepPlugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ee1bec5
Implement Dummy k4ActsAlgorithm that instantiates a DD4hepPlugin loop…
andresailer ffb6e12
CI: use docker container from github registry
andresailer 484010e
CMake: add compiler warnings
andresailer fbc1a2a
k4ActsPlugin: add some show casing of using cellIDcoder to identify l…
andresailer ba89a93
fix gaudi env var setup for ctest
vvolkl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}:$<TARGET_FILE_DIR:k4ActsTrackingPlugins>:$<TARGET_FILE_DIR:ROOT::Core>:$<TARGET_FILE_DIR:k4FWCore::k4FWCore>:$<TARGET_FILE_DIR:EDM4HEP::edm4hep>:$<TARGET_FILE_DIR:podio::podio>:$ENV{LD_LIBRARY_PATH} | ||
| PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/${GAUDI_GENCONF_DIR}:$<TARGET_FILE_DIR:k4FWCore::k4FWCore>/../python:$ENV{PYTHONPATH} | ||
| LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}:$<TARGET_FILE_DIR:k4ActsTrackingPlugins>:$<TARGET_FILE_DIR:k4ActsDD4hepPlugin>:$<TARGET_FILE_DIR:ROOT::Core>:$<TARGET_FILE_DIR:k4FWCore::k4FWCore>:$<TARGET_FILE_DIR:EDM4HEP::edm4hep>:$<TARGET_FILE_DIR:podio::podio>:$ENV{LD_LIBRARY_PATH} | ||
| PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/genConfDir:$<TARGET_FILE_DIR:k4FWCore::k4FWCore>/../python:$ENV{PYTHONPATH} | ||
| PATH=$<TARGET_FILE_DIR:k4FWCore::k4FWCore>/../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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include "ActsAlg.h" | ||
|
|
||
| #include <DD4hep/DetFactoryHelper.h> | ||
| #include <DD4hep/Factories.h> | ||
|
|
||
| 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<long>(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; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #include <DD4hep/DetElement.h> | ||
| #include <DD4hep/Detector.h> | ||
| #include <DD4hep/Factories.h> | ||
| #include <DD4hep/Printout.h> | ||
|
|
||
| #include <DD4hep/IDDescriptor.h> | ||
|
|
||
| #include <DDRec/DetectorData.h> | ||
| #include <DDRec/SurfaceHelper.h> | ||
| #include <DDRec/SurfaceManager.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| 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::SurfaceManager>(); | ||
|
|
||
| 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<dd4hep::rec::DoubleParameters>(); | ||
| para->doubleParameters["SortingPolicy"] = 123; | ||
| } catch (...) { | ||
| para = new dd4hep::rec::DoubleParameters; | ||
| para->doubleParameters["SortingPolicy"] = 321; | ||
| ddsurf->detElement().addExtension<dd4hep::rec::DoubleParameters>(para); | ||
| } | ||
| if (counter > 1000) { | ||
| break; | ||
| } | ||
| } // for all surfaces | ||
|
|
||
| return 42; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| DECLARE_APPLY(k4acts_addActsExtensions, ::addActsExtensions) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.