forked from AIDASoft/podio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure python parts, splitting code generation and python bindin…
…gs into separate modules (AIDASoft#511) * Decouple generation tools and files from the rest of podio python files * Move some tests to podio_gen * Simplify __init__.py * Make sure to always have the Frame python wrapper when imported --------- Co-authored-by: jmcarcell <[email protected]> Co-authored-by: tmadlener <[email protected]>
- Loading branch information
1 parent
401e71a
commit 0839921
Showing
19 changed files
with
139 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,33 @@ | ||
"""Python module for the podio EDM toolkit and its utilities""" | ||
import sys | ||
|
||
from .__version__ import __version__ | ||
|
||
from .podio_config_reader import * # noqa: F403, F401 | ||
|
||
import ROOT # pylint: disable=wrong-import-order | ||
|
||
# Track whether we were able to dynamially load the library that is built by | ||
# podio and enable certain features of the bindings only if they are actually | ||
# available. | ||
_DYNAMIC_LIBS_LOADED = False | ||
|
||
# Check if we can locate the dictionary wthout loading it as this allows us to | ||
# silence any ouptput. If we can find it, we can also safely load it | ||
if ROOT.gSystem.DynamicPathName("libpodioDict.so", True): | ||
ROOT.gSystem.Load("libpodioDict.so") | ||
from ROOT import podio | ||
|
||
_DYNAMIC_LIBS_LOADED = True | ||
|
||
if _DYNAMIC_LIBS_LOADED: | ||
from .frame import Frame | ||
from . import root_io, reading | ||
|
||
try: | ||
# We try to import the sio bindings which may fail if ROOT is not able to | ||
# load the dictionary in this case they have most likely not been built and | ||
# we just move on | ||
from . import sio_io | ||
except ImportError: | ||
pass | ||
|
||
from . import EventStore | ||
|
||
try: | ||
# For some reason the test_utils only work at (test) runtime if they are | ||
# imported with the rest of podio. Otherwise they produce a weird c++ error. | ||
# This happens even if we import the *exact* same file. | ||
from . import test_utils # noqa: F401 | ||
except ImportError: | ||
pass | ||
|
||
# Make sure that this module is actually usable as podio even though most of | ||
# it is dynamically populated by cppyy | ||
sys.modules["podio"] = podio | ||
|
||
__all__ = [ | ||
"__version__", | ||
"Frame", | ||
"root_io", | ||
"sio_io", | ||
"reading", | ||
"EventStore" | ||
] | ||
# Try to load podio, this is equivalent to trying to load libpodio.so and will | ||
# error if libpodio.so is not found but work if it's found | ||
try: | ||
from ROOT import podio # noqa: F401 | ||
except ImportError: | ||
print('Unable to load podio, make sure that libpodio.so is in LD_LIBRARY_PATH') | ||
raise | ||
|
||
from .frame import Frame | ||
from . import root_io, reading | ||
|
||
try: | ||
# We try to import the sio bindings which may fail if ROOT is not able to | ||
# load the dictionary. In this case they have most likely not been built and | ||
# we just move on | ||
from . import sio_io | ||
except ImportError: | ||
pass | ||
|
||
from . import EventStore | ||
|
||
|
||
__all__ = [ | ||
"__version__", | ||
"Frame", | ||
"root_io", | ||
"sio_io", | ||
"reading", | ||
"EventStore" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/usr/bin/env python3 | ||
"""Utilities for python unittests""" | ||
|
||
import importlib | ||
|
||
|
||
import ROOT | ||
|
||
if ROOT.gSystem.Load("libTestDataModelDict.so") < 0: # noqa: E402 | ||
raise RuntimeError("Could not load TestDataModel dictionary") | ||
|
||
from ROOT import ( # pylint: disable=wrong-import-position | ||
ExampleHitCollection, | ||
ExampleClusterCollection, | ||
) # noqa: E402 | ||
|
||
from podio import Frame # pylint: disable=wrong-import-position | ||
|
||
|
||
def create_hit_collection(): | ||
"""Create a simple hit collection with two hits for testing""" | ||
hits = ExampleHitCollection() | ||
hits.create(0xBAD, 0.0, 0.0, 0.0, 23.0) | ||
hits.create(0xCAFFEE, 1.0, 0.0, 0.0, 12.0) | ||
|
||
return hits | ||
|
||
|
||
def create_cluster_collection(): | ||
"""Create a simple cluster collection with two clusters""" | ||
clusters = ExampleClusterCollection() | ||
clu0 = clusters.create() | ||
clu0.energy(3.14) | ||
clu1 = clusters.create() | ||
clu1.energy(1.23) | ||
|
||
return clusters | ||
|
||
|
||
def create_frame(): | ||
"""Create a frame with an ExampleHit and an ExampleCluster collection""" | ||
frame = Frame() | ||
hits = create_hit_collection() | ||
frame.put(hits, "hits_from_python") | ||
clusters = create_cluster_collection() | ||
frame.put(clusters, "clusters_from_python") | ||
|
||
frame.put_parameter("an_int", 42) | ||
frame.put_parameter("some_floats", [1.23, 7.89, 3.14]) | ||
frame.put_parameter("greetings", ["from", "python"]) | ||
frame.put_parameter("real_float", 3.14, as_type="float") | ||
frame.put_parameter("more_real_floats", [1.23, 4.56, 7.89], as_type="float") | ||
|
||
return frame | ||
|
||
|
||
def write_file(io_backend, filename): | ||
"""Write a file using the given Writer type and put one Frame into it under | ||
the events category | ||
""" | ||
io_module = importlib.import_module(f"podio.{io_backend}") | ||
|
||
writer = io_module.Writer(filename) | ||
event = create_frame() | ||
writer.write_frame(event, "events") | ||
|
||
|
||
if __name__ == "__main__": | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("outputfile", help="Output file name") | ||
|
||
args = parser.parse_args() | ||
|
||
io_format = args.outputfile.split(".")[-1] | ||
|
||
write_file(f"{io_format}_io", args.outputfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters