Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make CreateDataFrame accessible from python #674

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion python/podio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@
except ImportError:
pass

__all__ = ["__version__", "Frame", "root_io", "sio_io", "reading", "version"]
try:
# Same mechanism as for the sio_io above
from . import data_source
except ImportError:
pass

__all__ = ["__version__", "Frame", "root_io", "sio_io", "reading", "data_source", "version"]
10 changes: 10 additions & 0 deletions python/podio/data_source.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Python module for creating ROOT RDataFrame with files containing podio Frames"""

from ROOT import gSystem

if gSystem.Load("libpodioDataSourceDict") < 0:
raise ImportError("Error when loading libpodioDataSourceDict")

from ROOT import podio # pylint: disable=wrong-import-position

CreateDataFrame = podio.CreateDataFrame
1 change: 1 addition & 0 deletions src/rds_selection.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<lcgdict>
<selection>
<class name="podio::DataSource"/>
<function name="podio::CreateDataFrame"/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to know :)

</selection>
</lcgdict>
6 changes: 6 additions & 0 deletions tests/root_io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ endif()
add_test(NAME param_reading_rdataframe COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/param_reading_rdataframe.py example_frame.root)
PODIO_SET_TEST_ENV(param_reading_rdataframe)
set_property(TEST param_reading_rdataframe PROPERTY DEPENDS write_frame_root)

if(ENABLE_DATASOURCE)
add_test(NAME read_python_with_rdatasource_root COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/root_io/read_datasource.py)
PODIO_SET_TEST_ENV(read_python_with_rdatasource_root)
set_property(TEST read_python_with_rdatasource_root PROPERTY DEPENDS read_with_rdatasource_root)
endif()
13 changes: 13 additions & 0 deletions tests/root_io/read_datasource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3
"""Small test case for checking DataSource based creating RDataFrames is accessible from python"""

import ROOT
from podio.data_source import CreateDataFrame

if ROOT.gSystem.Load("libTestDataModelDict") < 0: # noqa: E402
raise RuntimeError("Could not load TestDataModel dictionary")

input_file = "example_frame.root" # pylint: disable-msg=C0103
m-fila marked this conversation as resolved.
Show resolved Hide resolved
rdf = CreateDataFrame(input_file)

assert rdf.Count().GetValue() == 10