Skip to content

Commit

Permalink
Don't use getParameters() inline in range-based loop (#890)
Browse files Browse the repository at this point in the history
This causes segmentation errors because of wong object lifetimes.
  • Loading branch information
guitargeek authored Dec 20, 2023
1 parent 06a73aa commit dcde02a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/AsimovUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ RooAbsData *asimovutils::asimovDatasetNominal(RooStats::ModelConfig *mc, double

if (verbose>2) {
CombineLogger::instance().log("AsimovUtils.cc",__LINE__,"Parameters after fit for asimov dataset",__func__);
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{mc->GetPdf()->getParameters((const RooArgSet*) 0)}) {
std::unique_ptr<RooArgSet> params{mc->GetPdf()->getParameters((const RooArgSet*) 0)};
for (RooAbsArg *a : *params) {
TString varstring = utils::printRooArgAsString(a);
CombineLogger::instance().log("AsimovUtils.cc",__LINE__,std::string(Form("%s",varstring.Data())),__func__);
}
Expand Down Expand Up @@ -64,7 +65,8 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD

if (verbose>2) {
CombineLogger::instance().log("AsimovUtils.cc",__LINE__,"Parameters after fit for asimov dataset",__func__);
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{mc->GetPdf()->getParameters(realdata)}) {
std::unique_ptr<RooArgSet> params{mc->GetPdf()->getParameters(realdata)};
for (RooAbsArg *a : *params) {
TString varstring = utils::printRooArgAsString(a);
CombineLogger::instance().log("AsimovUtils.cc",__LINE__,std::string(Form("%s",varstring.Data())),__func__);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Combine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,8 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
// print the values of the parameters used to generate the toy
if (verbose > 2) {
CombineLogger::instance().log("Combine.cc",__LINE__, "Generate Asimov toy from parameter values ... ",__func__);
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{genPdf->getParameters((const RooArgSet*)0)}) {
std::unique_ptr<RooArgSet> params{genPdf->getParameters((const RooArgSet*)0)};
for (RooAbsArg *a : *params) {
TString varstring = utils::printRooArgAsString(a);
CombineLogger::instance().log("Combine.cc",__LINE__,varstring.Data(),__func__);
}
Expand Down Expand Up @@ -1069,7 +1070,8 @@ void Combine::run(TString hlfFile, const std::string &dataset, double &limit, do
std::cout << "Generate toy " << iToy << "/" << nToys << std::endl;
if (verbose > 2) {
CombineLogger::instance().log("Combine.cc",__LINE__, std::string(Form("Generating toy %d/%d, from parameter values ... ",iToy,nToys)),__func__);
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{genPdf->getParameters((const RooArgSet*)0)}) {
std::unique_ptr<RooArgSet> params{genPdf->getParameters((const RooArgSet*)0)};
for (RooAbsArg *a : *params) {
TString varstring = utils::printRooArgAsString(a);
CombineLogger::instance().log("Combine.cc" ,__LINE__,varstring.Data(),__func__);
}
Expand Down
4 changes: 2 additions & 2 deletions src/FitterAlgoBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ bool FitterAlgoBase::run(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats:
break;
}

;
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{mc_s->GetPdf()->getParameters(data)}) {
std::unique_ptr<RooArgSet> params{mc_s->GetPdf()->getParameters(data)};
for (RooAbsArg *a : *params) {
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
if (rrv == 0 || rrv->isConstant()) continue;
if (profileMode_ == ProfileUnconstrained && mc_s->GetNuisanceParameters()->find(*rrv) != 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ bool utils::checkModel(const RooStats::ModelConfig &model, bool throwOnFail) {
}
}
;
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{pdf->getParameters(*model.GetObservables())}) {
std::unique_ptr<RooArgSet> params{pdf->getParameters(*model.GetObservables())};
for (RooAbsArg *a : *params) {
if (a->getAttribute("flatParam") && a->isConstant()) {
ok = false; errors << "ERROR: parameter " << a->GetName() << " is declared as flatParam but is constant.\n";
}
Expand Down

0 comments on commit dcde02a

Please sign in to comment.