Skip to content

Commit

Permalink
Add a new test to read a TTree file and output an RNTuple file
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell committed Sep 6, 2024
1 parent f4f3613 commit d7b73fb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
4 changes: 2 additions & 2 deletions test/k4FWCoreTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ add_test_with_env(FunctionalCollectionMerger options/ExampleFunctionalCollection
add_test_with_env(FunctionalFilterFile options/ExampleFunctionalFilterFile.py)
add_test_with_env(FunctionalMetadata options/ExampleFunctionalMetadata.py)
add_test_with_env(FunctionalMetadataOldAlgorithm options/ExampleFunctionalMetadataOldAlgorithm.py)

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(FunctionalProducerRNTuple options/ExampleFunctionalProducerRNTuple.py)
add_test_with_env(FunctionalTTreeToRNTuple options/ExampleFunctionalTTreeToRNTuple.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;FunctionalProducerRNTuple;FunctionalReadNthEvent")
set_tests_properties(FunctionalCheckFiles PROPERTIES DEPENDS "FunctionalFile;FunctionalMTFile;FunctionalMultipleFile;FunctionalOutputCommands;FunctionalProducerAbsolutePath;FunctionalTransformerRuntimeEmpty;FunctionalMix;FunctionalMixIOSvc;FunctionalTransformerHist;FunctionalCollectionMerger;FunctionalFilterFile;FunctionalMetadata;FunctionalMetadataOldAlgorithm;FunctionalProducerRNTuple;FunctionalProducerTTreeToRNTuple")

# 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
9 changes: 5 additions & 4 deletions test/k4FWCoreTest/options/CheckOutputFiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ 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}"
)
podio_reader = podio.root_io.RNTupleReader("functional_producer_rntuple.root")
frames = podio_reader.get("events")
if len(frames) != 10:
raise RuntimeError(f"Expected 10 events but got {len(frames)}")
for rntuple in ["functional_producer_rntuple.root", "functional_producer_rntuple_converted.root"]:
reader = podio.root_io.RNTupleReader(f"{rntuple}")
frames = podio_reader.get("events")
if len(frames) != 10:
raise RuntimeError(f"Expected 10 events but got {len(frames)}")

reader = podio.root_io.Reader("functional_metadata_old_algorithm.root")
metadata = reader.get("metadata")[0]
Expand Down
40 changes: 40 additions & 0 deletions test/k4FWCoreTest/options/ExampleFunctionalTTreeToRNTuple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# 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 algorithm to modify a TTree into an RNTuple
# Don't use! There is already a converter in podio called
# podio-ttree-to-rntuple
# Running with k4run will add some extra configuration metadata to the file

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

iosvc = IOSvc("IOSvc")
iosvc.Input = "functional_producer.root"
iosvc.Output = "functional_producer_rntuple_converted.root"
iosvc.OutputType = "RNTuple"

ApplicationMgr(
TopAlg=[],
EvtSel="NONE",
EvtMax=10,
ExtSvc=[EventDataSvc("EventDataSvc")],
OutputLevel=INFO,
)

0 comments on commit d7b73fb

Please sign in to comment.