Skip to content

Commit

Permalink
Revert "add reading multiple files and glob patterns with get_reader"
Browse files Browse the repository at this point in the history
This reverts commit 60c9b02.
  • Loading branch information
m-fila committed Feb 5, 2025
1 parent 7a240c7 commit add1917
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 38 deletions.
32 changes: 10 additions & 22 deletions python/podio/reading.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3
"""Module for general reading functionality."""

from glob import glob

from ROOT import TFile

from podio import root_io
Expand Down Expand Up @@ -52,42 +50,32 @@ def _determine_root_format(filename):
return RootFileFormat.RNTUPLE


def get_reader(filenames):
"""Get an appropriate reader for the passed files.
The reader is inferred from the first file if multiple are given.
All files are assumed to be of the same I/O format.
def get_reader(filename):
"""Get an appropriate reader for the passed file.
Args:
filenames (str or list[str]): The input file(s)
filename (str): The input file
Returns:
root_io.[Legacy]Reader, sio_io.[Legacy]Reader: an initialized reader that
is able to process the input files.
is able to process the input file.
Raises:
ValueError: If the files cannot be recognized, or if podio has not been
ValueError: If the file cannot be recognized, or if podio has not been
built with the necessary backend I/O support
"""
if isinstance(filenames, str):
expanded_filenames = glob(filenames)
if not expanded_filenames:
filenames = [filenames]
else:
filenames = expanded_filenames
filename = filenames[0]

if filename.endswith(".sio"):
if _is_frame_sio_file(filename):
return sio_io.Reader(filenames)
return sio_io.LegacyReader(filenames)
return sio_io.Reader(filename)
return sio_io.LegacyReader(filename)

if filename.endswith(".root"):
root_flavor = _determine_root_format(filename)
if root_flavor == RootFileFormat.TTREE:
return root_io.Reader(filenames)
return root_io.Reader(filename)
if root_flavor == RootFileFormat.RNTUPLE:
return root_io.RNTupleReader(filenames)
return root_io.RNTupleReader(filename)
if root_flavor == RootFileFormat.LEGACY:
return root_io.LegacyReader(filenames)
return root_io.LegacyReader(filename)

raise ValueError("file must end on .root or .sio")
1 change: 0 additions & 1 deletion tests/CTestCustom.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ if ((NOT "@FORCE_RUN_ALL_TESTS@" STREQUAL "ON") AND (NOT "@USE_SANITIZER@" STREQ
write_frame_root
read_frame_root
read_glob
read_python_glob

write_interface_root
read_interface_root
Expand Down
4 changes: 0 additions & 4 deletions tests/root_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ set_tests_properties(
DEPENDS write_frame_root
)

add_test(NAME read_python_glob COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/root_io/read_glob.py)
PODIO_SET_TEST_ENV(read_python_glob)
set_property(TEST read_python_glob PROPERTY DEPENDS write_frame_root)

if(ENABLE_RNTUPLE)
set_property(TEST read_rntuple PROPERTY DEPENDS write_rntuple)
set_property(TEST read_interface_rntuple PROPERTY DEPENDS write_interface_rntuple)
Expand Down
11 changes: 0 additions & 11 deletions tests/root_io/read_glob.py

This file was deleted.

0 comments on commit add1917

Please sign in to comment.