Check the structure of root files before hadd

Dear All,

When using hadd, several oddities occur if merging two files with different structure.

At the moment warnings only happen if the first file in the list has less structure than the rest, “Error in TChain… Could not find branch”. But the output root file may still be created, potentially with no entries, or odd spiky entries.

I’m currently checking the structure of my root files by merging all root files against each other one by one, in both directions, and checking for warnings. This is CPU-time consuming.

Firstly it would be great if hadd printed warnings even if the file with different structure was somewhere in the middle of the list, or if the warning from TChain came with the filename it could not find the branch in!

Secondly if anyone could show me an example script which just checks that two root files have the same structure, including entries in all ntuples (preferrably in PyROOT), that would be a big help!

Thanks,

Rob

In principle you can merge ROOT files having different structures. The result will be a superset of all structures in all files.
In case you merge trees with different structures, it is true that the first tree dictates the behaviour. Since there are so many possible combinations for this process, it is difficult
to design a general procedure that does not penalize the merge process in general.

Rene

Hi Rene,

Yes, I think I understand that, but the current behaviour is dangerous since it can corrupt the resulting root files, without printing any warnings. It is also obtuse since the order of the files changes the results, again with no warnings.

Do you have any example that will just compare the structure of two root files including the ntuple contents? Then I can call that before hadding.

Thanks,

Rob

[quote]Yes, I think I understand that, but the current behaviour is dangerous since it can corrupt the resulting root files, without printing any warnings.
[/quote]

hadd cannot corrupt their input files. It writes only one output file.

[quote]It is also obtuse since the order of the files changes the results, again with no warnings.
[/quote]
As I said, the resulting file is a superset of the input files. If file1 contains directories a,b,c
and file2 contains b,c,d, the resulting file contains a,b,c,d.
In case of one or more Trees, the resulting Tree is based on the structure of the first encountered Tree. If you want a different behaviour, specify the file with the preferred Tree structure first.

[quote]Do you have any example that will just compare the structure of two root files including the ntuple contents? Then I can call that before hadding.
[/quote]
No, we do not have a general example. Try to read the code in order of complexity
$ROOTSYS/tutorials/io/loopdir.C
$ROOTSYS/tutorials/io/hadd.C

Rene