the dict that you print is the local set of data on the instance, which is empty if nothing has been filled in there: it only contains data members added in python, not any in C++, as those are private (and public data members are available through properties, which you’ll find in the dict of the class, not on the instance).
If the iterator and pair have a CINT dictionary available to them, then you should be able to iterate over the entries in the map:for key, value in myreturn:
print key, value
Otherwise, you can check the size (myreturn.size()) and access the members (myreturn[“amp”]) like in C++.
like I said, the iterator and pair need to have their CINT dictionaries for the iteration to work. Changing ROOT versions isn’t going to make a difference if those are missing. As recommended above, start with using direct access and size() to see whether the container is empty or not. Then, you can try begin() and end() and you’ll quickly see if the dicts are there (since these are custom classes, I presume not, unless you explicitly requested them when building the dictionary).
If you want a simple case for testing, use std::map<int, int> as that type is available from the pre-built CINT dlls, and thus works “out-of-the-box.”
Hi Wim.
Okay, I have it working now (indeed, I needed to generate a dictionary with LinkDef.h and include a class map<string,KResult>… before i was generating my dictionary without using a LinkDef.h file and just doing rootcint -f mydict.cxx -c myheader.h+ myheader2.h+… which works fine for many cases.)
in the linkDef file I had to add instructions for maps
but now, I’m stuck again…
My method that returns a map<string,int> is iterable, but clearly the method that returns map<string,KResult> is not, but it does contain data. (Also, there was this RuntimeWarning regarding the pair<string, KResult>. I managed to get this message to go away when I added “#pragma link C++ class std::pair<std::string, KResult>+;” to my LinkDef.h file, but it doesn’t appear to change the behavior of the returned object.
I put the “pragma class link map” lines both at the beginning of the LinkDef file and at the end of the LinkDef file, but the results appeared to be the same.
#pragma link C++ class std::map<std::string, KResult>+;
#pragma link C++ class std::pair<std::string, KResult>+;
#pragma link C++ class std::map<std::string, KResult>::*;
#pragma link C++ operators std::map<std::string, KResult>::iterator;
#pragma link C++ operators std::map<std::string, KResult>::const_iterator;
#pragma link C++ operators std::map<std::string, KResult>::reverse_iterator;