Skip to content

Commit

Permalink
Improve python API, use import edm4hep instead of `from edm4hep imp…
Browse files Browse the repository at this point in the history
…ort edm4hep` (#207)
  • Loading branch information
jmcarcell authored Jun 30, 2023
1 parent 9d3c9a0 commit b85db04
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 49 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ the clases individually (for working with collections podio has its own
bindings). Make sure that `<CMAKE_INSTALL_PREFIX>/lib` is in `LD_LIBRARY_PATH`,
`<CMAKE_PREFIX_PATH>/python` is in `PYTHONPATH` and `<CMAKE_INSTALL_PREFIX>/include` is in `ROOT_INCLUDE_PATH`:
```python
from edm4hep import edm4hep
import edm4hep
particle = edm4hep.MCParticle() # default initialized particle
particle.getCharge() # 0.0

Expand All @@ -92,6 +92,9 @@ mc.setPDG(2212)
mc.getPDG() # 2212
```

In an interactive session (with `python` or `ipython`, for example) it's
possible to see all the classes by typing `edm4hep.` and then pressing TAB.

## Contributing

Contributions and bug reports are welcome! See our [contributing
Expand Down
27 changes: 24 additions & 3 deletions python/edm4hep/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
"""Python module for the EDM4HEP datamodel and utilities."""
import sys

from .datamodel import Datamodel, Utils
from .__version__ import __version__
edm4hep = Datamodel()
utils = Utils()
import ROOT
res = ROOT.gSystem.Load('libedm4hepDict.so')
if res < 0:
raise RuntimeError('Failed to load libedm4hepDict.so')

res = ROOT.gSystem.Load('libedm4hepRDF.so')
if res < 0:
raise RuntimeError('Failed to load libedm4hepRDF.so')

res = ROOT.gInterpreter.LoadFile('edm4hep/utils/kinematics.h')
if res != 0:
raise RuntimeError('Failed to load kinematics.h')

res = ROOT.gInterpreter.LoadFile('edm4hep/utils/dataframe.h')
if res != 0:
raise RuntimeError('Failed to load dataframe.h')
from ROOT import edm4hep

# Make TAB completion work for utils
setattr(edm4hep, 'utils', edm4hep.utils)

# Make `import edm4hep` work
sys.modules['edm4hep'] = edm4hep
43 changes: 0 additions & 43 deletions python/edm4hep/datamodel.py

This file was deleted.

2 changes: 1 addition & 1 deletion test/test_rdf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

import ROOT
from edm4hep import edm4hep
import edm4hep

ROOT.EnableImplicitMT()

Expand Down
2 changes: 1 addition & 1 deletion test/utils/test_kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
import cppyy

from edm4hep import edm4hep
import edm4hep

# A few shorthands for slightly easier to read tests below
p4 = edm4hep.utils.p4
Expand Down

0 comments on commit b85db04

Please sign in to comment.