Skip to content

Commit

Permalink
Implement minimal consumer to exhibit failure
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Nov 16, 2023
1 parent 7c2dbe8 commit abe573a
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/k4FWCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
41 changes: 41 additions & 0 deletions test/k4FWCoreTest/options/runEventHeaderCheck.py
Original file line number Diff line number Diff line change
@@ -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,
)
45 changes: 45 additions & 0 deletions test/k4FWCoreTest/src/components/ExampleEventHeaderConsumer.cpp
Original file line number Diff line number Diff line change
@@ -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 <GaudiKernel/ISvcLocator.h>
#include "GaudiAlg/Consumer.h"

#include "edm4hep/Constants.h"
#include "edm4hep/EventHeaderCollection.h"

#include "k4FWCore/BaseClass.h"

#include <optional>
#include <stdexcept>

struct ExampleEventHeaderConsumer final
: Gaudi::Functional::Consumer<void(std::optional<const edm4hep::EventHeaderCollection&>), 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)

0 comments on commit abe573a

Please sign in to comment.