-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace deprecated legacy iterators #874
Merged
nucleosynthesis
merged 1 commit into
cms-analysis:main
from
guitargeek:legacy_iterators
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ | |
#include "RooConstVar.h" | ||
|
||
|
||
#include "TIterator.h" | ||
#include "RooListProxy.h" | ||
|
||
#include <iostream> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
#include <memory> | ||
#include <stdexcept> | ||
#include <TIterator.h> | ||
#include <RooAbsData.h> | ||
#include <RooArgSet.h> | ||
#include <RooProdPdf.h> | ||
|
@@ -21,8 +20,7 @@ RooAbsData *asimovutils::asimovDatasetNominal(RooStats::ModelConfig *mc, double | |
|
||
if (verbose>2) { | ||
CombineLogger::instance().log("AsimovUtils.cc",__LINE__,"Parameters after fit for asimov dataset",__func__); | ||
std::unique_ptr<TIterator> iter(mc->GetPdf()->getParameters((const RooArgSet*) 0)->createIterator()); | ||
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { | ||
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{mc->GetPdf()->getParameters((const RooArgSet*) 0)}) { | ||
TString varstring = utils::printRooArgAsString(a); | ||
CombineLogger::instance().log("AsimovUtils.cc",__LINE__,std::string(Form("%s",varstring.Data())),__func__); | ||
} | ||
|
@@ -45,8 +43,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD | |
} else { | ||
// Do we have free parameters anyway that need fitting? | ||
std::unique_ptr<RooArgSet> params(mc->GetPdf()->getParameters(realdata)); | ||
std::unique_ptr<TIterator> iter(params->createIterator()); | ||
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { | ||
for (RooAbsArg *a : *params) { | ||
RooRealVar *rrv = dynamic_cast<RooRealVar *>(a); | ||
if ( rrv != 0 && rrv->isConstant() == false ) { needsFit &= true; break; } | ||
} | ||
|
@@ -67,8 +64,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD | |
|
||
if (verbose>2) { | ||
CombineLogger::instance().log("AsimovUtils.cc",__LINE__,"Parameters after fit for asimov dataset",__func__); | ||
std::unique_ptr<TIterator> iter(mc->GetPdf()->getParameters(realdata)->createIterator()); | ||
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { | ||
for (RooAbsArg *a : *std::unique_ptr<RooArgSet>{mc->GetPdf()->getParameters(realdata)}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nucleosynthesis If it turns out that these inlined |
||
TString varstring = utils::printRooArgAsString(a); | ||
CombineLogger::instance().log("AsimovUtils.cc",__LINE__,std::string(Form("%s",varstring.Data())),__func__); | ||
} | ||
|
@@ -92,8 +88,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD | |
std::unique_ptr<RooAbsPdf> nuispdf(utils::makeNuisancePdf(*mc)); | ||
RooProdPdf *prod = dynamic_cast<RooProdPdf *>(nuispdf.get()); | ||
if (prod == 0) throw std::runtime_error("AsimovUtils: the nuisance pdf is not a RooProdPdf!"); | ||
std::unique_ptr<TIterator> iter(prod->pdfList().createIterator()); | ||
for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { | ||
for (RooAbsArg *a : prod->pdfList()) { | ||
RooAbsPdf *cterm = dynamic_cast<RooAbsPdf *>(a); | ||
if (!cterm) throw std::logic_error("AsimovUtils: a factor of the nuisance pdf is not a Pdf!"); | ||
if (!cterm->dependsOn(nuis)) continue; // dummy constraints | ||
|
@@ -109,8 +104,7 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD | |
if (cpars->getSize() == 1) { | ||
match = dynamic_cast<RooAbsReal *>(cpars->first()); | ||
} else { | ||
std::unique_ptr<TIterator> iter2(cpars->createIterator()); | ||
for (RooAbsArg *a2 = (RooAbsArg *) iter2->Next(); a2 != 0; a2 = (RooAbsArg *) iter2->Next()) { | ||
for (RooAbsArg *a2 : *cpars) { | ||
RooRealVar *rrv2 = dynamic_cast<RooRealVar *>(a2); | ||
if (rrv2 != 0 && !rrv2->isConstant()) { | ||
if (match != 0) throw std::runtime_error(Form("AsimovUtils: constraint term %s has multiple floating params", cterm->GetName())); | ||
|
@@ -138,10 +132,10 @@ RooAbsData *asimovutils::asimovDatasetWithFit(RooStats::ModelConfig *mc, RooAbsD | |
// we want to set the global obs to a value for which the current value | ||
// of the nuisance is the best fit one. | ||
// best fit x = (k-1)*theta ----> k = x/theta + 1 | ||
RooArgList leaves; cterm->leafNodeServerList(&leaves); | ||
std::unique_ptr<TIterator> iter2(leaves.createIterator()); | ||
RooArgList leaves; | ||
cterm->leafNodeServerList(&leaves); | ||
RooAbsReal *match2 = 0; | ||
for (RooAbsArg *a2 = (RooAbsArg *) iter2->Next(); a2 != 0; a2 = (RooAbsArg *) iter2->Next()) { | ||
for (RooAbsArg *a2 : leaves) { | ||
RooAbsReal *rar = dynamic_cast<RooAbsReal *>(a2); | ||
if (rar == 0 || rar == match || rar == &rrv) continue; | ||
if (!rar->isConstant()) throw std::runtime_error(Form("AsimovUtils: extra floating parameter %s of RooGamma %s.", rar->GetName(), cterm->GetName())); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not that a memory leak is fixed here by wrapping the return value of
getParameters
in a smart pointer (getParameters
returns a pointer that needs to be deleted)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change has introduced a seg fault when running with -v 3, try for example
combine data/tutorials/CAT23001/parametric-analysis-datacard.txt -m 125 -v 3
Any thoughts @guitargeek ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be that some compilers don't like that this
std::unique_ptr<RooArgSet>
objects lifetime is only defined by the scope of the loop.What happens if you give this a name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively you can try the
getParameters
overload with an output parameter, which doesn't do a heap allocation so in principle it's even better:Let me know if these patterns avoid the segfault