forked from key4hep/k4FWCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make "always read EventHeader" collection more robust (key4hep#161)
* Implement minimal consumer to exhibit failure * Check and read the EventHeader every event * Make sure to only read and register collections once
- Loading branch information
Showing
5 changed files
with
123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/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 = "eventHeader.root" | ||
|
||
inp = PodioInput() | ||
inp.collections = [] | ||
|
||
consumer = ExampleEventHeaderConsumer( | ||
"EventHeaderCheck", runNumber=42, eventNumberOffset=42 | ||
) | ||
|
||
ApplicationMgr( | ||
TopAlg=[inp, consumer], | ||
EvtSel="NONE", | ||
EvtMax=-1, | ||
ExtSvc=[podioevent], | ||
OutputLevel=INFO, | ||
) |
68 changes: 68 additions & 0 deletions
68
test/k4FWCoreTest/src/components/ExampleEventHeaderConsumer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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 "edm4hep/Constants.h" | ||
#include "edm4hep/EventHeaderCollection.h" | ||
|
||
#include "k4FWCore/BaseClass.h" | ||
|
||
#include <Gaudi/Property.h> | ||
#include <GaudiAlg/Consumer.h> | ||
#include <GaudiKernel/ISvcLocator.h> | ||
|
||
#include <fmt/core.h> | ||
#include <fmt/format.h> | ||
|
||
#include <atomic> | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
struct ExampleEventHeaderConsumer final | ||
: Gaudi::Functional::Consumer<void(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"); | ||
} | ||
const auto evtHeader = evtHeaderColl[0]; | ||
if (!evtHeader.isAvailable()) { | ||
throw std::runtime_error("Cannot get a valid EventHeader"); | ||
} | ||
|
||
if (evtHeader.getRunNumber() != m_runNumber) { | ||
throw std::runtime_error(fmt::format("Run number is not set correctly (expected {}, actual {})", | ||
m_runNumber.value(), evtHeader.getRunNumber())); | ||
} | ||
|
||
const auto expectedEvent = m_evtCounter++ + m_eventNumberOffset; | ||
if (evtHeader.getEventNumber() != expectedEvent) { | ||
throw std::runtime_error(fmt::format("Event number is not set correctly (expected {}, actual {})", expectedEvent, | ||
evtHeader.getEventNumber())); | ||
} | ||
} | ||
|
||
Gaudi::Property<int> m_runNumber{this, "runNumber", 0, "The expected run number"}; | ||
Gaudi::Property<int> m_eventNumberOffset{this, "eventNumberOffset", 0, | ||
"The event number offset where events will start counting from"}; | ||
mutable std::atomic<unsigned> m_evtCounter{0}; | ||
}; | ||
|
||
DECLARE_COMPONENT(ExampleEventHeaderConsumer) |