Showcase registration of callback functions that act on partial results while the event-loop is running using OnPartialResult
and OnPartialResultSlot
. This tutorial is not meant to run in batch mode.
void df013_InspectAnalysis()
{
const auto nSlots = 0 == poolSize ? 1 : poolSize;
const auto nEvents = nSlots * 10000ull;
auto heavyWork = [&
r]() {
for (volatile int i = 0; i < 1000000; ++i)
;
};
auto df =
d.Define(
"x", heavyWork);
auto h = df.Histo1D<
double>({
"browserHisto",
"", 100, -2., 2.},
"x");
auto dfDirectory =
new TMemFile(
"RDFResults",
"RECREATE");
auto browser =
new TBrowser(
"b", dfDirectory);
h.OnPartialResult(
h.kOnce, [dfDirectory](
TH1D &h_) { dfDirectory->Add(&h_); });
h.OnPartialResult(50, [&browserPad](
TH1D &hist) {
if (!browserPad)
return;
browserPad->cd();
browserPad->Update();
});
std::string progressBar;
std::mutex barMutex;
const auto everyN = nSlots == 8 ? 1000 : 100ull * nSlots;
const auto barWidth = nEvents / everyN;
h.OnPartialResultSlot(everyN, [&barWidth, &progressBar, &barMutex](
unsigned int ,
TH1D & ) {
std::lock_guard<std::mutex>
l(barMutex);
progressBar.push_back('#');
std::cout << "\r[" << std::left << std::setw(barWidth) << progressBar << ']' << std::flush;
});
std::cout << "Analysis running..." << std::endl;
std::cout << "\nDone!" << std::endl;
dfDirectory->Clear();
clone->SetDirectory(
nullptr);
if (!browserPad)
return;
browserPad->cd();
browserPad->Update();
}
TObject * clone(const char *newname) const override
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
R__EXTERN TSystem * gSystem
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
Using a TBrowser one can browse all ROOT objects.
1-D histogram with a double per channel (see TH1 documentation)
void Draw(Option_t *option="") override
Draw this histogram with options.
A TMemFile is like a normal TFile except that it reads and writes only from memory.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
This is the base class for the ROOT Random number generators.
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
UInt_t GetThreadPoolSize()
Returns the size of ROOT's thread pool.