diff --git a/src/CachingNLL.cc b/src/CachingNLL.cc index 3dbf58500e4..ed7c802f1cd 100644 --- a/src/CachingNLL.cc +++ b/src/CachingNLL.cc @@ -581,8 +581,7 @@ cacheutils::CachingAddNLL::setup_() } std::unique_ptr params(pdf_->getParameters(*data_)); - std::unique_ptr iter(params->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *params) { if (dynamic_cast(a)) params_.add(*a); else if (dynamic_cast(a)) catParams_.add(*a); } diff --git a/src/Combine.cc b/src/Combine.cc index d48c9af413b..bcbcd2ab3c3 100644 --- a/src/Combine.cc +++ b/src/Combine.cc @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -974,8 +973,7 @@ 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__); - std::unique_ptr iter(genPdf->getParameters((const RooArgSet*)0)->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *std::unique_ptr{genPdf->getParameters((const RooArgSet*)0)}) { TString varstring = utils::printRooArgAsString(a); CombineLogger::instance().log("Combine.cc",__LINE__,varstring.Data(),__func__); } @@ -1071,8 +1069,7 @@ 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__); - std::unique_ptr iter(genPdf->getParameters((const RooArgSet*)0)->createIterator()); - for (RooAbsArg *a = (RooAbsArg *) iter->Next(); a != 0; a = (RooAbsArg *) iter->Next()) { + for (RooAbsArg *a : *std::unique_ptr{genPdf->getParameters((const RooArgSet*)0)}) { TString varstring = utils::printRooArgAsString(a); CombineLogger::instance().log("Combine.cc" ,__LINE__,varstring.Data(),__func__); } diff --git a/src/MultiDimFit.cc b/src/MultiDimFit.cc index 054088d453a..683d9ff480e 100644 --- a/src/MultiDimFit.cc +++ b/src/MultiDimFit.cc @@ -370,8 +370,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) { RooArgSet mcNuis(*mc_s->GetNuisanceParameters()); if(saveSpecifiedNuis_=="all"){ specifiedNuis_.clear(); - RooLinkedListIter iterN = mc_s->GetNuisanceParameters()->iterator(); - for (RooAbsArg *a = (RooAbsArg*) iterN.Next(); a != 0; a = (RooAbsArg*) iterN.Next()) { + for (RooAbsArg *a : *mc_s->GetNuisanceParameters()) { if (poiList_.contains(*a)) continue; specifiedNuis_.push_back(a->GetName()); } @@ -382,8 +381,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) { while(token) { const RooArgSet* group = mc_s->GetWS()->set((std::string("group_") + token).data()); if (group){ - RooLinkedListIter iterN = group->iterator(); - for (RooAbsArg *a = (RooAbsArg*) iterN.Next(); a != 0; a = (RooAbsArg*) iterN.Next()) { + for (RooAbsArg *a : *group) { specifiedNuis_.push_back(a->GetName()); } }else if (!poiList_.find(token)){ @@ -404,8 +402,7 @@ void MultiDimFit::initOnce(RooWorkspace *w, RooStats::ModelConfig *mc_s) { } } if(saveInactivePOI_){ - RooLinkedListIter iterP = mc_s->GetParametersOfInterest()->iterator(); - for (RooAbsArg *a = (RooAbsArg*) iterP.Next(); a != 0; a = (RooAbsArg*) iterP.Next()) { + for (RooAbsArg *a : *mc_s->GetParametersOfInterest()) { if (poiList_.contains(*a)) continue; if (specifiedList_.contains(*a)) continue; RooRealVar *rrv = dynamic_cast(a); diff --git a/src/RooRealFlooredSumPdf.cc b/src/RooRealFlooredSumPdf.cc index 6ff54153b35..191c323390e 100755 --- a/src/RooRealFlooredSumPdf.cc +++ b/src/RooRealFlooredSumPdf.cc @@ -311,17 +311,14 @@ Double_t RooRealFlooredSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet* assert(cache != 0); } - RooFIter funcIntIter = cache->_funcIntList.fwdIterator(); - RooFIter coefIter = _coefList.fwdIterator(); - RooFIter funcIter = _funcList.fwdIterator(); - RooAbsReal *coef(0), *funcInt(0), *func(0); Double_t value(0); // N funcs, N-1 coefficients Double_t lastCoef(1); - while ((coef = (RooAbsReal*)coefIter.next())) { - funcInt = (RooAbsReal*)funcIntIter.next(); - func = (RooAbsReal*)funcIter.next(); + for (int iCoef = 0; iCoef < _coefList.getSize(); ++iCoef) { + RooAbsReal *coef = &static_cast(_coefList[iCoef]); + RooAbsReal *func = &static_cast(_funcList[iCoef]); + RooAbsReal *funcInt = &static_cast(cache->_funcIntList[iCoef]); Double_t coefVal = coef->getVal(normSet2); if (coefVal) { assert(func); @@ -333,7 +330,7 @@ Double_t RooRealFlooredSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet* if (!_haveLastCoef) { // Add last func with correct coefficient - funcInt = (RooAbsReal*)funcIntIter.next(); + RooAbsReal *funcInt = &static_cast(cache->_funcIntList[_coefList.getSize()]); assert(funcInt); value += funcInt->getVal()*lastCoef; @@ -350,11 +347,9 @@ Double_t RooRealFlooredSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet* normVal = 0; // N funcs, N-1 coefficients - RooAbsReal* funcNorm; - RooFIter funcNormIter = cache->_funcNormList.fwdIterator(); - RooFIter coefIter2 = _coefList.fwdIterator(); - while ((coef = (RooAbsReal*)coefIter2.next())) { - funcNorm = (RooAbsReal*)funcNormIter.next(); + for (int iCoef = 0; iCoef < _coefList.getSize(); ++iCoef) { + RooAbsReal *coef = &static_cast(_coefList[iCoef]); + RooAbsReal *funcNorm = &static_cast(cache->_funcNormList[iCoef]); Double_t coefVal = coef->getVal(normSet2); if (coefVal) { assert(funcNorm); @@ -364,7 +359,7 @@ Double_t RooRealFlooredSumPdf::analyticalIntegralWN(Int_t code, const RooArgSet* // Add last func with correct coefficient if (!_haveLastCoef) { - funcNorm = (RooAbsReal*)funcNormIter.next(); + RooAbsReal *funcNorm = &static_cast(cache->_funcNormList[_coefList.getSize()]); assert(funcNorm); normVal += funcNorm->getVal()*lastCoef; } @@ -399,10 +394,9 @@ std::list* RooRealFlooredSumPdf::binBoundaries(RooAbsRealLValue& obs, list* sumBinB = 0; Bool_t needClean(kFALSE); - RooFIter iter = _funcList.fwdIterator(); - RooAbsReal* func; // Loop over components pdf - while ((func = (RooAbsReal*)iter.next())) { + for (RooAbsArg *funcAbsArg : _funcList) { + RooAbsReal *func = static_cast(funcAbsArg); list* funcBinB = func->binBoundaries(obs, xlo, xhi); @@ -463,10 +457,9 @@ std::list* RooRealFlooredSumPdf::plotSamplingHint(RooAbsRealLValue& ob list* sumHint = 0; Bool_t needClean(kFALSE); - RooFIter iter = _funcList.fwdIterator(); - RooAbsReal* func; // Loop over components pdf - while ((func = (RooAbsReal*)iter.next())) { + for (RooAbsArg *funcAbsArg : _funcList) { + RooAbsReal *func = static_cast(funcAbsArg); list* funcHint = func->plotSamplingHint(obs, xlo, xhi); @@ -513,7 +506,6 @@ void RooRealFlooredSumPdf::printMetaArgs(ostream& os) const Bool_t first(kTRUE); - RooAbsArg* coef, *func; if (_coefList.getSize() != 0) { for (int iCoef = 0; iCoef <= _coefList.getSize(); ++iCoef) { RooAbsArg *coef = &_coefList[iCoef]; diff --git a/src/utils.cc b/src/utils.cc index 19fd580e8df..d62f5d5d028 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -297,8 +297,7 @@ RooAbsReal *utils::fullCloneFunc(const RooAbsReal *pdf, const RooArgSet &obs, Ro void utils::getClients(const RooAbsCollection &values, const RooAbsCollection &allObjects, RooAbsCollection &clients) { for (RooAbsArg *v : values) { if (typeid(*v) != typeid(RooRealVar) && typeid(*v) != typeid(RooCategory)) continue; - std::unique_ptr clientIter(v->clientIterator()); - for (RooAbsArg *a = (RooAbsArg *) clientIter->Next(); a != 0; a = (RooAbsArg *) clientIter->Next()) { + for (RooAbsArg *a : v->clients()) { if (allObjects.containsInstance(*a) && !clients.containsInstance(*a)) clients.add(*a); } } @@ -628,8 +627,8 @@ void utils::CheapValueSnapshot::readFrom(const RooAbsCollection &src) { src_ = &src; values_.resize(src.getSize()); } - RooLinkedListIter iter = src.iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (int i = 0; i < src.getSize(); ++i) { + RooAbsArg *a = src[i]; RooRealVar *rrv = dynamic_cast(a); if (rrv == 0) { RooCategory *rc = dynamic_cast(a); @@ -645,8 +644,8 @@ void utils::CheapValueSnapshot::readFrom(const RooAbsCollection &src) { void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const { if (&src == src_) { - RooLinkedListIter iter = src.iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (int i = 0; i < src.getSize(); ++i) { + RooAbsArg *a = src[i]; RooRealVar *rrv = dynamic_cast(a); if (rrv!=0) rrv->setVal(values_[i]); else { @@ -655,8 +654,8 @@ void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const { } } } else { - RooLinkedListIter iter = src_->iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (int i = 0; i < src_->getSize(); ++i) { + RooAbsArg *a = (*src_)[i]; RooAbsArg *a2 = src.find(a->GetName()); if (a2 == 0) continue; RooRealVar *rrv = dynamic_cast(a2); if (rrv!=0) rrv->setVal(values_[i]); @@ -671,8 +670,8 @@ void utils::CheapValueSnapshot::writeTo(const RooAbsCollection &src) const { void utils::CheapValueSnapshot::Print(const char *fmt) const { if (src_ == 0) { printf("\n"); return; } if (fmt[0] == 'V') { - RooLinkedListIter iter = src_->iterator(); int i = 0; - for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next(), ++i) { + for (int i = 0; i < src_->getSize(); ++i) { + RooAbsArg *a = (*src_)[i]; printf(" %3d) %-30s = %9.6g\n", i, a->GetName(), values_[i]); } printf("\n"); @@ -992,8 +991,8 @@ bool utils::anyParameterAtBoundaries( const RooArgSet ¶ms, int verbosity ){ static std::unordered_map timesFoundAtBoundary; bool isAnyBad = false; - RooLinkedListIter iter = params.iterator(); int i = 0; - for (RooRealVar *a = (RooRealVar *) iter.Next(); a != 0; a = (RooRealVar *) iter.Next(), ++i) { + for (RooAbsArg *aAbsArg : params) { + RooRealVar *a = static_cast(aAbsArg); bool isBad = isParameterAtBoundary(*a);