h5extractf raising exception on offline files with no event
Summary
I have a set of offline files containing simulated triggered events and I would like to convert them into the hdf5 format using h5extractf --without-full-reco -o output.h5 input.root
. When I do this file by file, I get an IndexError
for some of them. I attached an stderr file where one can see the error. The reason for this is that some of these offline files are empty, i.e., containing no triggered event. One could say now that this is desired behaviour since these files contain no useful information. But for my purposes, it would be much easier if I could have a one-to-one relation between the offline files and the hdf5 files.
I would suggest to implement h5extractf in a way that empty offline files result in hdf5 files with empty datasets. This could be achieved by either using the class h5py.Empty
or by creating the datasets with shape (0,)
. I would prefer the latter, because a dataset with shape (0,)
can be iterated through in a for-loop without raising an exception. This means that code using for-loops wouldn't have to be changed in order to work on empty hdf5 files. Also code using dataset.shape[0]
wouldn't have to be changed because it returns, as one would intuitively expect, the value zero.
We could also think about introducing a command line option called, e.g., --accept-empty-file
. If this option is set, h5extractf
would convert empty files, otherwise it would raise an exception (which could be more meaningful than an IndexError
). This would make sure that anyone using the assumption that the hdf5 files must contain at least one event wouldn't have to change their code, although I doubt that anyone uses this assumption.
Edit: I'm using v9.13.0 so far, and I just saw that a better error message was implemented in v9.13.2 some days ago.
Describe a possible workaround to achieve the same functionality
I could write some code just for me that checks whether an offline file is empty and then it would create a hdf5 file with a similar format to the one that we use with the difference that the datasets would be empty. But then, my hdf5 files are not compatible to anyone elses hdf5 files. So this would not be a very elegant solution.
mcCustom.gsg_ap-muon-NC_1-4-GeV_nGen-10000.km3sim.jterbr.jshower.9_err.txt