Cling fails when std::pow and ROOT::Math::IntegratorMultiDim are present

Dear all,
I’m facing issues with cling when running this C++ code:

#include <iostream>
#include <stdio.h>
#include <complex.h>
#include "TMath.h"

Double_t mw = 79.82436 ;
Double_t mz = 91.1876 ;
Double_t sW2 = 1.0- std::pow(mw/mz,2);
//Double_t sW2 = 1.0;

double get_const(){
	double res = sW2;
	return res;
};

class LinearIntegrand {
	public:
	Double_t sqs;
	LinearIntegrand( Double_t input_sqs){
		sqs = input_sqs;
	}

	double operator()(const Double_t *x) const{
	return 0.5;
	}
	double operator()(const Double_t t0, const Double_t t1, const Double_t f1, const Double_t t2, const Double_t f2){
	const Double_t x[5] = {t0,t1,f1,t2,f2};
	return operator()( x );
	}
};

array<Double_t,2> integral(const LinearIntegrand &integrand){
    const Double_t ini[5] = {0.,0.,-3.14,0.,-3.14};
    const Double_t fin[5] = {3.14,3.14, 3.14,3.14, 3.14};
    array<Double_t,2> res;   
    ROOT::Math::Functor func( integrand, 5 );
    ROOT::Math::IntegratorMultiDim inte( func ); //, ROOT::Math::IntegrationMultiDim::kADAPTIVE );
    res[0] = inte.Integral(ini,fin);
    res[1] = inte.Error();
	// res[0]=0.0;
	// res[1]=0.0;
    return res;
};

That I’m trying to run with the following Jupyter code:

import ROOT
# load cpp code
with open('minexample.cpp','r') as f:
    ROOT.gInterpreter.Declare(f.read())
    f.close()
print(ROOT.get_const())

This is just a minimal version to show the problem that appears in a much larger code, originally written to work with ROOT 6.08.

If one runs the code as attached, it fails with the following message:

