Skip to content

Commit

Permalink
Add the possibility of starting from the Nth event instead of the
Browse files Browse the repository at this point in the history
first one.
  • Loading branch information
jmcarcell committed Sep 6, 2024
1 parent 941da76 commit 23ca82f
Show file tree
Hide file tree
Showing 5 changed files with 54 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) {
error() << "First event entry is larger than the number of entries in the file" << 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 @@ -140,9 +140,10 @@ add_test_with_env(FunctionalMetadataOldAlgorithm options/ExampleFunctionalMetada

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;FunctionalMetadataOldAlgorithm")
set_tests_properties(FunctionalCheckFiles PROPERTIES DEPENDS "FunctionalFile;FunctionalMTFile;FunctionalMultipleFile;FunctionalOutputCommands;FunctionalProducerAbsolutePath;FunctionalTransformerRuntimeEmpty;FunctionalMix;FunctionalMixIOSvc;FunctionalTransformerHist;FunctionalCollectionMerger;FunctionalFilterFile;FunctionalMetadata;FunctionalMetadataOldAlgorithm;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
4 changes: 4 additions & 0 deletions test/k4FWCoreTest/options/CheckOutputFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,7 @@ def check_events(filename, number):
raise RuntimeError(
f"Metadata parameter {key} does not match the expected value, got {metadata.get_parameter(key)} but expected {value}"
)
check_events(
"functional_nth_event.root",
5,
)
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 = 5

consumer = ExampleFunctionalTransformer(Offset=0)

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

0 comments on commit 23ca82f

Please sign in to comment.