From abe573a9002e1c7245cd4cb4b6a96e5a0b6e85cf Mon Sep 17 00:00:00 2001 From: tmadlener Date: Thu, 16 Nov 2023 20:25:55 +0100 Subject: [PATCH] Implement minimal consumer to exhibit failure --- test/k4FWCoreTest/CMakeLists.txt | 1 + .../options/runEventHeaderCheck.py | 41 +++++++++++++++++ .../components/ExampleEventHeaderConsumer.cpp | 45 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 test/k4FWCoreTest/options/runEventHeaderCheck.py create mode 100644 test/k4FWCoreTest/src/components/ExampleEventHeaderConsumer.cpp diff --git a/test/k4FWCoreTest/CMakeLists.txt b/test/k4FWCoreTest/CMakeLists.txt index 49ad4607..bf806747 100644 --- a/test/k4FWCoreTest/CMakeLists.txt +++ b/test/k4FWCoreTest/CMakeLists.txt @@ -112,3 +112,4 @@ add_test_with_env(ExampleFunctionalConsumerMultiple options/runExampleFunctional add_test_with_env(ExampleFunctionalTransformerMultiple options/runExampleFunctionalTransformerMultiple.py PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) add_test_with_env(FunctionalChain options/runFunctionalChain.py) add_test_with_env(FunctionalMix options/runFunctionalMix.py PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) +add_test_with_env(EventHeaderCheck options/runEventHeaderCheck.py PROPERTIES DEPENDS ExampleFunctionalProducerMultiple) diff --git a/test/k4FWCoreTest/options/runEventHeaderCheck.py b/test/k4FWCoreTest/options/runEventHeaderCheck.py new file mode 100644 index 00000000..f4e5fd44 --- /dev/null +++ b/test/k4FWCoreTest/options/runEventHeaderCheck.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2014-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 INFO +from Configurables import k4DataSvc +from Configurables import PodioInput +from Configurables import ExampleEventHeaderConsumer +from Configurables import ApplicationMgr + +podioevent = k4DataSvc("EventDataSvc") +podioevent.input = "output_k4test_exampledata_producer_multiple.root" + +inp = PodioInput() +inp.collections = [] + +consumer = ExampleEventHeaderConsumer() + +ApplicationMgr( + TopAlg=[inp, consumer], + EvtSel="NONE", + EvtMax=-1, + ExtSvc=[podioevent], + OutputLevel=INFO, +) diff --git a/test/k4FWCoreTest/src/components/ExampleEventHeaderConsumer.cpp b/test/k4FWCoreTest/src/components/ExampleEventHeaderConsumer.cpp new file mode 100644 index 00000000..dc9326e4 --- /dev/null +++ b/test/k4FWCoreTest/src/components/ExampleEventHeaderConsumer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2014-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 +#include "GaudiAlg/Consumer.h" + +#include "edm4hep/Constants.h" +#include "edm4hep/EventHeaderCollection.h" + +#include "k4FWCore/BaseClass.h" + +#include +#include + +struct ExampleEventHeaderConsumer final + : Gaudi::Functional::Consumer), BaseClass_t> { + ExampleEventHeaderConsumer(const std::string& name, ISvcLocator* svcLoc) + : Consumer(name, svcLoc, {KeyValue("EventHeaderName", edm4hep::EventHeaderName)}) {} + + void operator()(const edm4hep::EventHeaderCollection& evtHeaderColl) const { + if (evtHeaderColl.empty()) { + throw std::runtime_error("EventHeader collection is empty"); + } + if (!evtHeaderColl[0].isAvailable()) { + throw std::runtime_error("Cannot get a valid EventHeader"); + } + } +}; + +DECLARE_COMPONENT(ExampleEventHeaderConsumer)