Skip to content

Commit

Permalink
[RF] Make rootbench also build in memory-safe interfaces mode
Browse files Browse the repository at this point in the history
In particular, this avoids some leaking RooWorkspaces.
  • Loading branch information
guitargeek committed Nov 14, 2023
1 parent 86f6238 commit 8107236
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions root/roofit/histfactory/TestWorkspaces.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// Returns the workspace that is also created in the hf001_example.C tutorial.
/// Note that running this function creates a directory `hf001_data` in the
/// current directory.
RooWorkspace *
std::unique_ptr<RooWorkspace>
TestWorkspaces::getWorkspace001(RooStats::HistFactory::HistoToWorkspaceFactoryFast::Configuration const &cfg)
{
using namespace RooStats::HistFactory;
Expand Down Expand Up @@ -81,5 +81,5 @@ TestWorkspaces::getWorkspace001(RooStats::HistFactory::HistoToWorkspaceFactoryFa
meas.SetExportOnly(true);

// Now, do the measurement
return MakeModelAndMeasurementFast(meas, cfg);
return std::unique_ptr<RooWorkspace>{MakeModelAndMeasurementFast(meas, cfg)};
}
5 changes: 4 additions & 1 deletion root/roofit/histfactory/TestWorkspaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

#include <RooStats/HistFactory/HistoToWorkspaceFactoryFast.h>

#include <memory>

class RooWorkspace;

namespace TestWorkspaces {

RooWorkspace *getWorkspace001(RooStats::HistFactory::HistoToWorkspaceFactoryFast::Configuration const &cfg);
std::unique_ptr<RooWorkspace>
getWorkspace001(RooStats::HistFactory::HistoToWorkspaceFactoryFast::Configuration const &cfg);

} // namespace TestWorkspaces

Expand Down
16 changes: 8 additions & 8 deletions root/roofit/histfactory/benchHistFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ class TestData {
using namespace RooFit;

RooStats::HistFactory::HistoToWorkspaceFactoryFast::Configuration hfCfg;
auto *w = TestWorkspaces::getWorkspace001(hfCfg);
std::unique_ptr<RooWorkspace> ws = TestWorkspaces::getWorkspace001(hfCfg);

auto *mc = static_cast<RooStats::ModelConfig *>(w->obj("ModelConfig"));
auto *mc = static_cast<RooStats::ModelConfig *>(ws->obj("ModelConfig"));

if (mc->GetParametersOfInterest())
constraintParams.add(*mc->GetParametersOfInterest());
if (mc->GetNuisanceParameters())
constraintParams.add(*mc->GetNuisanceParameters());

auto *pdf = w->pdf("simPdf");
auto *pdf = ws->pdf("simPdf");

std::unique_ptr<RooAbsReal> nll{pdf->createNLL(*w->data("obsData"), Constrain(constraintParams),
std::unique_ptr<RooAbsReal> nll{pdf->createNLL(*ws->data("obsData"), Constrain(constraintParams),
GlobalObservables(*mc->GetGlobalObservables()), EvalBackend::Legacy())};

RooMinimizer m(*nll);
Expand Down Expand Up @@ -64,14 +64,14 @@ static void benchHistFactory001(benchmark::State &state)

RooStats::HistFactory::HistoToWorkspaceFactoryFast::Configuration hfCfg;
hfCfg.binnedFitOptimization = state.range(0);
auto *w = TestWorkspaces::getWorkspace001(hfCfg);
std::unique_ptr<RooWorkspace> ws = TestWorkspaces::getWorkspace001(hfCfg);

auto *mc = static_cast<RooStats::ModelConfig *>(w->obj("ModelConfig"));
auto *mc = static_cast<RooStats::ModelConfig *>(ws->obj("ModelConfig"));

auto *pdf = w->pdf("simPdf");
auto *pdf = ws->pdf("simPdf");

auto evalBackend = static_cast<EvalBackend::Value>(state.range(1));
std::unique_ptr<RooAbsReal> nll{pdf->createNLL(*w->data("obsData"), Constrain(g_testData.constraintParams),
std::unique_ptr<RooAbsReal> nll{pdf->createNLL(*ws->data("obsData"), Constrain(g_testData.constraintParams),
GlobalObservables(*mc->GetGlobalObservables()),
EvalBackend(evalBackend))};

Expand Down
6 changes: 3 additions & 3 deletions root/roofit/roofit/RooFitBinnedBenchmarks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ void buildBinnedTest(int n_channels = 1, int nbins = 10, int nnps = 1, const cha
meas.AddChannel(*chan);
}
HistoToWorkspaceFactoryFast hist2workspace(meas);
RooWorkspace *ws;
std::unique_ptr<RooWorkspace> ws;
if (n_channels < 2) {
ws = hist2workspace.MakeSingleChannelModel(meas, *chan);
ws = std::unique_ptr<RooWorkspace>{hist2workspace.MakeSingleChannelModel(meas, *chan)};
} else {
ws = hist2workspace.MakeCombinedModel(meas);
ws = std::unique_ptr<RooWorkspace>{hist2workspace.MakeCombinedModel(meas)};
}
for (RooAbsArg * arg : ws->components()) {
if (arg->IsA() == RooRealSumPdf::Class()) {
Expand Down

0 comments on commit 8107236

Please sign in to comment.