TMap: Segmentation error?

Hi,
I got the following errors from using TMap in the ROOT interactive mod,

Enclose multiple statements between { }.
root [0] TMap* aMap = new TMap();
root [1] TString* name = new TString(“name”);
root [2] Int_t* x= new Int_t(0)
root [3] aMap->Add((TObject*)name,(TObject*)x)

*** Break *** segmentation violation
Attaching to program: /proc/12666/exe, process 12666
[Thread debugging using libthread_db enabled]
[New Thread 0x7f96c2658700 (LWP 12666)]
0x00007f96bf9c78f5 in waitpid () from /lib/libc.so.6
error detected on stdin
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/12666/exe, process 12666

Many thanks for your helps.

regards,

gma

[quote=“gma”]Hi,
I got the following errors from using TMap in the ROOT interactive mod,

Enclose multiple statements between { }.
root [0] TMap* aMap = new TMap();
root [1] TString* name = new TString(“name”);
root [2] Int_t* x= new Int_t(0)
root [3] aMap->Add((TObject*)name,(TObject*)x)

*** Break *** segmentation violation
Attaching to program: /proc/12666/exe, process 12666
[Thread debugging using libthread_db enabled]
[New Thread 0x7f96c2658700 (LWP 12666)]
0x00007f96bf9c78f5 in waitpid () from /lib/libc.so.6
error detected on stdin
The program is running. Quit anyway (and detach it)? (y or n) [answered Y; input not from terminal]
Detaching from program: /proc/12666/exe, process 12666

Many thanks for your helps.

regards,

gma[/quote]
I don’t see your tracelog, but I suspect the crash happens because Int_t isn’t a TObject child.
This is one disadvantage of ROOT containers. They can store only TObject objects.

BTW, you can wrap Int_t in a class inherited from TObject, then it should work.

Anar,
Thank you very much. Yes, you are right that I have to save objects derived from TObject. I thought all the types in ROOT are derived from TObject. TString is also not a TObject type. I have to use TObjString.

regards,

gma

Hi,
A related question is whether ROOT save the following class?

class A: public TObject{
private:
std::map amap<string, float>;

}

Thanks.

regards,

gma

Hi,

“save” as in save to a ROOT file? Sure it can do it, as long as you provide a dictionary for it (and correct your member definition of “amap” which has a bug :-). See the users guide. You don’t even need to derive from TObject to be able to store a class.

Cheers, Axel.

Hi, Axel,
:blush: Yes, I am thinking about saving it into a ROOT file. Interesting, we can use rootcint to generate the dictionary. What are the limitations of rootcint? I am thinking about transforming a small libraries (30 files) into ROOT classes. Thanks.

regards,

gma

Hi,

See the User’s guide and the CINT documentation.

Cheers,
Philippe.

PS. I.e. the limitation are minimal and in most case you do not even have to modify your code at all.

Thanks, Phillipe. I will experiment more about this.

regards,

gma