-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add python bindings for the datamodel classes #204
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care of this. This already looks pretty good, My main complaint is the factory being something that the users can see. I suppose we need the factory because of the dynamic nature of ROOTs python bindings, right? Can we still try to "hide" it in the __init__.py
or in datamodel.py
such that it is already instantiated and what the user sees would look something like:
from edm4hep import edm4hep
particle = edm4hep.MCParticle()
# ...
This should also work with from edm4hep import *
, but I am not sure I like that better. Ideally it would just be import edm4hep
and then we have the factory in hand, but I don't see a way how that could work.
It has been changed now to
or the one in the README:
|
Thanks, this looks very good now. I just realized we do have some tests for utility functionality already, that redo some of the stuff that is introduced here: EDM4hep/test/utils/test_kinematics.py Lines 10 to 16 in 1145e20
Now that we have a proper place for an |
Even more cases in the tests that could be cleaned up: Lines 5 to 9 in 1145e20
|
That is done now. I think it could be done on demand when using python but in the cases where something in |
res = ROOT.gInterpreter.LoadFile('edm4hep/utils/kinematics.h') | ||
if res != 0: | ||
raise RuntimeError('Failed to load kinematics.h') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this work like this?
from edm4hep import utils
p4 = utils.p4
or
import edm4hep
p4 = edm4hep.utils.p4
Or is this already possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some changes in ad539e7 and now it's possible:
from edm4hep import edm4hep
particle = edm4hep.MCParticle() # default initialized particle
particle.getCharge() # 0.0
from edm4hep import utils
p = utils.p4(particle) # edm4hep.utils.p4 or utils.p4 works
print(p) # (0,0,0,0)
There are two classes now, one for serving all classes from edm4hep and another one for the utils namespace. If there were more namespaces it's easy to change to a dictionary-based class that would store each of the edm4hep.namespace
object and serve by doing a lookup on the dictionary
81d328b
to
ad539e7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, thanks a lot for having another look at this. Since we are already at it, I think we could also add a __version__
to the __init__.py
for an even more pythonic feel.
In podio we have a __init__.py.in
that we configure during the cmake stage. This should be trivial to add here as well, I think.
import ROOT | ||
res = ROOT.gSystem.Load('libedm4hepDict.so') | ||
if res < 0: | ||
raise RuntimeError('Failed to load libedm4hepDict.so') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering whether all these RuntimeError
s should be ImportError
s instead. In the end import edm4hep
is the thing that will fail if one of these is triggered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well typically for the libraries it will be because they are not in LD_LIBRARY_PATH
which is a runtime search so one could say it's a RuntimeError
... both are quite generic, I don't think ImportError
tells you much, that will also be quite obveious when checking the trace. So I don't have a strong opinion on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, maybe a RuntimeError
is better, because that doesn't point you towards a python problem in this case.
…m4hep from python" This reverts part commit a0f4852.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really final comment (:wink:): I think it would make sense to add python/edm4hep/__version__.py
to .gitignore
BEGINRELEASENOTES
ENDRELEASENOTES
See the README for examples on how to use them