Skip to content

Commit

Permalink
Merge branch 'main' into metadatasvc
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell authored Sep 16, 2024
2 parents e53afba + 6a1b3b1 commit d6061c4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
6 changes: 6 additions & 0 deletions k4FWCore/components/IOSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ StatusCode IOSvc::initialize() {
m_entries = m_reader->getEntries(podio::Category::Event);
}

if ((m_entries && m_firstEventEntry >= m_entries) || m_firstEventEntry < 0) {
error() << "First event entry is larger than the number of entries in the file or negative" << endmsg;
return StatusCode::FAILURE;
}

if (!m_writingFileNameDeprecated.empty()) {
warning() << ".output is deprecated, use .Output instead in the steering file" << endmsg;
m_writingFileName = m_writingFileNameDeprecated;
}
m_nextEntry = m_firstEventEntry;

m_switch = KeepDropSwitch(m_outputCommands);

Expand Down
1 change: 1 addition & 0 deletions k4FWCore/components/IOSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class IOSvc : public extends<Service, IIOSvc, IIncidentListener> {
Gaudi::Property<bool> m_importedFromk4FWCore{
this, "ImportedFromk4FWCore", false,
"This is set to true when IOSvc is imported from k4FWCore instead of Configurables in python"};
Gaudi::Property<int> m_firstEventEntry{this, "FirstEventEntry", 0, "First event entry to read"};

std::mutex m_changeBufferLock;

Expand Down
3 changes: 2 additions & 1 deletion test/k4FWCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ add_test_with_env(FunctionalMetadataReadOldAlgorithm options/ExampleFunctionalMe

add_test_with_env(FunctionalWrongImport options/ExampleFunctionalWrongImport.py)
set_tests_properties(FunctionalWrongImport PROPERTIES PASS_REGULAR_EXPRESSION "ImportError: Importing ApplicationMgr or IOSvc from Configurables is not allowed.")
add_test_with_env(FunctionalReadNthEvent options/ExampleFunctionalReadNthEvent.py)

add_test(NAME FunctionalCheckFiles COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/options/CheckOutputFiles.py)

set_tests_properties(FunctionalCheckFiles PROPERTIES DEPENDS "FunctionalFile;FunctionalMTFile;FunctionalMultipleFile;FunctionalOutputCommands;FunctionalProducerAbsolutePath;FunctionalTransformerRuntimeEmpty;FunctionalMix;FunctionalMixIOSvc;FunctionalTransformerHist;FunctionalCollectionMerger;FunctionalFilterFile;FunctionalMetadata;FunctionalMetadataRead;FunctionalMetadataOldAlgorithm;FunctionalMetadataReadOldAlgorithm;createEventHeaderConcurrent")
set_tests_properties(FunctionalCheckFiles PROPERTIES DEPENDS "FunctionalFile;FunctionalMTFile;FunctionalMultipleFile;FunctionalOutputCommands;FunctionalProducerAbsolutePath;FunctionalTransformerRuntimeEmpty;FunctionalMix;FunctionalMixIOSvc;FunctionalTransformerHist;FunctionalCollectionMerger;FunctionalFilterFile;FunctionalMetadata;FunctionalMetadataRead;FunctionalMetadataOldAlgorithm;FunctionalMetadataReadOldAlgorithm;createEventHeaderConcurrent;FunctionalReadNthEvent")

# Do this after checking the files not to overwrite them
add_test_with_env(FunctionalFile_toolong options/ExampleFunctionalFile.py -n 999 PROPERTIES DEPENDS FunctionalCheckFiles PASS_REGULAR_EXPRESSION
Expand Down
5 changes: 5 additions & 0 deletions test/k4FWCoreTest/options/CheckOutputFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,8 @@ def check_metadata(filename, expected_metadata):
if event_number in seen_event_numbers:
raise RuntimeError(f"Event number {event_number} is duplicated")
seen_event_numbers.add(event_number)

check_events(
"functional_nth_event.root",
3,
)
41 changes: 41 additions & 0 deletions test/k4FWCoreTest/options/ExampleFunctionalReadNthEvent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# 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 for reading from a file starting from a certain event and
# tranforming so that later we can check the number of events in the output file

from Gaudi.Configuration import INFO
from Configurables import ExampleFunctionalTransformer
from Configurables import EventDataSvc
from k4FWCore import ApplicationMgr, IOSvc

svc = IOSvc("IOSvc")
svc.Input = "functional_producer.root"
svc.Output = "functional_nth_event.root"
svc.FirstEventEntry = 7

consumer = ExampleFunctionalTransformer(Offset=0)

mgr = ApplicationMgr(
TopAlg=[consumer],
EvtSel="NONE",
EvtMax=-1,
ExtSvc=[EventDataSvc("EventDataSvc")],
OutputLevel=INFO,
)

0 comments on commit d6061c4

Please sign in to comment.