I was curious if there is a way to tell RDF in what directory of a TFile a histogram may be stored the moment the histogram is booked. In the classic approach, this was “easy” as one could simply do e.g.:
TFile * f = new TFile("out.root", "recreate");
f->mkdir("newFolder");
f->cd("newFolder");
TH1D* h1 = new TH1D("h1","a histogram", 200, 0, 200);
f->cd();
And then afterwards one can fill the histogram and perform other operations, but it will be linked to this location in the TFile. This is particularly nice when dealing with lots of histograms. Now in RDF, when the histogram is booked, I have not found a way one could already declare where a histogram is stored. It somehow makes sense, given how RDF works, but it would be convenient if when I want to just loop over a large set of histograms to store them in an output file, I would not need to decide for each histogram “a posteriori” where to store them. Would there be a solution for this?
Indeed as you noticed, we tried not to rely on automatic memory management for RDF - as a matter of fact this is a direction we are taking for all new components, and a strategic direction for ROOT itself.
All histograms currently used by RDF inherit from TH1. Is it an option perhaps to collect their pointers in a simple container (vector? list?) to then store them in a loop in a file?
This is good to know and I can also see why this is the direction.
Indeed, for one folder that could work. Just to be sure – following that approach, would the simplest solution for storing multiple histograms to multiple folders be to define a vector for each folder (or a map of vectors)?