-
Notifications
You must be signed in to change notification settings - Fork 27
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
Make "always read EventHeader" collection more robust #161
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3330439
Implement minimal consumer to exhibit failure
tmadlener ef50161
Check event header produced by EventHeaderFiller
tmadlener 5f78229
Check and read the EventHeader every event
tmadlener 8a1aa92
Make sure to only read and register collections once
tmadlener c584240
Remove unnecessary include
tmadlener 0e55c1b
Remove method that is only used once
tmadlener File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,7 @@ add_test_with_env(TestDataHandleUniquePtr options/TestDataHandleUniquePtr.py) | |
add_test_with_env(TestUniqueIDGenSvc options/TestUniqueIDGenSvc.py) | ||
add_test_with_env(CreateLegacyExampleEventData options/createLegacyExampleEventData.py) | ||
add_test_with_env(TestEventHeaderFiller options/createEventHeader.py) | ||
add_test_with_env(EventHeaderCheck options/runEventHeaderCheck.py PROPERTIES DEPENDS TestEventHeaderFiller) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look at how easy it is to add one test now... |
||
add_test(NAME TestExec WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} COMMAND python options/TestExec.py) | ||
set_test_env(TestExec) | ||
|
||
|
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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about doing it this way initially, what happens if the EventHeader collection is also in the list of collections to read? Will it be read twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would query the underlying Frame again for a second time. However, the second time around that effectively is a map lookup and return. Technically,
hasCollection
does all the "heavy lifting" of prompting the Frame to actually read the data and populate it's internal map. Most importantly you will always get the same collection.I quickly checked what happens if I explicitly make the test read the EventHeader collection and nothing seems to have broken, but it looks like we would be putting two DataHandles pointing to the same collection into the EDS at the moment. I have to check why that seems to work without breaking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We indeed do get two
DataHandles
(and corresponding objects in the EDS) ifEventHeader
is explicitly passed in. However, since the collection is owned by the Frame and the DataSvc defers the cleanup to that, there is at least no double free.I will add a simple filter to clean out duplicate collection names as well as
"EventHeader"
. Additionally, I will adapt thePodioDataSvc::readCollection
to check for existence in the EDS before populating it twice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't do the filtering in the end, because it is effectively unnecessary with the guard against duplicate entries in the EDS.