Re: [CINT] FW: [ROOT] CINT and STL vector of private class

From: Masaharu Goto (MXJ02154@nifty.ne.jp)
Date: Thu Apr 17 2003 - 13:18:25 MEST


Hello Xiaorong, 

I am happy to answer your question.

This is a Cint limitation. You have STL container classes
vector<Dimuon> and vector<Particle> interpreted.  they
work to some extent, but not perfect. You'll find this kind
of problem as you go on.  Solution is to precompile
vector<Dimuon> and vector<Particle> in libDimuon.so
using  #pragma link statement.


#include <vector>

class Particle { .... };
class Dimuon { .... };

#ifdef __MAKECINT__
#pragma link C++ class vector<Dimuon>;
#pragma link C++ class vector<Particle>;
#endif

Then, things will be fine.

Thank you
Masa Goto




----- Original Message ----- 
From: "Philippe Canal" <pcanal@fnal.gov>
To: "Cint" <cint@pcroot.cern.ch>
Sent: Thursday, April 17, 2003 12:06 AM
Subject: [CINT] FW: [ROOT] CINT and STL vector of private class


> 
> 
> -----Original Message-----
> From: owner-roottalk@pcroot.cern.ch
> [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Xiaorong Wang
> Sent: Tuesday, April 15, 2003 11:21 PM
> To: 'Rene Brun'
> Cc: 'Root Mailinglist'
> Subject: [ROOT] CINT and STL vector of private class
> 
> 
> Dear Root expert,
> 
> I need your help on this issue. I am using ROOT 3.01/05, linux 7.3.
> Thanks for your time.
> 
> I created two private class Paricle and Dimuon(two particles build one
> Dimuon), and use 
> 
> rootcint -f $*Dict.C -c $(CINTFLAGS) $(DEFS) $(INCLUDES) $*.hh
> 
> to generate the root dictionary and library file libDimuon.so.
> 
> I load this library and use STL vector in root macro file
> 
> *********************
> #include <iostream>
> #include <fstream>
> #include <stdio.h>
> #include <vector>
> 
> class Dimuon;
> class Particle;
> 
> void main()
> {
>   gSystem->Load("install/lib/libDimuon.so");
>   vector<Dimuon> DimuVec;
>   vector<Particle> ParVec;
>   
>   int q1 = -1;
>   int q2 = 1;
>   float E1=3.0;
>   float Px1=1.0;
>   float Py1=1.0;
>   float Pz1=1.0;
>   float E2= 5.0;
>   float Px2=1.4;
>   float Py2=1.2;
>   float Pz2=1.0;
>   
>   Particle *muon1 = new Particle(q1, E1,Px1,Py1,Pz1);
>   Particle *muon2 = new Particle(q2, E2,Px2,Py2,Pz2);
>     
>   ParVec.push_back(*muon1);
>   ParVec.push_back(*muon2);
>   
>   Dimuon *jpsi = new Dimuon(muon1, muon2);
>   DimuVec.push_back(*jpsi);
>   
>   delete muon1;
>   delete muon2;
>   delete jpsi;
>   
>   vector<Particle>::iterator mu1;
>   for (mu1 = ParVec.begin(); mu1 < ParVec.end(); ++mu1){
>     cout << "I am here particle iterator loop " << endl;
>   }  
> 
>   vector<Dimuon>::iterator dimu;
>   for (dimu = DimuVec.begin(); dimu < DimuVec.end(); ++dimu){
>     cout << "I am here Dimuon iterator loop " << endl;
>   }   
>   cout << "DimuVec size= " << DimuVec.size() << endl;
>   cout << "ParVec size= " << ParVec.size() << endl;
> 
> }
> 
> ********************************************
> 
> when I run this marco, I got correct output, at the end of the root run,
> it crash by segmentation violation. 
> 
> ***************
> root [0] .L try.C
> root [1] main()  
> I am here particle iterator loop 
> I am here particle iterator loop 
> I am here Dimuon iterator loop 
> DimuVec size= 1
> ParVec size= 2
> 
>  *** Break *** segmentation violation
> Root > Function main() busy flag cleared
> **************** 
> 
> when I trace this root file: I got
> 
> *************
> void destroy(Dimuon* first, Dimuon* last) {
>     while (first != last) destroy(first++);
> }
> !!! Reading template destroy
> # 120 "algobase.h"
> 120  
> 121  void destroy(Dimuon* first, Dimuon* last) {
> 122      while (first != last) destroy(first++);
> 123  }
> !!!Complete instantiating template destroy
> 
>  *** Break *** segmentation violation
> Root > !!!Destroy static member object 0x883f838
> vector<Particle>::~TRint() !!!Destroy static member object 0x8822e58
> vector<Dimuon>::~TRint() Function main() busy flag cleared
> **************
> 
> PS: I can do this correctly using standard C++ without CINT, is this
> CINT problem or I did something wrong.
> 
> Thanks,
> Xiaorong
> 
> 
> 



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET