Typedefed template class to be used in cint

Hi, I want to use the following construct in CINT prompt
namespace1::namespace2::classname::type where type is a public typedefed template class MyIdCollection as follows

typedef Int_t MyId
typedef std::set MyIdCollection;

My linkdef.h that builds the library has at the moment

#ifdef MAKECINT

#pragma link off all class;
#pragma link off all function;
#pragma link off all global;
#pragma link off all typedef;

#pragma link C++ namespace namespace1::namespace2;
#pragma link C++ nestedclass;
#pragma link C++ nestedtypedef;

#pragma link C++ nestedtypedef namespace1::namespace2::classname::MyIdCollection;

but when I load it does not seem to recognize the type by tab completion or ctor eith wither typedef or nestedtypedef. What would be the correct syntax? Thanks,
filimon

Hi,

You would need to use something like:[code]#ifdef MAKECINT
#pragma link C++ nestedclass;
#pragma link C++ nestedtypedef;

#pragma link C++ namespace namespace1::namespace2;
#pragma link C++ class amespace1::namespace2::classname+;
#pragma link C++ typedef namespace1::namespace2::classname::MyIdCollection;
#pragma link C++ class std::set+;
#endif[/code]

Cheers,
Philippe.

Edit: Fixed spelling of std::set

Well, I got a complaint about missing std::set (I assume you meant std and not set but I tried both). Anyway, this is now bypassed because the code is now refactored a lot, but I have another question. I try to write a tree, initialized after opening a file but I get this msg
Error in TROOT::WriteTObject: The current directory (Rint) is not associated with a file. The object (testsim) has not been written.

(testsim is the tree name). fFile cd() before the write function call does not seem to help. Any ideas on what could be wrong? Please note that this application loads a macro with gROOT->LoadMacro. Could this be related?
filimon

[quote]Well, I got a complaint about missing std::set (I assume you meant std and not set but I tried both)[/quote]Did you have a #include (yes I meant std::set :slight_smile:).

[quote](testsim is the tree name). fFile cd() before the write function call does not seem to help[/quote]Either the fFile is deleted or something else does a cd to TRint before you create the TTree object and/or you ought to replace tree->Write() with tree->GetCurrentFile()->Write().

Cheers,
Philippe.

Well, I have it somewhere, so it should be included also in linkdef.h then? I assumed this but as I said I stopped trying because I refactored the code and in fact got rid of a global which bothered me a lot :wink: By the way, the way that CINT handles templates and/or STL is a little obscure to me. Is there a public presentation or sth or does the ROOT doc include it everything that is to be known? (Haven’t looked there for years). cheers,
filimon

OK, now everything works perfectly in the application except a small problem. As I said I do a gROOT->LoadMacro(“file.C”) and subsequent gROOT->ProcessLine(“some_func_in_file.C”). I would like to have an output .root file. If I put it in the ctor of the main application that does the gROOT->ProcessLine calls (ie the TFile gets initialized before), when the ctor of the class that does everything (it is a singleton) finishes I end up in the root prompt (this is inteted so as to use the root prompt afterwards for calling member functions of the singleton) and then pressing .q brings out the dump at the end of the msg. If 1. I disable the TFile ctor or 2. move it (with a necessary change to free store allocation instead of the stack ie new TFile) or 3. I issue a delete gFile at the root prompt before .q I do not get this and root terminates properly. I suspect this is because somehow there is an involvement of the file associated with the macro loaded by gROOT->LoadMacro but do not know the internals. Any hint on this? cheers,
filimon

