I am using rdataframe and am confused by the result of GetPtr() from the following snippet
{
ROOT::RDataFrame d(2000000);
auto dd = d.Define("x", [](){ return gRandom->Uniform(-5., 5.); });
auto getTH1DFunc = [&dd]() {
return
dd.Histo1D({"", "", 100, -5, 5}, {"x"});
};
auto getTH1DPtrFunc = [&dd]() {
return
dd.Histo1D({"", "", 100, -5, 5}, {"x"}).GetPtr();
};
auto getTH1DPtrFunc2 = [&dd]() -> TH1D* {
return
dynamic_cast<TH1D *>(dd.Histo1D({"", "", 100, -5, 5}, {"x"}).GetPtr());
};
cout << "Histo1D direct Print: ";
getTH1DFunc()->Print();
cout << "Histo1D.GetPtr() direct Print: ";
getTH1DFunc().GetPtr()->Print();
cout << "Func returned Histo1D: ";
getTH1DPtrFunc()->Print();
cout << "Func returned Histo1D and cast: ";
getTH1DPtrFunc2()->Print();
}
The above snippet gives the result as
Histo1D direct Print: TH1.Print Name = , Entries= 2000000, Total sum= 2e+06
Histo1D.GetPtr() direct Print: TH1.Print Name = , Entries= 2000000, Total sum= 2e+06
Func returned Histo1D: OBJ: TObject TObject Basic ROOT object
Func returned Histo1D and cast: OBJ: TObject TObject Basic ROOT object
Why does the pointer of GetPtr() lose the class information when it is returned by a function (lambda and normal function give the same results)?
Is it a bug or a mistake in my cpp code?
My root version is
ROOT Version: 6.26/04
Built for linuxx8664gcc on Jun 07 2022, 16:01:16
From tags/v6-26-04@v6-26-04
Thank you very much!