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


#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,


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+;


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?

[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().


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,

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,

root [2] .q
*** glibc detected *** /opt/root/v5-26-00b/bin/root.exe: free(): invalid pointer: 0x08de54f0 ***
======= Backtrace: =========
======= 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:~$


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).


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:.