Is it possible to store TKDE for future use?

I use TKDE objects to create a lambda function that I need to use at a later time in an another application. My code is something like this:

vector<double> vKDERT;
vector<double> vKDEWT;
//fill vectors, find xMin and xMax, define rho
TKDE *kdeRT = new TKDE(vKDERT.size(), &vKDERT[0], xMin-.1*rho, xMax+.1*rho,"", rho);
TKDE *kdeWT = new TKDE(vKDEWT.size(), &vKDEWT[0], xMin-.1*rho, xMax+.1*rho,"", rho);
auto fW = new TF1("fW", [&](double *x, double *p)
  double yRT = nRT*kdeRT->GetValue(x[0]); 
  double yWT = nWT*kdeWT->GetValue(x[0]); 
  return yWT/(yWT+yRT);

How can I store fW or the TKDEs?


You should be able to store the TKDE to a TFile. The function OTOH uses a lambda; we currently cannot store that one.

Hi Alex,
I tried to no success.

This code:

void test()
        TFile *f = new TFile("test.root", "RECREATE");
        vector<double> v;
        for(int i=0;i<10;++i) v.push_back((double)i);
        TKDE *kde = new TKDE(v.size(), &v[0], 0., 20., "", 1);

produces this error:

root [0] 
Processing test.C...
Warning in <TClass::Init>: no dictionary for class TKDE::TKernel is available
Error in <TStreamerInfo::Build>: TKDE: TKDE::TKernel* has no streamer or dictionary, data member fKernel will not be saved
Warning in <TBufferFile::WriteObjectAny>: since ROOT::Math::WrappedMemFunction<TKDE,double(TKDE::*)(double)const> has no public constructor
	which can be called without argument, objects of this class
	can not be read with the current library. You will need to
	add a default constructor before attempting to read it.
Error in <TStreamerInfo::Build>: ROOT::Math::WrappedMemFunction<TKDE,double(TKDE::*)(double)const>, unknown type: double(TKDE::*)(double)const fMemFunc

 *** Break *** segmentation violation



Thanks Alberto. @moneta could you have a look when you’re back at work?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.