Automatically cast dict to map in pyROOT

I’m porting some plotting methods to C++ for wider use. I use a python dict of TH1F objects indexed by their name.
Here’s the c++ prototype:

typedef std::map<std::string,TH1*> HistogramBook;
THStack* makeStackFromList(HistogramBook histList,std::string name="");

From python, I would have a structure like:

histList={'h1':ROOT.TH1F('h1','Hist 1',50,-5,5),'h2':ROOT.TH2F('h2','Hist 2',50,-5,5),'h3':ROOT.TH3F('h3','Hist 3',50,-5,5)}

What I get out is:

  File "path/to/source/python/", line 119, in makeStackFromList
TypeError: THStack* PrettyPlotsUtils::makeStackFromList(HistogramBook histList, string name = "") =>
    could not convert argument 1

Is there a way to make this work?


sorry for the late reply, but I’ve been traveling.

No, there’s no connection between python dicts and C++ std::maps (there should be, but my TODO list is long …). You will have to copy over the values from the dict into the std::map (and make sure that there is a dictionary for the latter.

(You could use an annotation to make this nice for other users your code.)