root2hdf5 conversion

65 views
Skip to first unread message

Saba Sehrish

unread,
Jun 19, 2014, 11:56:27 AM6/19/14
to rootpy...@googlegroups.com
Hi, 

I have just started to look at the root2hdf5 converter provided in rootpy, and essentially I am using rootpy.root2hdf5.root2hdf5 to achieve that. 
Running it on one of the root files we have, I get the error message shown below.

Is it possible to tell this function to only convert one tree from the file? If not is there any development going to achieve that? 
Also, what could be causing "empty datatype" as shown in the following error message. 

Thanks,
Saba

INFO:rootpy.root2hdf5] Will convert 9 trees in this directory

INFO:rootpy.root2hdf5] Converting tree 'Parentage' with 1 entries ...

/home/ssehrish/.local/lib/python2.7/site-packages/root_numpy/_tree.py:280: RootNumpyUnconvertibleWarning: cannot convert leaf Hash of branch Hash with type art::Hash<5> (skipping)

  weight_name)

/home/ssehrish/.local/lib/python2.7/site-packages/root_numpy/_tree.py:280: RootNumpyUnconvertibleWarning: cannot convert leaf Description of branch Description with type art::Parentage (skipping)

  weight_name)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "/home/ssehrish/.local/lib/python2.7/site-packages/rootpy-dev-py2.7.egg/rootpy/root2hdf5.py", line 169, in root2hdf5

    recarray = tree2rec(tree, selection=selection)

  File "/home/ssehrish/.local/lib/python2.7/site-packages/root_numpy/_tree.py", line 312, in tree2rec

    weight_name=weight_name).view(np.recarray)

  File "/home/ssehrish/.local/lib/python2.7/site-packages/root_numpy/_tree.py", line 280, in tree2array

    weight_name)

  File "tree.pyx", line 594, in _librootnumpy.root2array_fromCObj (root_numpy/src/_librootnumpy.cpp:597)

  File "tree.pyx", line 524, in _librootnumpy.tree2array (root_numpy/src/_librootnumpy.cpp:524)

  File "tree.pyx", line 420, in _librootnumpy.init_array (root_numpy/src/_librootnumpy.cpp:420)

TypeError: Empty data-type



Noel Dawe

unread,
Jun 20, 2014, 6:18:59 AM6/20/14
to rootpy...@googlegroups.com
Hi Saba,

An option to only convert specific trees is not yet implemented.

But this uncovers a bug in root_numpy. What happened is none of the branches in a tree were supported types and therefore the list of branches to convert was empty. Then you got the same error as:

>>> import numpy as np
>>> np.empty(10, dtype=[])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Empty data-type

since dtype was an empty list.

For now, you can of course follow the same procedure as implemented in root2hdf5 to convert a single tree:


recarray = tree2rec(tree)
table = hfile.create_table(group, tree.GetName(),
                          recarray, tree.GetTitle())

or first copy the trees you want converted to a new ROOT file and then run root2hdf5 on that new file.

I'll fix the bug in root_numpy. Thanks for reporting this! After the bug is fixed, the script will simply skip trees where all the branches are not supported.

Cheers,
Noel


--
You received this message because you are subscribed to the Google Groups "rootpy users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rootpy-users...@googlegroups.com.
To post to this group, send email to rootpy...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rootpy-users/69594839-00d1-4f0f-bb52-09da86af2a80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Noel Dawe

unread,
Jun 20, 2014, 7:48:29 AM6/20/14
to rootpy...@googlegroups.com
I've fixed the problem in root_numpy:


Once that is merged I will implement an option in root2hdf5 to skip trees that result in any exception being raised by root_numpy.

Noel Dawe

unread,
Jun 22, 2014, 1:59:43 AM6/22/14
to rootpy...@googlegroups.com, Saba Sehrish
Hi Saba,

This problem should now be fixed.

Just upgrade root_numpy to version 3.3.1:

pip install --user -U root_numpy

and update your rootpy installation.

root2hdf5 has the new option: --ignore-exception where a tree will be gracefully skipped if an exception is raised during the conversion.

I also factored out the tree conversion into a tree2hdf5 function (now called by root2hdf5). So you can call that function to convert a specific tree if needed:


Cheers,
Noel
Reply all
Reply to author
Forward
0 new messages