Re: Templated member functions in root.

From: Brett Viren <bv_at_bnl.gov>
Date: Wed, 16 Feb 2005 12:44:21 -0500


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>((const 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 - 18:44:48 MET

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