Attach metadata to TH1s, TObjects?

Hello experts,

Is it possible to attach metadata to a TH1 object (or a TObject in general)? For example, a dictionary of strings could be useful for identifying the contents of the histogram:

type: mc
datasetid: 12345
process: vbfhiggs
region: signal
cut: preselection
channel: 4e
systematic: nominal

I have been putting this information into the histogram name, separated by a delimiter, and parsing it. I also organize my ROOT file structure so that it expresses some of this information (multiple layers of TDirectories, with the name of each TDirectory specifying an attribute, e.g. TDirectory with name 12345 to identify that histograms inside it correspond to dataset ID 12345).

What I am looking for something similar to the UserInfo TList for TTrees: Meta-data in ROOT files.

Thanks,
Justin


ROOT Version: 6.14/08
Platform: SLC6/Centos 7
Compiler: gcc 6.2.0


Each TH1 as a TList associated. You can access it using GetListOfFunctions.
May be that can help you ?

Thank you for the suggestion. Do you think inserting a TMap – that I populate with TMap::Add(keyTString, valueTString) – into the TList returned by TH1::GetListOfFunctions is a good solution? Perhaps you can think of something better?

I was also exploring writing a std::map<std::string, std::string> or even a std::map<std::string, myMetadataStruct> to the TFile.

I understand that dictionaries for some STL containers are available by default with ROOT [1].
How can I get the list of them – i.e. what types T for std::vector<T> and std::map<Key, T> can I write to a TFile without setting up a dictionary entry for Key and T?

How would I merge the metadata together from multiple files? E.g. if I have a TList with one TMap in each file, then the merged result (hadd) will be one TList with multiple TMaps. Then I will have to merge the TMaps together manually. Or, if I have std::map<Key, T>, then I will have to implement std::map<Key, T>::Merge(TCollection *maplist). Is this correct?

Thanks,
Justin

[1] https://root.cern.ch/notebooks/HowTos/write-objects-to-a-file.html
Writting and Getting a std::vector from a TFile
https://root.cern.ch/root/html/tutorials/math/mathcoreVectorCollection.C.html

May be @moneta has something else to suggest.

I am not completely sure. The maps (if having the same name) might merge together. Give it a try.

Adding object in the TList is a very flexible solutions. You have only the constraints that these meta-objects needs to be something deriving from TObject’s. The only drawback is that the histogram list of functions are not merged when using hadd. You will have to merge them by hand

Lorenzo

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.