Hello all,
After several days struggling with the HDF5 to ROOT conversion, I have created a program based on the original one posted by Giuseppe Vacanti:hdf2root.tar.gz (3.74 KB)
It converts the whole HDF5 structure into TTrees:
For every Group in the HDF5 file, hdf2root creates a TTree (named as the orginal Group) which stores the info contained in the original DataSets. Moreover, the Attributes of the Group are stored in another TTree (named as the original group plus “_att”), together with the Attributes of every DataSet in the Group.
The program is thought to work in any kind of HDF5 file and make a “general” conversion.
It works in all the data files I have tested, which amounts to 4 or 5 different types (only!).
A clear limitation would be how to handle more complex DataTypes. Up to know, only simple types are supported, but this could be enough for many users (it is actually enough for the files I have to handle!).
The usage is quite simple:
hdf2root just needs the original HDF5 file as input to create a root file with the same name. If you want a different output name, put it in as a second argument. If the –seq is set, hdf2root create the TTrees for the DataSets in sequential mode. This means that the first dimension of the data set is used like an “event index” (if you know what I mean…).
I aim you (interested people) to take a look and send some feedback.
One could start with the example file I posted in a previous post in this thread (gamma.h5).
Warning: I am only experiencing problems with the conversion of hdf5_strings mostly present in Attributes.
The size of these objects is not 1 to 1 with their length and, as a result, larger strings of characters are stored in root unnecessarily. This could be a problem of the particular hdf5 files I am using, instead of the converter itself.
I tried to compile the program you attached but I get the msg below. I am guessing that I am missing mpif77. I tried to install that through yum searching for openmpi but none of the packages I found help. Do you know if mpif77 is compatible with SLC6?
======================================
[wht34@icarus hdf2root]$ make
make: mpif77: Command not found
Linking hdf2root
hdf2root.o: In function main': /home/wht34/MyCodes/hdf2root/hdf2root.cpp:394: undefined reference toH5check_version’
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/…/…/…/…/lib64/libhdf5_cpp.so: undefined reference to H5Tunregister' /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/libhdf5_cpp.so: undefined reference toH5set_free_list_limits’
Try this new version:hdf2root.tar.gz (4.86 KB)
You will need a root installation and the HDF5 libraries for C++.
There are a configuration script where you can define the paths to the needed libraries.
Let me know wether you succeed to compile and or not.
I modified the env.sh file to point to my root installation directory. I am not sure if I pointed the hdf5 interface correctly but they’re the only hdf5 libraries I found on my computer. Make is still complaining about
undefined reference to `H5check_version’ and so on with all these H5 commands being undefined.
The compiler also has to know where the headers for HDF5 are.
If in the configuration script you define the environment variable HDF5CPP, the Makefile would define the path to the HDF5 headers in this way: $HDF5CPP/include.
The code compiles now but I run into this runtime error now. I have libhdf5_cpp.so.6 but not 8 in my /usr/lib64.
[wht34@icarus hdf2root]$ ./hdf2root --ver lux10_20130611T0605_f000001_eb00014.hdf5 lux10_20130611T0605_f000001_eb00014.hdf5.root
./hdf2root: error while loading shared libraries: libhdf5_cpp.so.8: cannot open shared object file: No such file or directory
[wht34@icarus hdf2root]$ ldd hdf2root.e | grep libhdf5_cpp.so.8
libhdf5_cpp.so.8 => not found
If the hdf5 libraries are located at /usr/local/hdf5/lib, the include files should be at /usr/local/hdf5/include.
In the configuration script you should define:
export HDF5CPP= /usr/local/hdf5
export LD_LIBRARY_PATH=$HDF5CPP/lib:$LD_LIBRARY_PATH
By the way, in which system are you trying to build the program?
DYLD_LIBRARY_PATH is used for macos, for linux systems it is LD_LIBRARY_PATH the variable which holds the path to the needed libraries.
Hello,
Thanks to your interest I have updated the code into a more professional fashion.
I have tried it and it works in both linux and mac os platforms.
Give it a try: github.com/delaossa/hdf2root
In the config folder there are various examples of configuration files.
Pick up the most similar to your system and modify it accordingly.
Good luck!
The git version of your code compiles fine but the executable still doesn’t do anything to the hdf5 test file.
It’ll just say converting … , but no root output comes out with hdf2root test.hdf5 test.root.
Here’s the log for the compilation and my env.sh file.
Actually by renaming the extension of my hdf5 to h5 the program does convert the h5 to root. The output created a bunch of broken trees however. Do you know if there’s any specially formatting of the hdf5 file in order to make this conversion to .root?
[wht34@icarus hdf2root-master]$ hdf2root test.h5 test.root
Converting test.h5 …
Error in TBranch::TLeaf: Illegal data type for nb_seqs/nb_seqs/c
Error in TBranch::TLeaf: Illegal data type for nb_chs/nb_chs/c
Error in TBranch::TLeaf: Illegal data type for trig_ch/trig_ch/c
Error in TBranch::TLeaf: Illegal data type for pulse_detect_pretrigger/pulse_detect_pretrigger/c
Error in TBranch::TLeaf: Illegal data type for pulse_end_posttrigger/pulse_end_posttrigger/c
Error in TBranch::TLeaf: Illegal data type for baseline_average_samples/baseline_average_samples/c
Error in TBranch::TLeaf: Illegal data type for sampling_freq_MHz/sampling_freq_MHz/c
Error in TBranch::TLeaf: Illegal data type for delay_buffer/delay_buffer/c
Error in TBranch::TLeaf: Illegal data type for vptg/vptg/c
Error in TBranch::TLeaf: Illegal data type for save_pair/save_pair/c
Error in TBranch::TLeaf: Illegal data type for baseline_freeze_enable/baseline_freeze_enable/c
Error in TBranch::TLeaf: Illegal data type for timestamp_clear/timestamp_clear/c
Error in TBranch::TLeaf: Illegal data type for end_address_threshold/end_address_threshold/c
Error in TBranch::TLeaf: Illegal data type for read_xlm/read_xlm/c
Error in TBranch::TLeaf: Illegal data type for water_thresh/water_thresh/c
Error in TBranch::TLeaf: Illegal data type for max_pulse_length/max_pulse_length/c
Error in TBranch::TLeaf: Illegal data type for write_log_files/write_log_files/c
Error in TBranch::TLeaf: Illegal data type for max_file_time_secs/max_file_time_secs/c
Hello,
Good. That means that the program works to such an extend…
It is true that the program filters the input files to have the .h5 extension. I have just fixed that and now it also accepts .hdf5 extensions. Update it from the git repository to get that version if you want.
Take into account that I made the program for my personal purpose and decided to shared it with others.
Normally, I only have to convert relatively simple hdf5 files and the program does its job.
But it is very likely that your files are more complex and/or they contain some elements that cannot be currently handled by hdf2root.
Would you send me one of your files so I can take a deeper look to it?
Another solution, if you are familiar with C++, is that you implement the missing features that you need and contribute to the hdf2root utility. The Git repository is also meant for that and you can “fork” the project, develop what you want, and eventually merge with the original one if success.
Are you up for this?
Dear delaossa,
thanks to your code I has been able to convert hdf file to root file (I just modified the extension from hdf5 to hdf).
I tried to visualize my root file with TreeViewer but I have some problem. And I would like understand if is just my fault or the output root file have some limit to fix. Probably not.
My hdf file has X value, Y value, Z value (equal to X value), a dataset called DATA that is a matrix 360X1024 and another dadaset with the errors of DATA so another matrix 360X1024.
Using TreeViewer when I put in in x_empty the Y value, in y_empty the X value (for my case the axis are inverse) and in z_empty the DATA. I try to plot I get out just a 2 dimensional graph in 3D plot and I and he is not able to associated the columns whit X-axes and the row with Y-axes, so I don’t have a surfacer as I would like have. It depends because the z_empty want a vector and not a matrix? I put in some information about my root file end I put in also the root file to better understand. What I would like see is a 3D plot with all my data…
[code]echo "root [3] TFile f2(“120195_120199.root”);
root [4] gDirectory->pwd()
120195_120199.root:/
root [5] .ls
TFile** 120195_120199.root Dump of HDF file
TFile* 120195_120199.root Dump of HDF file
KEY: TTree root;1 DataSets in root group
KEY: TTree entry1;1 DataSets in entry1 group
KEY: TTree data1;1 DataSets in data1 group
KEY: TTree root_att;1 Attributes of root group
KEY: TTree entry1_att;1 Attributes of entry1 group
KEY: TTree data1_att;1 Attributes of data1 group
data1->Print()
*Tree :data1 : DataSets in data1 group *
*Entries : 1 : Total = 2978283 bytes File Size = 2976213 *
Hi Alberto,
your code works fine, but looks like it skips datetime objects (such as 18-char-long YYYYMMDDHHMMSS.mmm), since non-supported.
Could this feature be added?
Alex