Hi rooters!
Could anybody please help me with one problem:
I’m using RDataFrame in my analysis and I would like to save few histograms to the root file, I know that I can do it straightforward like:
auto rd = new ROOT::RDataFrame("tree", "....root");
auto f = new TFile("...", "recreate");
f->cd();
auto hist1= rd->Define(col1Name, Pt1, {...}).Filter(...).Histo1D(*histModel, col1Name).GetPtr();
auto hist2= rd->Define(col2Name, Pt2, {...}).Filter(...).Histo1D(*histModel, col2Name).GetPtr();
f->Wirte();
f->Close();
but, I have several function Pt1, Pt2, … which are very similar. Let say it has a difference only in one condition, so I want to use some wrapper for my expressions(Pt1, Pt2). Something like this:
TH1D* GetHist(TString col1Name, TString col1Title, TString filter, Int_t bins, Double_t xLow, Double_t xUp, Int_t Limit)
{
auto rd = new ROOT::RDataFrame("tree", "....root");
auto Pt = WrapPt(Limit);
return rd->Define(col1Name.Data(), Pt, {...}).Filter(...).Histo1D(*histModel, col1Name.Data()).GetPtr();
}
auto WrapPt(Int_t param)
{
return [&] (...)
{
int something;
// ... some calculations
if (something > param) return -1.;
return ev;
};
}
In this case all what I need just:
auto f = new TFile("...", "recreate");
f->cd();
auto hist1 = GetHist(col1Name, col1Title, filter, bins, xLow, xUp, Limit1);
auto hist2 = GetHist(col2Name, col2Title, filter, bins, xLow, xUp, Limit2);
f->Wirte();
f->Close();
and I have only one piece of code for my Pt.
So the problem is that syntax parser allows it, but compiler doesn’t:
error: 'auto' return without trailing return type; deduced return types are a C++14 extension
auto WrapPt(Int_t netChargeLimit)
error: no viable conversion from returned value of type to function return type 'int'
return [&] (...
To be short: how can I create an interface like RDataFrame has it for Define:
name, expression, ...
Perhaps root reinstallation with std=c++14 flag solves this?
Boris
ROOT Version: 6.17/01
Platform: linux
Compiler: gcc 7.3.0