ROOT Version: 6.20.04 Platform: Linux Compiler: gcc
I’m just having my first foray into RDataFrames and it has taken me some time to work out how to prevent histograms produced this way from disappearing when a named macro ends. My solution is
Save a copy of the histogram on the heap AND
Save a pointer to the histogram in a TFolder before leaving the macro
Is this the correct way to do this? Is there a better solution? Is it documented somewhere that I’ve not found?
Here is a sketch of what I am doing
Hi @ajfinch ,
the following certainly apply to v6.24 and v6.26 and I think it applies to v6.20 as well, but I would strongly recommend to update to a more recent ROOT version: RDataFrame has improved a lot in the last few years.
The histograms returned by RDataFrame are not associated to ROOT’s memory management and are held by an owning pointer. To make them survive the scope of a macro, you have two options:
return them from the macro:
auto foo() { // in C++11, must return a RDF::RResultPtr<TH1D> instead of auto
auto h = ROOT::RDataFrame(10).Histo1D("rdfentry_");
return h;
}