-1.0
cling JIT session error: Failed to materialize symbols: { (main, { _ZN4ROOT4Math18IntegratorMultiDim16CreateIntegratorENS0_19IntegrationMultiDim4TypeEddj }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _ZNSt8functionIFdPKdEEC2ERKS3_, _ZTIN4ROOT4Math18IntegratorMultiDimE, _ZNSt9_Any_data9_M_accessIP15LinearIntegrandEERT_v, $.cling-module-297.__inits.0, _Z8integralRK15LinearIntegrand, _ZN4ROOT4Math26IBaseFunctionMultiDimTemplIdEC2ERKS2_, _ZNSt17_Function_handlerIFdPKdE15LinearIntegrandE9_M_invokeERKSt9_Any_dataOS1_, sW2, _ZNSt10unique_ptrIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EED2Ev, _ZN4ROOT4Math18IntegratorMultiDimC1ERKNS0_26IBaseFunctionMultiDimTemplIdEENS0_19IntegrationMultiDim4TypeEddj, _ZNSt5tupleIJPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEEC1IS4_S6_Lb1EEEv, _ZN4ROOT4Math7FunctorD0Ev, _ZN4ROOT4Math26IBaseFunctionMultiDimTemplIdED1Ev, _ZN4ROOT4Math7FunctorC1ERKSt8functionIFdPKdEEj, _ZNK4ROOT4Math7Functor4NDimEv, _ZN4ROOT4Math26IBaseFunctionMultiDimTemplIdED2Ev, _ZNSt15__uniq_ptr_implIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EE6_M_ptrEv, _ZNSt15__uniq_ptr_implIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EE10_M_deleterEv, _ZTSN4ROOT4Math26IBaseFunctionMultiDimTemplIdEE, _ZTVN4ROOT4Math7FunctorE, _ZTVN4ROOT4Math26IBaseFunctionMultiDimTemplIdEE, _ZNSt10_Head_baseILm0EPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEELb0EEC2Ev, _ZTIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEE, _ZNK4ROOT4Math7Functor6DoEvalEPKd, _ZNSt10unique_ptrIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EE11get_deleterEv, __cxx_global_var_initcling_module_297_, _ZTS15LinearIntegrand, _ZN4ROOT4Math26IBaseFunctionMultiDimTemplIdED0Ev, _ZTSN4ROOT4Math7FunctorE, _ZNSt14_Function_base13_Base_managerI15LinearIntegrandE8_M_cloneERSt9_Any_dataRKS3_St17integral_constantIbLb0EE, _ZNSt10_Head_baseILm1ESt14default_deleteIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEEELb1EE7_M_headERS6_, _ZN4ROOT4Math18IntegratorMultiDimD0Ev, _ZNSt11_Tuple_implILm1EJSt14default_deleteIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEEEEEC2Ev, _ZNSt9_Any_data9_M_accessEv, _ZNSt8functionIFdPKdEED2Ev, _ZNSt14_Function_base13_Base_managerI15LinearIntegrandE15_M_init_functorERSt9_Any_dataOS1_St17integral_constantIbLb0EE, _ZN4ROOT4Math7FunctorC2ERKSt8functionIFdPKdEEj, _ZNSt14_Function_base13_Base_managerI15LinearIntegrandE14_M_get_pointerERKSt9_Any_data, _ZN4ROOT4Math18IntegratorMultiDim8IntegralEPKdS3_, _ZNSt14__array_traitsIdLm2EE6_S_refERA2_Kdm, _ZN4ROOT4Math7FunctorC1ERKS1_, _ZN4ROOT4Math18IntegratorMultiDimD1Ev, _ZTIN4ROOT4Math7FunctorE, _ZNKSt9_Any_data9_M_accessIPK15LinearIntegrandEERKT_v, _ZN4ROOT4Math18IntegratorMultiDim11SetFunctionERKNS0_26IBaseFunctionMultiDimTemplIdEE, _ZNSt11_Tuple_implILm0EJPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEE7_M_headERS7_, _ZNSt14_Function_base13_Base_managerI15LinearIntegrandE15_M_init_functorERSt9_Any_dataOS1_, mw, mz, _ZSt3getILm1EJPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEERNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERSB_, _ZNSt5arrayIdLm2EEixEm, _ZNK15LinearIntegrandclEPKd, _ZNSt8functionIFdPKdEEC1ERKS3_, _ZN4ROOT4Math7FunctorC2ERKS1_, _ZNSt10unique_ptrIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EED1Ev, _ZNSt14_Function_base13_Base_managerI15LinearIntegrandE10_M_managerERSt9_Any_dataRKS3_St18_Manager_operation, _ZNSt14_Function_base13_Base_managerI15LinearIntegrandE21_M_not_empty_functionIS1_EEbRKT_, _ZNKSt9_Any_data9_M_accessEv, _ZNSt14_Function_baseD2Ev, _ZNSt15__uniq_ptr_implIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEC1Ev, _ZNKSt14default_deleteIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEEEclEPS3_, _ZTVN4ROOT4Math18IntegratorMultiDimE, _ZN4ROOT4Math26IBaseFunctionMultiDimTemplIdEC2Ev, _ZNK4ROOT4Math18IntegratorMultiDim5ErrorEv, _ZNKSt8functionIFdPKdEEclES1_, _ZNSt8functionIFdPKdEEC2I15LinearIntegrandvvEET_, _ZNKSt8functionIFdPKdEEcvbEv, _ZSt12__get_helperILm1ESt14default_deleteIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEEEJEERT0_RSt11_Tuple_implIXT_EJS6_DpT1_EE, _ZNSt5tupleIJPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEEC2IS4_S6_Lb1EEEv, _ZTSN4ROOT4Math18IntegratorMultiDimE, _ZNSt14_Function_baseC2Ev, _ZN4ROOT4Math18IntegratorMultiDimC2ERKNS0_26IBaseFunctionMultiDimTemplIdEENS0_19IntegrationMultiDim4TypeEddj, _ZN4ROOT4Math7FunctorD1Ev, _ZNKSt14_Function_base8_M_emptyEv, _ZNK4ROOT4Math7Functor5CloneEv, _ZNSt11_Tuple_implILm0EJPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEEC2Ev, _ZSt3powIdiEN9__gnu_cxx11__promote_2IT_T0_NS0_9__promoteIS2_Xsr3std12__is_integerIS2_EE7__valueEE6__typeENS4_IS3_Xsr3std12__is_integerIS3_EE7__valueEE6__typeEE6__typeES2_S3_, _Z9get_constv, _ZNSt14_Function_base13_Base_managerI15LinearIntegrandE10_M_destroyERSt9_Any_dataSt17integral_constantIbLb0EE, _ZNSt10_Head_baseILm0EPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEELb0EE7_M_headERS5_, _GLOBAL__sub_I_cling_module_297, _ZNSt15__uniq_ptr_implIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEC2Ev, _ZNKSt9_Any_data9_M_accessIP15LinearIntegrandEERKT_v, _ZNSt8functionIFdPKdEED1Ev, _ZTI15LinearIntegrand, __orc_init_func.cling-module-297, _ZNSt10_Head_baseILm1ESt14default_deleteIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEEELb1EEC2Ev, _ZNSt10unique_ptrIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEC2IS5_vEEv, _ZNSt10unique_ptrIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEC1IS5_vEEv, _ZSt12__get_helperILm0EPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEEJSt14default_deleteIS3_EEERT0_RSt11_Tuple_implIXT_EJS7_DpT1_EE, _ZNSt11_Tuple_implILm1EJSt14default_deleteIN4ROOT4Math26IBaseFunctionMultiDimTemplIdEEEEE7_M_headERS6_, _ZNSt8functionIFdPKdEEC1I15LinearIntegrandvvEET_, _ZN4ROOT4Math7FunctorD2Ev, _ZSt3getILm0EJPN4ROOT4Math26IBaseFunctionMultiDimTemplIdEESt14default_deleteIS3_EEERNSt13tuple_elementIXT_ESt5tupleIJDpT0_EEE4typeERSB_, _ZNK4ROOT4Math26IBaseFunctionMultiDimTemplIdE11HasGradientEv, _ZN4ROOT4Math18IntegratorMultiDimD2Ev, gf, _ZNSt9_Any_data9_M_accessIPKSt9type_infoEERT_v }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { __orc_init_func.cling-module-297 }) }
cling JIT session error: Failed to materialize symbols: { (main, { _Z9get_constv }) }