root [2] .q
*** glibc detected *** /opt/root/v5-26-00b/bin/root.exe: free(): invalid pointer: 0x08de54f0 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0x3749ff1]
/lib/tls/i686/cmov/libc.so.6[0x374b6f2]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0x374e7cd]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xc476f1]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN8TStorage13ObjectDeallocEPv+0x73)[0x3b1493]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN7TObjectdlEPv+0x38)[0x38f388]
/opt/root/v5-26-00b/lib/libRIO.so(_ZN5TFileD0Ev+0x212)[0x22c1002]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN11TCollection14GarbageCollectEP7TObject+0x7a)[0x3f7c2a]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN5TList6DeleteEPKc+0x110)[0x3feb50]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN11TUnixSystem4ExitEib+0x46)[0x44f616]
/opt/root/v5-26-00b/lib/libRint.so.5.26(_ZN5TRint9TerminateEi+0xa8)[0x11cd38]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN12TApplication11ProcessLineEPKcbPi+0x352)[0x35fa62]
/opt/root/v5-26-00b/lib/libRint.so.5.26(_ZN5TRint15HandleTermInputEv+0x1e9)[0x11e939]
/opt/root/v5-26-00b/lib/libRint.so.5.26(_ZN17TTermInputHandler6NotifyEv+0x25)[0x11cad5]
/opt/root/v5-26-00b/lib/libRint.so.5.26(_ZN17TTermInputHandler10ReadNotifyEv+0x14)[0x11f4b4]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN11TUnixSystem16CheckDescriptorsEv+0x177)[0x453797]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN11TUnixSystem16DispatchOneEventEb+0xf5)[0x453da5]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN7TSystem9InnerLoopEv+0x21)[0x3c3261]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN7TSystem3RunEv+0x89)[0x3c6059]
/opt/root/v5-26-00b/lib/libCore.so.5.26(_ZN12TApplication3RunEb+0x37)[0x35da67]
/opt/root/v5-26-00b/lib/libRint.so.5.26(_ZN5TRint3RunEb+0x1e1)[0x11ed41]
/opt/root/v5-26-00b/bin/root.exe(main+0x6f)[0x8048edf]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x36f5b56]
/opt/root/v5-26-00b/bin/root.exe[0x8048da1]
======= Memory map: ========
00110000-0013d000 r-xp 00000000 08:06 428174 /opt/root/v5-26-00b/lib/libRint.so.5.26
0013d000-0013e000 r–p 0002d000 08:06 428174 /opt/root/v5-26-00b/lib/libRint.so.5.26
0013e000-0013f000 rw-p 0002e000 08:06 428174 /opt/root/v5-26-00b/lib/libRint.so.5.26
0013f000-00141000 r-xp 00000000 08:06 1076 /lib/tls/i686/cmov/libdl-2.10.1.so
00141000-00142000 r–p 00001000 08:06 1076 /lib/tls/i686/cmov/libdl-2.10.1.so
00142000-00143000 rw-p 00002000 08:06 1076 /lib/tls/i686/cmov/libdl-2.10.1.so
00143000-00167000 r-xp 00000000 08:06 1078 /lib/tls/i686/cmov/libm-2.10.1.so
00167000-00168000 r–p 00023000 08:06 1078 /lib/tls/i686/cmov/libm-2.10.1.so
00168000-00169000 rw-p 00024000 08:06 1078 /lib/tls/i686/cmov/libm-2.10.1.so
00169000-00185000 r-xp 00000000 08:06 5821 /lib/libgcc_s.so.1
00185000-00186000 r–p 0001b000 08:06 5821 /lib/libgcc_s.so.1
00186000-00187000 rw-p 0001c000 08:06 5821 /lib/libgcc_s.so.1
00187000-0019c000 r-xp 00000000 08:06 1128 /lib/tls/i686/cmov/libpthread-2.10.1.so
0019c000-0019d000 r–p 00014000 08:06 1128 /lib/tls/i686/cmov/libpthread-2.10.1.so
0019d000-0019e000 rw-p 00015000 08:06 1128 /lib/tls/i686/cmov/libpthread-2.10.1.so
0019e000-001a0000 rw-p 00000000 00:00 0
001a0000-001a9000 r-xp 00000000 08:06 1048 /lib/tls/i686/cmov/libcrypt-2.10.1.so
001a9000-001aa000 r–p 00008000 08:06 1048 /lib/tls/i686/cmov/libcrypt-2.10.1.so
001aa000-001ab000 rw-p 00009000 08:06 1048 /lib/tls/i686/cmov/libcrypt-2.10.1.so
001ab000-001d2000 rw-p 00000000 00:00 0
001d2000-001d8000 r-xp 00000000 08:06 1087 /lib/tls/i686/cmov/libnss_compat-2.10.1.so
001d8000-001d9000 r–p 00005000 08:06 1087 /lib/tls/i686/cmov/libnss_compat-2.10.1.so
001d9000-001da000 rw-p 00006000 08:06 1087 /lib/tls/i686/cmov/libnss_compat-2.10.1.so
001da000-001ed000 r-xp 00000000 08:06 1085 /lib/tls/i686/cmov/libnsl-2.10.1.so
001ed000-001ee000 r–p 00012000 08:06 1085 /lib/tls/i686/cmov/libnsl-2.10.1.so
001ee000-001ef000 rw-p 00013000 08:06 1085 /lib/tls/i686/cmov/libnsl-2.10.1.so
001ef000-001f1000 rw-p 00000000 00:00 0
001f1000-001fa000 r-xp 00000000 08:06 1101 /lib/tls/i686/cmov/libnss_nis-2.10.1.so
001fa000-001fb000 r–p 00008000 08:06 1101 /lib/tls/i686/cmov/libnss_nis-2.10.1.so
001fb000-001fc000 rw-p 00009000 08:06 1101 /lib/tls/i686/cmov/libnss_nis-2.10.1.so
001fc000-00206000 r-xp 00000000 08:06 1091 /lib/tls/i686/cmov/libnss_files-2.10.1.so
00206000-00207000 r–p 00009000 08:06 1091 /lib/tls/i686/cmov/libnss_files-2.10.1.so
00207000-00208000 rw-p 0000a000 08:06 1091 /lib/tls/i686/cmov/libnss_files-2.10.1.so
00208000-0020a000 r-xp 00000000 08:06 5525 /usr/lib/libXau.so.6.0.0
0020a000-0020b000 r–p 00001000 08:06 5525 /usr/lib/libXau.so.6.0.0
0020b000-0020c000 rw-p 00002000 08:06 5525 /usr/lib/libXau.so.6.0.0
0020c000-00210000 r-xp 00000000 08:06 5536 /usr/lib/libXdmcp.so.6.0.0
00210000-00211000 rw-p 00003000 08:06 5536 /usr/lib/libXdmcp.so.6.0.0
00211000-0022c000 r-xp 00000000 08:06 65 /lib/ld-2.10.1.so
0022c000-0022d000 r–p 0001a000 08:06 65 /lib/ld-2.10.1.so
0022d000-0022e000 rw-p 0001b000 08:06 65 /lib/ld-2.10.1.so
0022e000-0091d000 r-xp 00000000 08:06 426339 /opt/root/v5-26-00b/lib/libCore.so.5.26
0091d000-00931000 r–p 006ef000 08:06 426339 /opt/root/v5-26-00b/lib/libCore.so.5.26
00931000-0093b000 rw-p 00703000 08:06 426339 /opt/root/v5-26-00b/lib/libCore.so.5.26
0093b000-009b1000 rw-p 00000000 00:00 0
009b1000-00b84000 r-xp 00000000 08:06 426538 /opt/root/v5-26-00b/lib/libMathCore.so.5.26
00b84000-00b85000 —p 001d3000 08:06 426538 /opt/root/v5-26-00b/lib/libMathCore.so.5.26
00b85000-00b89000 r–p 001d3000 08:06 426538 /opt/root/v5-26-00b/lib/libMathCore.so.5.26
00b89000-00b8c000 rw-p 001d7000 08:06 426538 /opt/root/v5-26-00b/lib/libMathCore.so.5.26
00b8c000-00b8f000 rw-p 00000000 00:00 0
00b8f000-00c75000 r-xp 00000000 08:06 3342 /usr/lib/libstdc++.so.6.0.13
00c75000-00c79000 r–p 000e6000 08:06 3342 /usr/lib/libstdc++.so.6.0.13
00c79000-00c7a000 rw-p 000ea000 08:06 3342 /usr/lib/libstdc++.so.6.0.13
00c7a000-00c81000 rw-p 00000000 00:00 0
00c81000-00c8f000 r-xp 00000000 08:06 5538 /usr/lib/libXext.so.6.4.0
00c8f000-00c90000 r–p 0000d000 08:06 5538 /usr/lib/libXext.so.6.4.0
00c90000-00c91000 rw-p 0000e000 08:06 5538 /usr/lib/libXext.so.6.4.0
00c92000-00c93000 r-xp 00000000 00:00 0 [vdso]
00c93000-00ed7000 r-xp 00000000 08:06 425829 /opt/root/v5-26-00b/lib/libCint.so.5.26
00ed7000-00ed9000 r–p 00243000 08:06 425829 /opt/root/v5-26-00b/lib/libCint.so.5.26
00ed9000-00edc000 rw-p 00245000 08:06 425829 /opt/root/v5-26-00b/lib/libCint.so.5.26
00edc000-01277000 rw-p 00000000 00:00 0
01277000-0159d000 r-xp 00000000 08:06 428313 /opt/root/v5-26-00b/lib/libGeom.so.5.26
0159d000-015a7000 r–p 00325000 08:06 428313 /opt/root/v5-26-00b/lib/libGeom.so.5.26
015a7000-015ab000 rw-p 0032f000 08:06 428313 /opt/root/v5-26-00b/lib/libGeom.so.5.26
015ab000-015b0000 rw-p 00000000 00:00 0
015b0000-019a4000 r-xp 00000000 08:06 426713 /opt/root/v5-26-00b/lib/libHist.so.5.26
019a4000-019b3000 r–p 003f4000 08:06 426713 /opt/root/v5-26-00b/lib/libHist.so.5.26
019b3000-019b7000 rw-p 00403000 08:06 426713 /opt/root/v5-26-00b/lib/libHist.so.5.26
019b7000-019ba000 rw-p 00000000 00:00 0
019ba000-01a8c000 r-xp 00000000 08:06 427718 /opt/root/v5-26-00b/lib/libGpad.so.5.26
01a8c000-01a91000 r–p 000d1000 08:06 427718 /opt/root/v5-26-00b/lib/libGpad.so.5.26
01a91000-01a92000 rw-p 000d6000 08:06 427718 /opt/root/v5-26-00b/lib/libGpad.so.5.26
01a92000-01a94000 rw-p 00000000 00:00 0
01a94000-01af4000 r-xp 00000000 08:06 428218 /opt/root/v5-26-00b/lib/libEG.so.5.26
01af4000-01af6000 r–p 0005f000 08:06 428218 /opt/root/v5-26-00b/lib/libEG.so.5.26
01af6000-01af7000 rw-p 00061000 08:06 428218 /opt/root/v5-26-00b/lib/libEG.so.5.26
01af7000-01b55000 rw-p 00000000 00:00 0
01b55000-01b8b000 r-xp 00000000 08:06 428632 /opt/root/v5-26filimon@FILIMON-LNV:~$

Hi,

It is hard to tell what the problem is without seeing the actual code. One can probably track down the memory problem by running valgrind (and using root.exe). It is usually best to create the TFile object via new or even better via TFile::Open (which works for all types of access protocol instead of just local files).

Cheers,
Philippe.

Hi, yes indeed new TFile helped even when keeping the allocation in its original place, because the destructor is not automatically called at the end (singleton/global destructors call) :wink:.