Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jim Pivarski
    @jpivarski
    "Create" as in write a TTree to a ROOT files?
    lemiere
    @lemiere
    YES !
    Jim Pivarski
    @jpivarski
    Okay, that's currently only supported in Uproot 3, not Uproot 4, which complicates things.
    lemiere
    @lemiere
    up to now, I can read my TTree into a root file.
    Arf !
    Jim Pivarski
    @jpivarski
    Since you're just starting out now, I'd want to point you to Uproot 4 documentation only (as the interface has changed), but for this feature, you'd need to import uproot3.
    lemiere
    @lemiere
    So i've to pip install uproot3
    Jim Pivarski
    @jpivarski
    Also, only the case of flat arrays (TBranch type is a number or boolean, like np.float32 or np.int64) is documented.
    lemiere
    @lemiere
    my main purpose is to write a df5 to root convertor. Colleagues used python (even if I'm more fluent using C++) That's why I'm looking after python solutions
    Jim Pivarski
    @jpivarski
    It's admittedly hard to find because it's on the Uproot 3 website, which is not featured because (apart from this one feature) we want to move people to Uproot 4.
    You mean HDF5?
    lemiere
    @lemiere
    YES
    Jim Pivarski
    @jpivarski
    Then your case is covered, unless you're using HDF5's COMPOUND or VARLEN arrays, which are not mainstream.
    When I say that Uproot 3 writes "flat arrays," I mean any rectilinear array, such as shaped arrays from NumPy.
    lemiere
    @lemiere
    I've several dataset which contain float64... That should pass
    Jim Pivarski
    @jpivarski
    You should be able to do import h5py, uproot3, get the NumPy arrays from the h5py.File or Group, and then follow the above to write it into a ROOT file with uproot3.
    For any other purpose, I recommend using Uproot 4 so that you don't have to remember two ways of doing something.
    lemiere
    @lemiere
    ;-)
    many thx ! That's it I 'recreate' my first root file with TTree using uproot3 !
    lemiere
    @lemiere
    can you confirm one point ?
    newtree to create the branch then extend to fill with my data
    no needs to use method to write the file
    Jim Pivarski
    @jpivarski
    That's right. extend is like Python's list.extend in that it takes a batch of data at a time.
    It's like this so that you don't have to have the whole array in memory at once. But if you do have the whole array in memory at once, do just a single extend.
    If I remember right, each call to extend creates 1 TBasket in every TBranch. (You have to supply an array for every TBranch in each call to extend, so that they're all kept the same length at all times. TTrees don't have TBranches with different numbers of entries.)
    The bigger you make the TBaskets, assuming that the writer and reader do not run out of memory, the better performance you'll get.
    lemiere
    @lemiere
    great !
    I just tried several uproot3.newtree and file["t"].extend but something's going wrong
    that's not very conveniant...
    Jim Pivarski
    @jpivarski

    that's not very conveniant...

    The interface will be improved in Uproot 4.

    But about something going wrong, let me know when you get a sense of what the issue is.

    lemiere
    @lemiere
    file["t"]["branch2"].newbasket --> do the job as said :-D
    So that work !
    I've no more battery and one rule ! do not plug the PC the evening ....
    Jim Pivarski
    @jpivarski
    Okay, so the high-level extend interface (in which all TBranches must be filled each time) is not working, but the low-level newbasket interface is? I'll keep that in mind when I visit this again.
    lemiere
    @lemiere
    I will write my convertor tomorrow morning. I learned how to read HDF5 file this morning and tonight how to write a tree using uproot! It's time to move on ;-)
    Bye and Thx
    Jim Pivarski
    @jpivarski
    Sure! Cheers!
    lemiere
    @lemiere
    I will try to come back to follow the project
    have a good night
    lemiere
    @lemiere
    succeed in 30 lines :-D
    Daniel Wenz
    @WenzDaniel

    Hej, I have a short question regarding the reading of a single integer value. I opened a root file via root_dir = uproot.open(file_path) and try to load now a single integer value which is written into another sub-directory:

    events_dir = root_dir['events']
    events_dir['nbevents']

    While I could swear, that a few versions ago this syntax directly returned an integer value, I now get back the following:

    <TParameter<int> (version 2) at 0x7f276abefca0>

    My current uproot version is 4.0.2, but I do not remember the previous one I used. I am also not sure whether I remember it correctly, but either way could you tell me how I can access the stored value? Already, thanks a lot in advance.

    Daniel Wenz
    @WenzDaniel
    Probably I should add events_dir = <ReadOnlyDirectory '/events' at 0x7f276abef880>
    Daniel Wenz
    @WenzDaniel
    Okay, found it. If anyone has the same issue: events_dir['nbevents'].members['fVal'] works. Thanks
    Jim Pivarski
    @jpivarski
    Objects in ROOT directories must be classes, and I think they must be subclasses of TObject, so it couldn't have been a single integer. But we could add a convenience method to the TParameter<int> class so that you could access the integer with .value instead of .members["fVal"] (or equivalently, .member("fVal"), which only fetches that one).
    Daniel Wenz
    @WenzDaniel
    Thanks a lot for your answer. If it is not too much work yes, I think this would help in the future. At least this was my first idea to try .value.
    Jim Pivarski
    @jpivarski
    I was going to try to just add it as a quick PR, but I realized I'd need an example file. If you want to try this, could you open a feature request and drop a file containing a TParameter<int> in it? (GitHub accepts ROOT files if they're renamed to end in .txt.)
    Daniel Wenz
    @WenzDaniel
    You have already one from our experiment in an older uproot3 issue: scikit-hep/uproot3#64 the integer is in events/nbevents. But if you like I can also upload it in a new request for uproot4.
    Jim Pivarski
    @jpivarski
    Found it, thanks! I can do this without the formality of a GitHub Issue.
    Jim Pivarski
    @jpivarski