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

Fix assignment to non-exisitng members in createEDM4hep.py #357

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

m-fila
Copy link
Contributor

@m-fila m-fila commented Sep 4, 2024

BEGINRELEASENOTES

  • Fixed typos in member assignment in createEDM4hep.py

ENDRELEASENOTES

Fixed the typos in script creating example edm4hep file.
Due to the typos a new member was created instead of updating a value of an existing one., hence incorrect values were written to the output. Originally reported on #353.

Since earlier there were some similar issues reported (#355) I checked if there are any more typos by setting a pythonizations that forbids dynamically creating new members:

import cppyy

def freeze_class(klass, name):
    def freeze_setattr(self, attr, val):
        if not attr in type(self).__dict__:
            raise AttributeError(attr)
        old_setattr(self,attr,val)

    old_setattr = klass.__setattr__ 
    klass.__setattr__ = freeze_setattr

cppyy.py.add_pythonization(freeze_class, "edm4hep")

which gives errors like that:

Traceback (most recent call last):
  File "/home/mafila/EDM4hep/./scripts/createEDM4hepFile.py", line 234, in <module>
    state.d0 = next(counter)
  File "/home/mafila/EDM4hep/./scripts/createEDM4hepFile.py", line 8, in freeze_setattr
    raise AttributeError(attr)
AttributeError: d0

The only errors were for d0 and z0 so hopefully that was the last bug of this type

@m-fila
Copy link
Contributor Author

m-fila commented Sep 4, 2024

As a side note I don't see much difference when running the script without pythonization:

real    0m11.938s
user    0m7.229s
sys     0m3.836s

and with it

real    0m12.041s
user    0m7.305s
sys     0m3.866s

(single run)

@tmadlener
Copy link
Contributor

Nice. The pythonization look generic enough to add it to the ones we already have available in podio, right?

@jmcarcell jmcarcell merged commit c88b9cd into key4hep:main Sep 4, 2024
7 of 10 checks passed
@jmcarcell
Copy link
Member

Yeah, this default behaviour of being able to set anything from python is not great since mistakes like I did will always end up happening...

@m-fila
Copy link
Contributor Author

m-fila commented Sep 4, 2024

Yeah, this default behaviour of being able to set anything from python is not great since mistakes like I did will always end up happening...

They call it a feature 😉

Nice. The pythonization look generic enough to add it to the ones we already have available in podio, right?

Thank you. This version is not taking into account attributes from super class. I need to think whether it might be a problem for podio generated classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants