Skip to content

Commit

Permalink
Always convert EventHeader to lcio (#162)
Browse files Browse the repository at this point in the history
* Always convert EventHeader to lcio

* Replace "EventHeader" by edm4hep::EventHeaderName

---------

Co-authored-by: Thomas Madlener <[email protected]>
  • Loading branch information
Zehvogel and tmadlener authored Dec 5, 2023
1 parent 346132a commit cacee63
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 5 deletions.
1 change: 0 additions & 1 deletion k4MarlinWrapper/examples/clicRec_e4h_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@

inp = PodioInput('InputReader')
inp.collections = [
'EventHeader',
'MCParticles',
'VertexBarrelCollection',
'VertexEndcapCollection',
Expand Down
1 change: 0 additions & 1 deletion k4MarlinWrapper/examples/event_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

inp = PodioInput('InputReader')
inp.collections = [
'EventHeader',
'MCParticles',
'VertexBarrelCollection',
'VertexEndcapCollection',
Expand Down
2 changes: 2 additions & 0 deletions k4MarlinWrapper/src/components/EDM4hep2Lcio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ StatusCode EDM4hep2LcioTool::convertCollections(lcio::LCEventImpl* lcio_event) {
const auto collections = m_podioDataSvc->getEventFrame().getAvailableCollections();
// Start off with the pre-defined collection name mappings
auto collsToConvert{m_collNames.value()};
// We *always* want to convert the EventHeader
collsToConvert.emplace(edm4hep::EventHeaderName, "");
if (m_convertAll) {
info() << "Converting all collections from EDM4hep to LCIO" << endmsg;
// And simply add the rest, exploiting the fact that emplace will not
Expand Down
4 changes: 2 additions & 2 deletions k4MarlinWrapper/src/components/Lcio2EDM4hep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ namespace {

StatusCode Lcio2EDM4hepTool::convertCollections(lcio::LCEventImpl* the_event) {
// Convert Event Header outside the collections loop
if (!collectionExist("EventHeader")) {
registerCollection("EventHeader", LCIO2EDM4hepConv::createEventHeader(the_event));
if (!collectionExist(edm4hep::EventHeaderName)) {
registerCollection(edm4hep::EventHeaderName, LCIO2EDM4hepConv::createEventHeader(the_event));
}

// Start off with the pre-defined collection name mappings
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ if (BASH_PROGRAM)
# multiple processors
add_test( global_converter_maps ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/global_converter_maps.sh )

add_test( event_header_conversion ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/event_header.sh )

set_tests_properties (
simple_processors
simple_processors2
Expand All @@ -100,6 +102,7 @@ if (BASH_PROGRAM)
clicRec_edm4hep_input
clic_geo_test
global_converter_maps
event_header_conversion
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;MARLIN_DLL=$ENV{MARLIN_DLL}:${CMAKE_CURRENT_BINARY_DIR}/libMarlinTestProcessors.so"
)
Expand Down
50 changes: 50 additions & 0 deletions test/gaudi_opts/createEventHeader.py
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.
#
from Gaudi.Configuration import WARNING

from Configurables import (
EventHeaderCreator,
k4DataSvc,
MarlinProcessorWrapper,
ApplicationMgr,
EDM4hep2LcioTool,
)

eventHeaderCreator = EventHeaderCreator("eventHeaderCreator", eventNumberOffset=42)

podioevent = k4DataSvc("EventDataSvc")

EDM4hep2Lcio = EDM4hep2LcioTool("EDM4hep2Lcio")
EDM4hep2Lcio.convertAll = False

out = MarlinProcessorWrapper("out")
out.ProcessorType = "LCIOOutputProcessor"
out.Parameters = {"LCIOOutputFile": ["test.slcio"], "LCIOWriteMode": ["WRITE_NEW"]}
out.EDM4hep2LcioTool = EDM4hep2Lcio

ApplicationMgr(
TopAlg=[
eventHeaderCreator,
out,
],
EvtSel="NONE",
EvtMax=2,
ExtSvc=[podioevent],
OutputLevel=WARNING,
)
1 change: 0 additions & 1 deletion test/gaudi_opts/fccRec_e4h_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

inp = PodioInput('InputReader')
inp.collections = [
'EventHeader',
'MCParticles',
'VertexBarrelCollection',
'VertexEndcapCollection',
Expand Down
24 changes: 24 additions & 0 deletions test/scripts/event_header.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env sh
##
## 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.
##

set -eu

k4run $TEST_DIR/gaudi_opts/createEventHeader.py
anajob test.slcio | grep "EVENT: 42"

0 comments on commit cacee63

Please sign in to comment.