Problem in root with map

I am trying to use map in root.

ROOT is having problems creating a pointer to my map.

The map is created at line 23 in the attached code:

map<char, int> m;

The pointer setup is at line 41:

map<char, int>::iterator iterp;

The root output is as below. ROOT is happy to execute functions directly on my map object, m - but crashes when the pointer code is used. Suggestions much appreciated. Thanks, Dave.

********************* >>>>>>>>>>>>>>

The ROOT version in use is:
/cvmfs/cms.cern.ch/slc6_amd64_gcc472/lcg/root/5.32.00

End of messages from /afs/cern.ch/user/d/davec/rootlogon.C:

root [0] .L map-test.C
root [1] main()
map m is empty - fill it !
map m is not empty now
Number of map entries = 26
Error: Symbol iterp is not defined in current scope map-test.C:47:
Error: Failed to evaluate iterp->second
Its ASCII value is (class G__CINT_ENDL)10754800
*** Interpreter error recovered ***

map-test.C (1.23 KB)

The easiest would be to:

  1. rename “main” into something else, e.g. “mtest”,
  2. use ACLiC to precompile it:
    root [0] .L map-test.C++
    root [1] mtest();

BTW. If you switch to ROOT 6, you will not need to “precompile” it.

Many thanks - changing main to mtest worked perfectly!

Q1) Why was “main” giving problems?

Q2) If I am in root, compile, then run, but then change my code, is there a way to recompile without having to exit root and go in again ??

Yours gratefully!

Dave Cockerill

A1) See “Wikipedia -> Entry point -> C and C++”.

A2) You can simply try to execute “.L map-test.C++” again. In ROOT 5 you may get a warning that some iterator is already in TClassTable but there should be no such warning in ROOT 6 (neither when used via ACLiC nor when used as “interpreted”).

Note: if you rename your file into “mtest.C”, you should be able to (re)load and execute it using simply “.x mtest.C++” (in ROOT 6, you can also try “.x mtest.C”).