Skip to content
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

TrackingCellIDEncodingSvc: add service to set the Cell ID encoding st… #134

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions doc/starterkit/k4MarlinWrapperCLIC/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,27 @@ result=$?
[ $result = "0" ] || [ $result = "4" ] && true
```

### DD4hep Geometry Information

The ``MarlinDD4hep::InitializeDD4hep`` processor can be replaced by the ``k4SimGeant4::GeoSvc`` and the
``TrackingCellIDEncodingSvc`` the latter of which is part of the k4MarlinWrapper repository.

For example:

```python
import os
from Gaudi.Configuration import INFO
from Configurables import GeoSvc, TrackingCellIDEncodingSvc
andresailer marked this conversation as resolved.
Show resolved Hide resolved
andresailer marked this conversation as resolved.
Show resolved Hide resolved
svcList = []
geoservice = GeoSvc("GeoSvc")
geoservice.detectors = [os.environ["K4GEO"]+"/CLIC/compact/CLIC_o3_v15/CLIC_o3_v15.xml"]
geoservice.OutputLevel = INFO
geoservice.EnableGeant4Geo = False
svcList.append(geoservice)

cellIDSvc = TrackingCellIDEncodingSvc("CellIDSvc")
cellIDSvc.EncodingStringParameterName = "GlobalTrackerReadoutID"
cellIDSvc.GeoSvcName = geoservice.name()
cellIDSvc.OutputLevel = INFO
svcList.append(cellIDSvc)
```
2 changes: 2 additions & 0 deletions k4MarlinWrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ target_include_directories(k4MarlinWrapperPlugins PUBLIC
gaudi_add_module(MarlinWrapper
SOURCES
src/components/MarlinProcessorWrapper.cpp
src/components/TrackingCellIDEncodingSvc.cpp
LINK
Gaudi::GaudiAlgLib
k4FWCore::k4FWCore
k4FWCore::k4Interface
${Marlin_LIBRARIES}
EDM4HEP::edm4hep
)
Expand Down
50 changes: 50 additions & 0 deletions k4MarlinWrapper/k4MarlinWrapper/TrackingCellIDEncodingSvc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (c) 2019-2023 Key4hep-Project.
*
* This file is part of Key4hep.
* See https://key4hep.github.io/key4hep-doc/ for further info.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef CELLIDSVC_H
#define CELLIDSVC_H

#include <GaudiKernel/Service.h>

//LCIO Includes
#include <UTIL/LCTrackerConf.h>

#include <string>

class IGeoSvc;

class TrackingCellIDEncodingSvc : public extends<Service, IService> {
public:
TrackingCellIDEncodingSvc(const std::string& name, ISvcLocator* svc);

~TrackingCellIDEncodingSvc();
StatusCode initialize() final;
StatusCode finalize() final;

/// Property to configure which DD4hep constant to use for the encodingString
Gaudi::Property<std::string> m_encodingStringVariable{
this, "EncodingStringParameterName", "GlobalTrackerReadoutID",
"The name of the DD4hep constant that contains the Encoding string for tracking detectors"};

Gaudi::Property<std::string> m_geoSvcName{this, "GeoSvcName", "GeoSvc", "The name of the GeoSvc instance"};

private:
SmartIF<IGeoSvc> m_geoSvc;
};

#endif // CELLIDSVC_H
57 changes: 57 additions & 0 deletions k4MarlinWrapper/src/components/TrackingCellIDEncodingSvc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2019-2023 Key4hep-Project.
*
* This file is part of Key4hep.
* See https://key4hep.github.io/key4hep-doc/ for further info.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "k4MarlinWrapper/TrackingCellIDEncodingSvc.h"

// k4fwcore
#include <k4Interface/IGeoSvc.h>

#include <GaudiKernel/MsgStream.h>

DECLARE_COMPONENT(TrackingCellIDEncodingSvc);

TrackingCellIDEncodingSvc::TrackingCellIDEncodingSvc(const std::string& name, ISvcLocator* svc)
: base_class(name, svc) {}

TrackingCellIDEncodingSvc::~TrackingCellIDEncodingSvc() {}

StatusCode TrackingCellIDEncodingSvc::initialize() {
try {
info() << "Looking for GeoSvc with the name" << m_geoSvcName.value() << endmsg;

m_geoSvc = serviceLocator()->service(m_geoSvcName);

info() << "Taking the encoding string as specified in dd4hep constant: " << m_encodingStringVariable.value()
<< endmsg;

auto encodingString = m_geoSvc->constantAsString(m_encodingStringVariable.value());
andresailer marked this conversation as resolved.
Show resolved Hide resolved

info() << "LCTrackerCellID::_encoding will be set to " << encodingString << endmsg;

UTIL::LCTrackerCellID::instance().set_encoding_string(encodingString);

return StatusCode::SUCCESS;

} catch (std::exception& e) {
error() << "Failed to set the encoding string!\n";
error() << e.what() << endmsg;
return StatusCode::FAILURE;
}
}

StatusCode TrackingCellIDEncodingSvc::finalize() { return StatusCode::SUCCESS; }
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ if (BASH_PROGRAM)
# Run clicReconstruction sequence with LCIO input and output, no converters, with inter-event parallelism
add_test( clicRec_lcio_mt ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicRec_lcio_mt.sh )

# Test the GeoSvc and TrackingCellIDEncodingSvc
add_test( clic_geo_test ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/clicGeoTest.sh )

set_tests_properties (
simple_processors
simple_processors2
Expand All @@ -97,6 +100,7 @@ if (BASH_PROGRAM)
same_num_io
clicRec_lcio_mt
clicRec_edm4hep_input
clic_geo_test
PROPERTIES
ENVIRONMENT "TEST_DIR=${CMAKE_CURRENT_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:$ENV{LD_LIBRARY_PATH};PYTHONPATH=${CMAKE_INSTALL_PREFIX}/python:$ENV{PYTHONPATH};EXAMPLE_DIR=${PROJECT_SOURCE_DIR}/k4MarlinWrapper/examples"
)
Expand Down
45 changes: 45 additions & 0 deletions test/gaudi_opts/geoTest_cld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Copyright (c) 2019-2023 Key4hep-Project.
#
# This file is part of Key4hep.
# See https://key4hep.github.io/key4hep-doc/ for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os

from Gaudi.Configuration import *
andresailer marked this conversation as resolved.
Show resolved Hide resolved

from Configurables import TrackingCellIDEncodingSvc, GeoSvc
algList = []
svcList = []

geoservice = GeoSvc("GeoSvc")
andresailer marked this conversation as resolved.
Show resolved Hide resolved
geoservice.detectors = [os.environ["K4GEO"]+"/CLIC/compact/CLIC_o3_v15/CLIC_o3_v15.xml"]
geoservice.OutputLevel = INFO
geoservice.EnableGeant4Geo = False
svcList.append(geoservice)

cellIDSvc = TrackingCellIDEncodingSvc("CellIDSvc")
cellIDSvc.EncodingStringParameterName = "GlobalTrackerReadoutID"
cellIDSvc.GeoSvcName = geoservice.name()
cellIDSvc.OutputLevel = DEBUG
svcList.append(cellIDSvc)

from Configurables import ApplicationMgr
ApplicationMgr( TopAlg = algList,
EvtSel = 'NONE',
EvtMax = 3,
ExtSvc = svcList,
hegner marked this conversation as resolved.
Show resolved Hide resolved
OutputLevel=WARNING
)
24 changes: 24 additions & 0 deletions test/scripts/clicGeoTest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
##
## Copyright (c) 2019-2023 Key4hep-Project.
##
## This file is part of Key4hep.
## See https://key4hep.github.io/key4hep-doc/ for further info.
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##

# exit if command or variable fails
set -eu

k4run $TEST_DIR/gaudi_opts/geoTest_cld.py