However, if one does either one of following 2 modifications:

  1. Comments out line 8 in the C++ code and uncomments line 9,
  2. Comments out lines 37-39 and uncomments lines 40-41,

the code works as expected. So it seems that there’s a problem due to the presence of a mathematical operation such as std::pow and ROOT::Math::IntegratorMultiDim. This is not exclusive of std::pow, the code fails similarly if in line 11 one replaces std::pow(mw/mz,2) by mw/mz.

I tried it with 3 different ROOT versions: 6.34.00, 6.32.08, and 6.24 with identical results. Sadly, the older versions are not available for my Ubuntu 20.04.

How can I solve this issue?

I apologize in advance if the question is trivial and for the extensive code.


_ROOT Version:6.32, 6.24, 6.34
_Platform:Ubuntu 20.04
_Compiler:gcc 9.4


Best regards,
Alejo.

Hi Alejo,

Thanks for the report. I am sorry to read ROOT did not work out of the box for you in this case. We are aware of this issue, and will fix it: [6.32/master] Fail to materialise simbols from `libMatrix` · Issue #16601 · root-project/root · GitHub

In the meantime, here you have a workaround for your case:

import ROOT
# load cpp code
ROOT.gInterpreter.ProcessLine('#include "minexample.cpp"')
print(ROOT.get_const())

I hope this helps,
D

Hi Danilo,
Thanks a lot for your quick reply! I confirm that your workaround solves my problem and allows me to reuse the original full code.

Best regards,
Alejo.