Explicit Template Instantiation for CINT

Hi, I have two similar cases of templated code that I want to use in CINT after compiling with ACLiC using “+”. The first case I was able to make work, but the second one is more difficult.

Case 1: regular class with templated static methods. I have a class MySpline with methods ::Poly where N is an unsigned integer. I wrote a macro that defines standalone functions PolyN (with N = 1 through 6) that take the same arguments and forwards them as MySpline::Poly. In this way, the template is explicitly instantiated and I can use the PolyN functions from CINT, as long as N is in my list of explicit instantiations.

Case 2: templated class with two integer parameters, methods are non-templated. This class is PieceWise<N_knots,N> where both parameters are unsigned ints. I would like to make a list of explicit instantiations using the two parameters like PieceWise1_1, PieceWise1_2, PieceWise2_2, etc. My values will not need to grow too much, so the combinatorics are not a problem (e.g. I might have 20 such instantiations). Unfortunately I am unable to get this to work, often ACLiC gives a segmentation fault. I have tried several things:

template class MySpline::PieceWise<1,3>;

This gives a segmentation fault when compiling with “+”. The message is “Fatal: sizeof(::MySpline::PieceWise<1,3>) == sizeof(::ROOT::Shadow::MySpline::PieceWiselE1cO3gR) violated at line 153 of `/Users/jfcaron/Projects/Proto2BeamTest2/code_test/MySpline_C_ACLiC_dict.cxx’” and a stack trace.

typedef MySpline::PieceWise<1,3> PieceWise1_3; with the same crash & message.

class PieceWise1_3 : public MySpline::PieceWise<1,3> { using MySpline::PieceWise<1,3>::PieceWise; }; same crash but the message is now about a different line of the dict.cxx file.

class PieceWise1_3 { PieceWise1_3(const double * const knots) : pw(knots){}; MySpline::PieceWise<1,3> pw; }; same crash, but yet another line of the dict.cxx file.

I have determined that there is probably a single thing I am doing wrong that is giving that seg fault. Maybe if that one thing was fixed then any of my techniques would work, and I could write an ugly macro that stamps out several such classes.

I have attached the code MySpline.C+ that contains case 1 and case 2. Hopefully someone can help.

Jean-François
MySpline.C (9.63 KB)

I figured I should attach that _dict.cxx file that is mentioned in the error message. This one is for the first attempt using “template class MySpline::PieceWise<1,3>”, the error occurs on line 153. Here’s a segment of the code around that line:

   // Function generating the singleton type initializer
   static TGenericClassInfo *GenerateInitInstanceLocal(const ::MySpline::PieceWise<1,3>*)
   {
      // Make sure the shadow class has the right sizeof
      R__ASSERT(sizeof(::MySpline::PieceWise<1,3>) ==sizeof(::ROOT::Shadow::MySpline::PieceWiselE1cO3gR));
      ::MySpline::PieceWise<1,3> *ptr = 0;

The crash occurs inside the sizeof in the assert, it’s not the assert itself firing, afaik.

Jean-François
MySpline_C_ACLiC_dict.cxx.txt (42.8 KB)