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

Add direct support for REST classes in PyROOT (Python) #323

Merged
merged 7 commits into from
Nov 13, 2022

Conversation

lobis
Copy link
Member

@lobis lobis commented Nov 10, 2022

lobis Ok: 72

After this PR, REST classes can be imported into Python via

import REST

# they can be accessed via (but not recommended)
run = REST.ROOT.TRestRun()

# this would be the preferred way to use REST classes from Python
import REST
import ROOT

run = ROOT.TRestRun()

@lobis lobis added python Related to the Python bindings for REST (PyROOT) enhancement New feature or request labels Nov 10, 2022
@lobis lobis marked this pull request as ready for review November 10, 2022 21:38
@lobis lobis requested a review from a team November 11, 2022 14:01
@jgalan
Copy link
Member

jgalan commented Nov 13, 2022

Thanks for this PR. I love it!

@jgalan
Copy link
Member

jgalan commented Nov 13, 2022

When I do import REST in a python interactive session it takes long to load. I imagine this is because it is trying to load macros and not just libraries?

@lobis lobis merged commit 11feddb into master Nov 13, 2022
@lobis lobis deleted the lobis-python-bindings branch November 13, 2022 20:14
@lobis
Copy link
Member Author

lobis commented Nov 13, 2022

When I do import REST in a python interactive session it takes long to load. I imagine this is because it is trying to load macros and not just libraries?

It's because loading root takes a long time (import ROOT). import REST calls import ROOT behind the scenes (if it has not been called before, as other python imports) which takes a few seconds usually. If you do import ROOT and then import REST it should be instant I think.

This only loads REST libraries, you cannot use macros from python.

@Vindaar
Copy link
Member

Vindaar commented Nov 15, 2022

What's the actual reason that the REST shared libraries need to be loaded only to read a REST generated ROOT file anyway? Doesn't ROOT provide some interface to define custom types to store in a ROOT file (I assume that's what requires it)?
I've once tried to be able to read from an AnalysisTree with pure ROOT and couldn't get anything sensible out of it (segfault land, thanks ROOT!). Or maybe there is some interface one can use to define the correct structs / whatever such that reading without REST is possible that I'm not aware of?

@lobis
Copy link
Member Author

lobis commented Nov 15, 2022

What's the actual reason that the REST shared libraries need to be loaded only to read a REST generated ROOT file anyway? Doesn't ROOT provide some interface to define custom types to store in a ROOT file (I assume that's what requires it)? I've once tried to be able to read from an AnalysisTree with pure ROOT and couldn't get anything sensible out of it (segfault land, thanks ROOT!). Or maybe there is some interface one can use to define the correct structs / whatever such that reading without REST is possible that I'm not aware of?

You can read a REST generated root file with ROOT without loading libraries or more especifically dictionaries, atleast when reading data from a TTree. This only works if the TTree splitting is set to the default value (full splitting or no splitting, I don't remember).

What you cannot do without dictionaries is call the methods of each class. I would assume you can read data from EventTree / AnalysisTree (REST trees) directly from PyRoot also without loading dictionaries. You can also use https://github.com/scikit-hep/uproot5 to avoid ROOT altogether, I have verified this to work with REST before.

I don't think you should be getting a segfault when reading from the analysis tree, maybe something is broken now (we should add a test for this...). I remember for instance that if we added an additional level of depth to the EventTree (event > track > hits, instead of event > track - hits, which is what we have now, this reading without loading REST libraries was also broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python Related to the Python bindings for REST (PyROOT)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants