diff --git a/python/podio/base_reader.py b/python/podio/base_reader.py index a2c98a692..e078aa4ad 100644 --- a/python/podio/base_reader.py +++ b/python/podio/base_reader.py @@ -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) diff --git a/python/podio/test_Reader.py b/python/podio/test_Reader.py index 8324deab1..6be55467d 100644 --- a/python/podio/test_Reader.py +++ b/python/podio/test_Reader.py @@ -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: diff --git a/tools/podio-dump b/tools/podio-dump index a896cf3ca..f85387711 100755 --- a/tools/podio-dump +++ b/tools/podio-dump @@ -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( @@ -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}")