I’d like to save meta-data in a ROOT file next to a TTree with triggers. More specifically, I would like to save the search parameters which were used to produce the triggers.
My question is: what is the best way and the best structure to save meta-data in a ROOT file?
I thought about using a TTree with 1 branch per parameter and with only one entry. This is a bit silly. Do you have a better suggestion?
I just learned about this last week, but each TTree contains a TList called UserInfo (root.cern.ch/root/html/TTree.htm … etUserInfo) which can store any number of TObjects. For storing individual numbers, you could use TParameter and set the name and value and push it into the UserInfo TList.
TFiles are compressed pretty efficiently, so even if you make an extra branch in your TTree for every parameter (and fill it for every event), the file won’t grow very much. Depending on how efficient you need your code/storage, this might be the easiest way. Then you can just GetEntry(0) to retrieve the parameters before looping through the individual entries.
The UserInfo method mentioned above is probably more efficient, but requires manipulating more stuff than the existing TTree that contains the data. The extra TTree branches solution keeps all the related info in one place, and even allows for merging of TTrees with different parameters and later cutting, etc.
As a third possibility, you could also make a separate parameter TTree with many branches per variable and one entry. Then in your main TTree with many events have it treat the parameter TTree as Friend tree and rebuild the event index (described in the user’s guide). That way you can have a 1-1 correspondence with the trigger info parameters and the events even if you merge files!
I like the third possibility proposed by Saboot. Before implementing it, I want to make sure this is what I need.
What do you mean by “rebuild the event index”? I know what the event index is but I don’t see your point.
The merging of TTrees is crucial for me. Here is an example of what I need to do.
Say I have a “trigger” tree and another tree “param” with my parameters (only one entry).
I have 2 root files: file1.root and file2.root with N1 and N2 triggers respectively. Then I merge the 2 root files. I end up with a “trigger” tree with N1+N2 entries and a “param” tree with 2 entries. How can I know that the first entry of “param” goes with the N1 first entries of “trigger” and the second entry of “param” goes with the N2 last entries of “trigger”.