Skip to content

Commit ee1bec5

Browse files
committed
Implement Dummy k4ActsAlgorithm that instantiates a DD4hepPlugin looping over surfaces
1 parent fac8c47 commit ee1bec5

File tree

8 files changed

+128
-25
lines changed

8 files changed

+128
-25
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ find_package(ROOT COMPONENTS RIO Tree)
66
find_package(EDM4HEP)
77
find_package(k4FWCore)
88
find_package(Acts)
9+
find_package(DD4hep)
910

1011
#---------------------------------------------------------------
1112
# Load macros and functions for Gaudi-based projects

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ This repository contains the necessary tools to use ACTS functionality in Key4he
1818

1919
* k4FWCore
2020

21-
## Installation
21+
## Compilation and testing
2222

2323

2424
```
25+
source /cvmfs/sw-nightlies.hsf.org/key4hep/setup.sh
2526
mkdir build install
2627
cd build;
27-
cmake .. -DCMAKE_INSTALL_PREFIX=../install
28-
make install
29-
30-
28+
cmake .. -DCMAKE_INSTALL_PREFIX=../install -G Ninja
29+
ninja
30+
ctest
3131
```
3232

k4ActsTracking/CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
file(GLOB _plugin_sources src/components/*.cpp)
22
gaudi_add_module(k4ActsTrackingPlugins
33
SOURCES ${_plugin_sources}
4-
LINK Gaudi::GaudiKernel Gaudi::GaudiAlgLib k4FWCore::k4FWCore EDM4HEP::edm4hep)
4+
LINK Gaudi::GaudiKernel Gaudi::GaudiAlgLib DD4hep::DDCore)
55

6-
set(GAUDI_GENCONF_DIR "genConfDir")
6+
7+
file(GLOB _dd4hep_plugin_sources src/dd4hepplugin/*.cpp)
8+
add_dd4hep_plugin(k4ActsDD4hepPlugin SHARED ${_dd4hep_plugin_sources})
9+
target_link_libraries(k4ActsDD4hepPlugin DD4hep::DDCore DD4hep::DDRec DD4hep::DDParsers)
710

811
function(set_test_env _testname)
912
set_property(TEST ${_testname} APPEND PROPERTY ENVIRONMENT
10-
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}
11-
PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/${GAUDI_GENCONF_DIR}:$<TARGET_FILE_DIR:k4FWCore::k4FWCore>/../python:$ENV{PYTHONPATH}
13+
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}
14+
PYTHONPATH=${CMAKE_BINARY_DIR}/${CMAKE_PROJECT_NAME}/genConf:$<TARGET_FILE_DIR:k4FWCore::k4FWCore>/../python:$ENV{PYTHONPATH}
1215
PATH=$<TARGET_FILE_DIR:k4FWCore::k4FWCore>/../bin:$ENV{PATH}
1316
K4ACTSTRACKING=${CMAKE_CURRENT_LIST_DIR}/
1417
)
1518
endfunction()
1619

20+
add_test(NAME ActsAlgTest
21+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
22+
COMMAND k4run k4ActsTracking/options/run_acts_plugin.py)
23+
set_test_env(ActsAlgTest)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import os
2+
from pprint import pprint
3+
from Gaudi.Configuration import *
4+
5+
from Configurables import ActsAlg, GeoSvc
6+
algList = []
7+
8+
geosvc = GeoSvc("GeoSvc")
9+
# using this instead of CLIC_o3_v14 because it is much faster to instantiate
10+
geosvc.detectors = [os.environ["LCGEO"]+"/CLIC/compact/CLIC_o2_v04/CLIC_o2_v04.xml"]
11+
12+
a = ActsAlg("MyActsAlg")
13+
algList.append(a)
14+
15+
from Configurables import ApplicationMgr
16+
ApplicationMgr( TopAlg = algList,
17+
EvtSel = 'NONE',
18+
EvtMax = 2,
19+
ExtSvc = [geosvc],
20+
OutputLevel=INFO
21+
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "ActsAlg.h"
2+
3+
#include <DD4hep/DetFactoryHelper.h>
4+
#include <DD4hep/Factories.h>
5+
6+
DECLARE_COMPONENT(ActsAlg)
7+
8+
ActsAlg::ActsAlg(const std::string& aName, ISvcLocator* aSvcLoc) : GaudiAlgorithm(aName, aSvcLoc) {}
9+
10+
ActsAlg::~ActsAlg() {}
11+
12+
StatusCode ActsAlg::initialize() {
13+
info() << "Initializing the ACTS algorithm" << endmsg;
14+
int argc = 0;
15+
char* argv = {};
16+
dd4hep::PluginDebug dbg;
17+
std::string name = "k4acts_addActsExtensions";
18+
long result = dd4hep::PluginService::Create<long>(name, &dd4hep::Detector::getInstance(), argc, &argv);
19+
if (0 == result) {
20+
error() << "Failed to locate plugin " << name << "\n" << dbg.missingFactory(name) << endmsg;
21+
return StatusCode::FAILURE;
22+
}
23+
24+
info() << "Successfully loaded the plugin!" << endmsg;
25+
return StatusCode::SUCCESS;
26+
}
27+
28+
StatusCode ActsAlg::execute() { return StatusCode::SUCCESS; }
29+
30+
StatusCode ActsAlg::finalize() { return StatusCode::SUCCESS; }

k4ActsTracking/src/components/EmptyAlg.h renamed to k4ActsTracking/src/components/ActsAlg.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#include "Gaudi/Property.h"
55
#include "GaudiAlg/GaudiAlgorithm.h"
66

7-
class EmptyAlg : public GaudiAlgorithm {
7+
class ActsAlg : public GaudiAlgorithm {
88
public:
9-
explicit EmptyAlg(const std::string&, ISvcLocator*);
10-
virtual ~EmptyAlg();
9+
explicit ActsAlg(const std::string&, ISvcLocator*);
10+
virtual ~ActsAlg();
1111
/** Initialize.
1212
* @return status code
1313
*/

k4ActsTracking/src/components/EmptyAlg.cpp

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include <DD4hep/DetElement.h>
2+
#include <DD4hep/Detector.h>
3+
#include <DD4hep/Factories.h>
4+
#include <DD4hep/Printout.h>
5+
6+
#include <DDRec/DetectorData.h>
7+
#include <DDRec/SurfaceHelper.h>
8+
9+
#include <string>
10+
11+
using dd4hep::DetElement;
12+
using dd4hep::PrintLevel;
13+
14+
namespace {
15+
16+
/** Plugin for adding the ACTS Extensions to surface, or DetElements, or something
17+
*
18+
*/
19+
20+
static long addActsExtensions(dd4hep::Detector& description, int argc, char** argv) {
21+
const std::string LOG_SOURCE("AddActsExtensions");
22+
printout(PrintLevel::INFO, LOG_SOURCE, "Running extension");
23+
24+
dd4hep::rec::SurfaceHelper ds(description.world());
25+
dd4hep::rec::SurfaceList const& detSL = ds.surfaceList();
26+
27+
for (dd4hep::rec::ISurface* surf : detSL) {
28+
dd4hep::Volume volume = ((dd4hep::rec::Surface*)surf)->volume();
29+
auto* ddsurf = ((dd4hep::rec::Surface*)surf);
30+
auto const volumeName = std::string(volume->GetName());
31+
if (not ddsurf->detElement().isValid())
32+
continue;
33+
std::string path = ddsurf->detElement().path();
34+
35+
//FIXME: replace this with the ACTS type to be used as an extension
36+
dd4hep::rec::DoubleParameters* para = nullptr;
37+
try { // use existing map, or create a new one
38+
para = ddsurf->detElement().extension<dd4hep::rec::DoubleParameters>();
39+
para->doubleParameters["SortingPolicy"] = 123;
40+
} catch (...) {
41+
para = new dd4hep::rec::DoubleParameters;
42+
para->doubleParameters["SortingPolicy"] = 321;
43+
ddsurf->detElement().addExtension<dd4hep::rec::DoubleParameters>(para);
44+
}
45+
printout(PrintLevel::INFO, LOG_SOURCE,
46+
"Added extension to %s"
47+
" path %s, type %s, value %3.5f",
48+
volumeName.c_str(), ddsurf->detElement().path().c_str(), ddsurf->detElement().type().c_str(),
49+
para->doubleParameters["SortingPolicy"]);
50+
} // for all surfaces
51+
52+
return 0; // this return value isn't really returned from the plugin service
53+
}
54+
55+
} // namespace
56+
57+
DECLARE_APPLY(k4acts_addActsExtensions, ::addActsExtensions)

0 commit comments

Comments
 (0)