I am putting a TMap
into a TTree branch. But the following minimal reproducer shows that when I ‘process’ my tree with a RDataFrame I don’t get the maps I was expecting:
TTree* t = new TTree("t","t");
TMap* myMap = new TMap;
t->Branch("myMap",&myMap);
auto k = new TObjString("prop");
myMap->Add(k, new TObjString("value"));
myMap->Print();
t->Fill();
// replace with different value
myMap->Remove(k);
myMap->Add(k, new TParameter<int>("par",4));
myMap->Print();
t->Fill();
t->ResetBranchAddresses(); // otherwise DataFrame will merge with existing obj
ROOT::RDataFrame df(*t);
auto selector = [](const TMap& m) {
m.Print();
return true;
};
df.Foreach(selector,{"myMap"});
This prints:
Collection name='TMap', class='TMap', size=1
Key: TObjString = prop
Value: TObjString = value
Collection name='TMap', class='TMap', size=1
Key: TObjString = prop
Value: TParameter<int> par = 4
Collection name='TMap', class='TMap', size=1
Key: TObjString = prop
Value: TObjString = value
Collection name='TMap', class='TMap', size=2
Key: TObjString = prop
Value: TObjString = value
Key: TObjString = prop
Value: TObjString = value
Note that the last TMap print should have been a copy of the 2nd print, instead it seems to be some strange map of size 2, with two copies of the first entry (prop: value) in it. I was expecting it to be a map of size 1 with (prop: 4) in it.
What did I do wrong?
Thanks
Will