Skip to content

Commit

Permalink
Make python API closer in name to c++ API
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 5, 2024
1 parent 65617c0 commit b225083
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
26 changes: 13 additions & 13 deletions python/podio/base_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,28 @@ def get_datamodel_definition(self, edm_name):
return ""
return self._reader.getDatamodelDefinition(edm_name).data()

def current_file_version(self):
"""Get the podio (build) version that was used to write this file
def current_file_version(self, edm_name=None):
"""Get the (build) version that was used to write this file
Returns:
podio.version.Version: The build version of podio that was use to
write this file
"""
return self._reader.currentFileVersion()

def get_datamodel_version(self, edm_name):
"""Get the datamodel version
If called without argument or None, the podio build version is returned
otherwise the build version of the datamodel
Args:
edm_name (str): The package name of the datamodel
edm_name (str, optional): The package name of the datamodel
Returns:
podio.version.Version: The version of the datamodel if available
podio.version.Version: The build version of podio or the build
version of the datamodel (if available) that was used to write
this file
Raises:
KeyError: If the datamodel does not have a version stored
RuntimeError: If the reader is a legacy reader
RuntimeError: If the reader is a legacy reader and a datamodel
version is requested
"""
if edm_name is None:
return self._reader.currentFileVersion()

if self._is_legacy:
raise RuntimeError("Legacy readers do not store any version info")
maybe_version = self._reader.currentFileVersion(edm_name)
Expand Down
6 changes: 3 additions & 3 deletions python/podio/test_Reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ def test_available_datamodels(self):
for model in datamodels:
self.assertTrue(model in ("datamodel", "extension_model"))

self.assertEqual(self.reader.get_datamodel_version("datamodel"), build_version)
self.assertEqual(self.reader.current_file_version("datamodel"), build_version)

def test_invalid_datamodel_version(self):
"""Make sure that the necessary exceptions are raised"""
with self.assertRaises(KeyError):
self.reader.get_datamodel_version("extension_model")
self.reader.current_file_version("extension_model")

with self.assertRaises(KeyError):
self.reader.get_datamodel_version("non-existant-model")
self.reader.current_file_version("non-existant-model")


class LegacyReaderTestCaseMixin:
Expand Down
3 changes: 2 additions & 1 deletion tools/podio-dump
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def print_general_info(reader, filename):
Args:
reader (root_io.Reader, sio_io.Reader): An initialized reader
filename (str): The name of the input file
"""
legacy_text = " (this is a legacy file!)" if reader.is_legacy else ""
print(
Expand All @@ -30,7 +31,7 @@ def print_general_info(reader, filename):
print("datamodel model definitions stored in this file: ")
for edm_name in reader.datamodel_definitions:
try:
edm_version = reader.get_datamodel_version(edm_name)
edm_version = reader.current_file_version(edm_name)
print(f" - {edm_name} ({version_as_str(edm_version)})")
except KeyError:
print(f" - {edm_name}")
Expand Down

0 comments on commit b225083

Please sign in to comment.