I try to fill a TMap in ROOT using int’s as key and TVector as values. However, I’m unable to do so, since the arguments to TMap::Add cannot be converted (I guess due to TObject* parameters). What I do is something like this:
mEvents = ROOT.TMap()
someArray = array('f',someList)
myInt = some int
vec = ROOT.TVector(len(someArrary),someArray)
I already tried switching to ROOT primitive types, i.e. ROOT.Int/Double/TString and also tried ctypes, but non of them worked. Is there any way to do this within python?
nothing to do with python: the interface requires a TObject*, so nothing else will pass. Think about it: if an integer is passed where a TObject* is expected, then the next step will most likely be a crash on the C++ side, as the int will not point to a valid address.
The list of alternatives that you put there has TString, but as you found, that, too, does not derive from TObject. Use TObjString instead.
You can also simply bind an std::map<int, TVector>, which will work. Or, if the integers are consecutive, use an std::vector or some TCollection. If the integers have no meaning other than bookkeeping or ordering, then a THashList may work for you.
Unfortunately the dictionart generation crashes due to errors which I don’t understand:
/amnt/remote/pkthafc.home/morgenst/workarea/2011/HiggsAnalysis/HadHad/macros/AutoDict_map_int_vector_int____cxx_ACLiC_dict.o: In function G__cpp_setup_tagtableAutoDict_map_int_vector_int____cxx_ACLiC_dict': /amnt/remote/pkthafc.home/morgenst/workarea/2011/HiggsAnalysis/HadHad/macros/AutoDict_map_int_vector_int____cxx_ACLiC_dict.cxx:1294: undefined reference toG__get_linked_tagnum_fwd’
**this goes on for a while
I’m even unable to generate the dictionary for simpler object, such as std::vector<double*>. Do you know what I’m doing wrong?
that linking problem is an open bug in gSystem: https://savannah.cern.ch/bugs/?95188. It can be worked around using: gSystem.SetMakeSharedLib(gSystem.GetMakeSharedLib().replace('-Wl,--as-needed', ''))