Hadd shuffles keys

I have a couple of files with histograms, the histograms are stored in the file in order (opening and running .ls shows them in alphabetical order).

When I run hadd on the files, the order of keys in the output file is not preserved. Some keys from the beginning go to the end and are shuffled.

Is there a way to preserve the keys order in the output file?

Or, is there a way to sort keys when reading the shuffled files?

OK, I found the problem. Some files have missing histograms, so if the first file had missing histogram and it was present in the next one, new key was put on the end of file.