-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for creating EventHeader with GaudiHive
- Loading branch information
Showing
4 changed files
with
178 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# | ||
# Copyright (c) 2014-2024 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. | ||
# | ||
|
||
# This is an example checking EventHeader created in GaudiHive | ||
# The checks include whether a correct range of EventNumber is created | ||
# and if there are no duplicates | ||
|
||
from Gaudi.Configuration import * | ||
|
||
from Configurables import ExampleEventHeaderCheck | ||
from Configurables import EventDataSvc | ||
from k4FWCore import ApplicationMgr, IOSvc | ||
|
||
|
||
eventHeaderCreator = ExampleEventHeaderCheck( | ||
"eventHeaderCreator", | ||
runNumber=42, | ||
expectedEventNumbers=list(range(42, 42 + 10)), | ||
OutputLevel=DEBUG, | ||
) | ||
|
||
svc = IOSvc("IOSvc") | ||
svc.input = "eventHeaderConcurrent.root" | ||
|
||
ApplicationMgr( | ||
TopAlg=[eventHeaderCreator], | ||
EvtSel="NONE", | ||
EvtMax=10, | ||
ExtSvc=[EventDataSvc("EventDataSvc")], | ||
MessageSvcType="InertMessageSvc", | ||
OutputLevel=INFO, | ||
) |
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,59 @@ | ||
# | ||
# Copyright (c) 2014-2024 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. | ||
# | ||
|
||
# This is an example creating EventHeader created in GaudiHive | ||
|
||
from Gaudi.Configuration import * | ||
|
||
from Configurables import EventHeaderCreator | ||
from Configurables import HiveSlimEventLoopMgr, HiveWhiteBoard, AvalancheSchedulerSvc | ||
from k4FWCore import ApplicationMgr, IOSvc | ||
|
||
evtslots = 6 | ||
threads = 6 | ||
|
||
whiteboard = HiveWhiteBoard( | ||
"EventDataSvc", | ||
EventSlots=evtslots, | ||
ForceLeaves=True, | ||
) | ||
|
||
slimeventloopmgr = HiveSlimEventLoopMgr( | ||
"HiveSlimEventLoopMgr", SchedulerName="AvalancheSchedulerSvc", OutputLevel=WARNING | ||
) | ||
|
||
scheduler = AvalancheSchedulerSvc(ThreadPoolSize=threads, ShowDataFlow=True, OutputLevel=WARNING) | ||
|
||
|
||
eventHeaderCreator = EventHeaderCreator( | ||
"eventHeaderCreator", runNumber=42, eventNumberOffset=42, OutputLevel=DEBUG | ||
) | ||
|
||
svc = IOSvc("IOSvc") | ||
svc.output = "eventHeaderConcurrent.root" | ||
|
||
ApplicationMgr( | ||
TopAlg=[eventHeaderCreator], | ||
EvtSel="NONE", | ||
EvtMax=10, | ||
ExtSvc=[whiteboard], | ||
EventLoop=slimeventloopmgr, | ||
MessageSvcType="InertMessageSvc", | ||
OutputLevel=INFO, | ||
) |
68 changes: 68 additions & 0 deletions
68
test/k4FWCoreTest/src/components/ExampleEventHeaderCheck.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-2024 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/Consumer.h" | ||
|
||
#include <Gaudi/Property.h> | ||
|
||
#include <fmt/core.h> | ||
|
||
#include <iterator> | ||
#include <mutex> | ||
#include <stdexcept> | ||
#include <string> | ||
|
||
struct ExampleEventHeaderCheck final : k4FWCore::Consumer<void(const edm4hep::EventHeaderCollection&)> { | ||
ExampleEventHeaderCheck(const std::string& name, ISvcLocator* svcLoc) | ||
: Consumer(name, svcLoc, {KeyValues("EventHeaderName", {edm4hep::labels::EventHeader})}) {} | ||
|
||
void operator()(const edm4hep::EventHeaderCollection& evtHeaderColl) const override { | ||
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())); | ||
} | ||
if (std::find(std::begin(m_expectedEventNumbers), std::end(m_expectedEventNumbers), evtHeader.getEventNumber()) == | ||
std::end(m_expectedEventNumbers)) { | ||
throw std::runtime_error(fmt::format("Event number {} is not in expected numbers", evtHeader.getEventNumber())); | ||
} | ||
auto lock = std::scoped_lock(m_mutex); | ||
if (m_seenEventNumbers.contains(evtHeader.getEventNumber())) { | ||
throw std::runtime_error(fmt::format("Event number {} is duplicated", evtHeader.getEventNumber())); | ||
} | ||
m_seenEventNumbers.insert(evtHeader.getEventNumber()); | ||
} | ||
|
||
Gaudi::Property<int> m_runNumber{this, "runNumber", 0, "The expected run number"}; | ||
Gaudi::Property<std::vector<int>> m_expectedEventNumbers{this, "expectedEventNumbers", 0, "Expected event numbers"}; | ||
mutable std::mutex m_mutex; | ||
mutable std::set<int> m_seenEventNumbers; | ||
}; | ||
|
||
DECLARE_COMPONENT(ExampleEventHeaderCheck) |