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 tdf =
d.Define(
"x", heavyWork);
auto h = tdf.Histo1D<double>({"browserHisto", "", 100, -2., 2.}, "x");
auto *tdfDirectory =
new TMemFile(
"RDFResults",
"RECREATE");
auto *browser =
new TBrowser(
"b", tdfDirectory);
h.OnPartialResult(h.kOnce, [tdfDirectory](
TH1D &h_) { tdfDirectory->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;
h->Draw();
std::cout << "\nDone!" << std::endl;
tdfDirectory->Clear();
auto clone =
static_cast<TH1D *
>(h->Clone());
tdfDirectory->Add(clone);
if (!browserPad)
return;
browserPad->cd();
clone->Draw();
}
- Date
- September 2017
- Author
- Enrico Guiraud
Definition in file df013_InspectAnalysis.C.