Skip to content

Commit 172c924

Browse files
committed
[RF] Replace more createIterator occurences by range-based loops
This is part of the RooFit code modernization. After this PR, we will probably only need one more to replace the remaining occurences of `createIterator`.
1 parent 40fd04f commit 172c924

File tree

12 files changed

+101
-313
lines changed

12 files changed

+101
-313
lines changed

roofit/histfactory/src/RooBarlowBeestonLL.cxx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ ClassImp(RooStats::HistFactory::RooBarlowBeestonLL);
5656
{
5757
// Default constructor
5858
// Should only be used by proof.
59-
// _piter = _par.createIterator() ;
60-
// _oiter = _obs.createIterator() ;
6159
}
6260

6361

@@ -86,9 +84,6 @@ RooStats::HistFactory::RooBarlowBeestonLL::RooBarlowBeestonLL(const char *name,
8684
8785
delete actualObs ;
8886
delete actualPars ;
89-
90-
_piter = _par.createIterator() ;
91-
_oiter = _obs.createIterator() ;
9287
*/
9388
}
9489

@@ -106,9 +101,6 @@ RooStats::HistFactory::RooBarlowBeestonLL::RooBarlowBeestonLL(const RooBarlowBee
106101
{
107102
// Copy constructor
108103

109-
// _piter = _par.createIterator() ;
110-
// _oiter = _obs.createIterator() ;
111-
112104
// _paramAbsMin.addClone(other._paramAbsMin) ;
113105
// _obsAbsMin.addClone(other._obsAbsMin) ;
114106

roofit/roofit/src/RooMomentMorphFuncND.cxx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,6 @@ void RooMomentMorphFuncND::cartesian_product(vector<vector<T>> &out, vector<vect
248248
//_____________________________________________________________________________
249249
void RooMomentMorphFuncND::initialize()
250250
{
251-
// TIterator* pdfItr = _referenceGrid._pdfList.createIterator() ;
252-
// RooAbsReal* pdf ;
253-
// for (int i=0; (pdf = dynamic_cast<RooAbsReal*>(pdfItr->Next())); ++i) {
254-
// if (!pdf) {
255-
// coutE(InputArguments) << "RooMomentMorphFunc::ctor(" << GetName() << ") ERROR: pdf " << pdf->GetName() << " is
256-
// not of type RooAbsReal" << endl ;
257-
// throw string("RooPolyMorh::ctor() ERROR pdf is not of type RooAbsReal") ;
258-
// }
259-
// _pdfList.addClone(*pdf) ;
260-
// }
261-
// delete pdfItr ;
262-
263251
for (vector<RooAbsBinning *>::iterator itr = _referenceGrid._grid.begin(); itr != _referenceGrid._grid.end();
264252
++itr) {
265253
_referenceGrid._nnuis.push_back((*itr)->numBins() + 1);

roofit/roofit/src/RooMomentMorphND.cxx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,6 @@ inline void cartesian_product(vector<vector<T>> &out, vector<vector<T>> &in)
248248
//_____________________________________________________________________________
249249
void RooMomentMorphND::initialize()
250250
{
251-
// TIterator* pdfItr = _referenceGrid._pdfList.createIterator() ;
252-
// RooAbsPdf* pdf ;
253-
// for (int i=0; (pdf = dynamic_cast<RooAbsPdf*>(pdfItr->Next())); ++i) {
254-
// if (!pdf) {
255-
// coutE(InputArguments) << "RooMomentMorph::ctor(" << GetName() << ") ERROR: pdf " << pdf->GetName() << " is not
256-
// of type RooAbsPdf" << endl ;
257-
// throw string("RooPolyMorh::ctor() ERROR pdf is not of type RooAbsPdf") ;
258-
// }
259-
// _pdfList.addClone(*pdf) ;
260-
// }
261-
// delete pdfItr ;
262-
263251
for (vector<RooAbsBinning *>::iterator itr = _referenceGrid._grid.begin(); itr != _referenceGrid._grid.end();
264252
++itr) {
265253
_referenceGrid._nnuis.push_back((*itr)->numBins() + 1);

roofit/roofitcore/inc/RooExpensiveObjectCache.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
class RooExpensiveObjectCache : public TObject {
2525
public:
2626

27-
RooExpensiveObjectCache() ;
28-
RooExpensiveObjectCache(const RooExpensiveObjectCache&) ;
27+
RooExpensiveObjectCache() {}
28+
RooExpensiveObjectCache(const RooExpensiveObjectCache& other) : TObject(other) {}
2929
~RooExpensiveObjectCache() override ;
3030

3131
bool registerObject(const char* ownerName, const char* objectName, TObject& cacheObject, TIterator* paramIter) ;
@@ -75,7 +75,7 @@ class RooExpensiveObjectCache : public TObject {
7575

7676
protected:
7777

78-
Int_t _nextUID ;
78+
Int_t _nextUID = 0;
7979

8080
std::map<TString,ExpensiveObject*> _map ;
8181

roofit/roofitcore/src/RooDataSet.cxx

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -400,26 +400,18 @@ RooDataSet::RooDataSet(RooStringView name, RooStringView title, const RooArgSet&
400400

401401
// process StoreError requests
402402
if (errorSet) {
403-
RooArgSet* intErrorSet = (RooArgSet*) _vars.selectCommon(*errorSet) ;
403+
std::unique_ptr<RooArgSet> intErrorSet{static_cast<RooArgSet*>(_vars.selectCommon(*errorSet))};
404404
intErrorSet->setAttribAll("StoreError") ;
405-
TIterator* iter = intErrorSet->createIterator() ;
406-
RooAbsArg* arg ;
407-
while((arg=(RooAbsArg*)iter->Next())) {
405+
for(RooAbsArg* arg : *intErrorSet) {
408406
arg->attachToStore(*_dstore) ;
409407
}
410-
delete iter ;
411-
delete intErrorSet ;
412408
}
413409
if (asymErrorSet) {
414-
RooArgSet* intAsymErrorSet = (RooArgSet*) _vars.selectCommon(*asymErrorSet) ;
410+
std::unique_ptr<RooArgSet> intAsymErrorSet{static_cast<RooArgSet*>(_vars.selectCommon(*asymErrorSet))};
415411
intAsymErrorSet->setAttribAll("StoreAsymError") ;
416-
TIterator* iter = intAsymErrorSet->createIterator() ;
417-
RooAbsArg* arg ;
418-
while((arg=(RooAbsArg*)iter->Next())) {
412+
for(RooAbsArg* arg : *intAsymErrorSet) {
419413
arg->attachToStore(*_dstore) ;
420414
}
421-
delete iter ;
422-
delete intAsymErrorSet ;
423415
}
424416

425417
// Lookup name of weight variable if it was specified by object reference
@@ -1797,10 +1789,8 @@ void RooDataSet::printValue(ostream& os) const
17971789
void RooDataSet::printArgs(ostream& os) const
17981790
{
17991791
os << "[" ;
1800-
TIterator* iter = _varsNoWgt.createIterator() ;
1801-
RooAbsArg* arg ;
18021792
bool first(true) ;
1803-
while((arg=(RooAbsArg*)iter->Next())) {
1793+
for(RooAbsArg* arg : _varsNoWgt) {
18041794
if (first) {
18051795
first=false ;
18061796
} else {
@@ -1812,7 +1802,6 @@ void RooDataSet::printArgs(ostream& os) const
18121802
os << ",weight:" << _wgtVar->GetName() ;
18131803
}
18141804
os << "]" ;
1815-
delete iter ;
18161805
}
18171806

18181807

roofit/roofitcore/src/RooExpensiveObjectCache.cxx

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,19 @@ the object is valid, so that other instances can, at a later moment
2626
retrieve these precalculated objects.
2727
**/
2828

29+
#include "RooExpensiveObjectCache.h"
2930

3031
#include "TClass.h"
3132
#include "RooAbsReal.h"
3233
#include "RooAbsCategory.h"
3334
#include "RooArgSet.h"
3435
#include "RooMsgService.h"
3536
#include <iostream>
36-
using namespace std ;
37-
38-
#include "RooExpensiveObjectCache.h"
3937

4038
ClassImp(RooExpensiveObjectCache);
4139
ClassImp(RooExpensiveObjectCache::ExpensiveObject);
4240

4341

44-
////////////////////////////////////////////////////////////////////////////////
45-
/// Constructor
46-
47-
RooExpensiveObjectCache::RooExpensiveObjectCache() : _nextUID(0)
48-
{
49-
}
50-
51-
52-
53-
////////////////////////////////////////////////////////////////////////////////
54-
/// Copy constructor
55-
56-
RooExpensiveObjectCache::RooExpensiveObjectCache(const RooExpensiveObjectCache& other) :
57-
TObject(other), _nextUID(0)
58-
{
59-
}
60-
61-
62-
6342
////////////////////////////////////////////////////////////////////////////////
6443
/// Destructor.
6544

@@ -231,7 +210,7 @@ RooExpensiveObjectCache::ExpensiveObject::ExpensiveObject(Int_t uidIn, const cha
231210
if (cat) {
232211
_catRefParams[cat->GetName()] = cat->getCurrentIndex() ;
233212
} else {
234-
oocoutW(&inPayload,Caching) << "RooExpensiveObject::registerObject() WARNING: ignoring non-RooAbsReal/non-RooAbsCategory reference parameter " << arg->GetName() << endl ;
213+
oocoutW(&inPayload,Caching) << "RooExpensiveObject::registerObject() WARNING: ignoring non-RooAbsReal/non-RooAbsCategory reference parameter " << arg->GetName() << std::endl ;
235214
}
236215
}
237216
}
@@ -305,12 +284,9 @@ bool RooExpensiveObjectCache::ExpensiveObject::matches(TClass* tc, const RooArgS
305284

306285
void RooExpensiveObjectCache::print() const
307286
{
308-
map<TString,ExpensiveObject*>::const_iterator iter = _map.begin() ;
309-
310-
while(iter!=_map.end()) {
311-
cout << "uid = " << iter->second->uid() << " key=" << iter->first << " value=" ;
312-
iter->second->print() ;
313-
++iter ;
287+
for(auto const& item : _map) {
288+
std::cout << "uid = " << item.second->uid() << " key=" << item.first << " value=" ;
289+
item.second->print() ;
314290
}
315291
}
316292

@@ -320,22 +296,22 @@ void RooExpensiveObjectCache::print() const
320296

321297
void RooExpensiveObjectCache::ExpensiveObject::print() const
322298
{
323-
cout << _payload->ClassName() << "::" << _payload->GetName() ;
299+
std::cout << _payload->ClassName() << "::" << _payload->GetName() ;
324300
if (_realRefParams.size()>0 || _catRefParams.size()>0) {
325-
cout << " parameters=( " ;
301+
std::cout << " parameters=( " ;
326302
auto iter = _realRefParams.begin() ;
327303
while(iter!=_realRefParams.end()) {
328-
cout << iter->first << "=" << iter->second << " " ;
304+
std::cout << iter->first << "=" << iter->second << " " ;
329305
++iter ;
330306
}
331307
auto iter2 = _catRefParams.begin() ;
332308
while(iter2!=_catRefParams.end()) {
333-
cout << iter2->first << "=" << iter2->second << " " ;
309+
std::cout << iter2->first << "=" << iter2->second << " " ;
334310
++iter2 ;
335311
}
336-
cout << ")" ;
312+
std::cout << ")" ;
337313
}
338-
cout << endl ;
314+
std::cout << std::endl ;
339315
}
340316

341317

@@ -345,16 +321,14 @@ void RooExpensiveObjectCache::ExpensiveObject::print() const
345321

346322
void RooExpensiveObjectCache::importCacheObjects(RooExpensiveObjectCache& other, const char* ownerName, bool verbose)
347323
{
348-
map<TString,ExpensiveObject*>::const_iterator iter = other._map.begin() ;
349-
while(iter!=other._map.end()) {
350-
if (string(ownerName)==iter->second->ownerName()) {
351-
_map[iter->first.Data()] = new ExpensiveObject(_nextUID++, *iter->second) ;
324+
for(auto const& item : other._map) {
325+
if (std::string(ownerName)==item.second->ownerName()) {
326+
_map[item.first.Data()] = new ExpensiveObject(_nextUID++, *item.second) ;
352327
if (verbose) {
353-
oocoutI(iter->second->payload(),Caching) << "RooExpensiveObjectCache::importCache() importing cache object "
354-
<< iter->first << " associated with object " << iter->second->ownerName() << endl ;
328+
oocoutI(item.second->payload(),Caching) << "RooExpensiveObjectCache::importCache() importing cache object "
329+
<< item.first << " associated with object " << item.second->ownerName() << std::endl ;
355330
}
356331
}
357-
++iter ;
358332
}
359333

360334
}

0 commit comments

Comments
 (0)