Accessing std::map in PyRoot


Suppose I fill a TTree using a C++ based macro with one of its branches a std::mapstd::string,int. How do you access the different key values of the map? I figured it would’ve been very similar to a python dictionary, but when I try something like this:

import ROOT
f = ROOT.TFile('Output.AANT.root')
t = f.Get('MyTree')

for i in xrange(t.GetEntries()):
  print t.MAP_NAME["KEY_NAME"].second


  print t.MAP_NAME["KEY_NAME"]

I keep getting a seg fault:

#11 0xf6e78764 in std::map<std::string, int, std::lessstd::string, std::allocator<std::pair<std::string const, int> > >::operator[](std::string const&) ()
from /afs/

Traceback (most recent call last):
File “”, line 12, in
print t.MAP_NAME[“KEY_NAME”]
SystemError: problem in C++; program state has been reset

Anyone can help?


the words “AANT” make me think that this is an ATLAS “Athena Aware NTuple” and hence filled with dictionaries that were from Reflex. When reading in a standalone ROOT session (can’t say that for sure, since your traceback does seem to suggest a full ATLAS setup?), if the dictionary for the map is available, it will be a Cint one. Don’t think that’ll work.

Instead of relying on the auto-selection, could you create a map object and use SetBranchAddress and make sure the same type of dictionary is loaded when reading as when creating?

If that doesn’t work out, please post the file you’re reading so that I may reproduce the problem.


Hi Wim,

I was testing this using the default root setup after an ATLAS setup. But when I tried it using a standalone root setup, it worked fine.

Thanks for your help.