I think TMap is interesting to manipulate. I have a std::map<TString, TString> that I would like to convert into a TMap, save it into a root file (possibly not at the root of the file), and retrieve it later on.
Could you advice on this ?
Here is what I have done so far, but the TMap object is split into separate keys when saved into a root file. ( I guess this is somehow expected? Read TMap from a file, @pcanal, @eguiraud would you maybe have an idea ?)
TFile *f = TFile::Open("test.root", "recreate");
TMap *m = new TMap();
m->Add(new TObjString("test:0"), TObjString("My Test 0"));
m->Add(new TObjString("test:1"), TObjString("My Test 1"));
m->Write();
f->Close();
Opening the saved file is returning this list, but I would like to store it as a single object.
Collection name='THashList', class='THashList', size=4
TKey Name = test:0, Title = Collectable string class, Cycle = 1
TKey Name = My Test 0, Title = Collectable string class, Cycle = 1
TKey Name = test:1, Title = Collectable string class, Cycle = 1
TKey Name = My Test 1, Title = Collectable string class, Cycle = 1
Sure, ROOT I/O supports writing arbitrary C++ objects to TFile!
For many standard C++ classes, you can use my example from above and just change std::map to the corresponding class.