RE: Templated member functions in root.

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Wed, 16 Feb 2005 13:25:25 -0600


Hi Brett,

There was a bug in CINT (the fix will be uploaded shortly in the CVS repository),
which allowed CINT to only see the first declared method of the correct name when the template argument is explicit set.

Alternatively you can remove the problem by adding an argument of type THType* to you Book method (so that you can use a signature which does not have an explicit template parameter).

Cheers,
Philippe.

-----Original Message-----
From: Brett Viren [mailto:bviren_at_minos.phy.bnl.gov] On Behalf Of Brett Viren Sent: Wednesday, February 16, 2005 11:44 AM To: Philippe Canal
Cc: roottalk_at_pcroot.cern.ch
Subject: Re: [ROOT] Templated member functions in root.

Hi Philippe,

Philippe Canal <pcanal_at_fnal.gov> writes:

> #pragma link C++ function HistMan::Book<TH1D>(const char*, ....etc... );

Thanks, this is an adequate work around but leads to a new problem. I actually have two Book<> methods to handle the different interfaces between 1D and 2D histograms:

    template<class THType>
    THType* Book(const char* name, const char* title,

                 int nbinsx, Axis_t xmin, Axis_t xmax,
                 const char* path=".") {
        TH1* h = Adopt(path, new THType(name,title,nbinsx,xmin,xmax));
        return dynamic_cast<THType*>(h);
    }
        
        

    template<class THType>
    THType* Book(const char* name, const char* title,

                 int nbinsx, Axis_t xmin, Axis_t xmax,
                 int nbinsy, Axis_t ymin, Axis_t ymax,
                 const char* path=".") {
        TH1* h= Adopt(path, new THType(name,title,nbinsx,xmin,xmax,
                                       nbinsy,ymin,ymax));
        return dynamic_cast<THType*>(h);
    }

In the LinkDef.h I try lines like these:

#pragma link C++ function HistMan::Book<TH1D>(const char*, const char*, int, Axis_t, Axis_t, const char*);
#pragma link C++ function HistMan::Book<TH2D>(const char*, const char*, int, Axis_t, Axis_t, int, Axis_t, Axis_t,const char*);

The first alone works fine however adding the second leads to these build errors:



bviren_at_coop:HistMan> make
Generating HistManCint.cc dictionary...
Warning: #pragma link, function Book<TH2D>(const char*,const char*,int,Axis_t,Axis_t,int,Axis_t,Axis_t,const char*) not found FILE:LinkDef.h LINE:16
<**special depend**> HistManCint.cc
<**depend**> HistManCint.ccd
<**compiling**> HistManCint.cc

HistMan.h: In member function `THType* HistMan::Book(const char*, const char*,

   int, double, double, const char*) [with THType = TH2D]': /home/bviren/work/minos/bd-devel/tmp/Linux2.6-GCC/HistMan/libHistMan-shared/ HistManCint.cc:342: instantiated from here HistMan.h:104: error: no matching function for call to `TH2D::TH2D(const

   char*&, const char*&, int&, Axis_t&, Axis_t&)'


Checking the rootcint generated file I see that it is calling the 1D version with the TH2D template argument:



static int G__HistManCint_195_6_1(G__value *result7,G__CONST char *funcname,struct G__param *libp,int hash) {

   switch(libp->paran) {
   case 6:  

G__letint(result7,85,(long)((HistMan*)(G__getstructoffset()))->Book<TH2D>((c onst char*)G__int(libp->para[0]),(const char*)G__int(libp->para[1]) ,(int)G__int(libp->para[2]),(Axis_t)G__double(libp->para[3]) ,(Axis_t)G__double(libp->para[4]),(const char*)G__int(libp->para[5])));


Any suggestion?

-Brett. Received on Wed Feb 16 2005 - 20:29:33 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:05 MET