Skip to content

Commit 62005b0

Browse files
guitargeekanigamova
authored andcommitted
Apply a few more clang-tidy checks
Add a few more clang-tidy checks and apply them to the codebase. The most important check here is `modernize-use-default-member-init`, because it helps to ensure that we do default member variable initialization. Doing this consistently helps to avoid undefined behavior. The changes were *automatically generated by clang-tidy*. How this was done: ``` mkdir build cd build cmake -DCMAKE_INSTALL_PREFIX=../install -DINSTALL_PYTHON=FALSE -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. make -j12 run-clang-tidy -config-file=../.clang-tidy -export-fixes fixes.yaml -header-filter="interface/.*" . mv fixes.yaml .. cd .. clang-apply-replacements . ```
1 parent 865a330 commit 62005b0

30 files changed

Lines changed: 163 additions & 164 deletions

.clang-tidy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
---
22
Checks: -*,
3+
,boost-use-to-string,
4+
,bugprone-string-constructor,
5+
,misc-definitions-in-headers,
6+
,misc-string-compare,
7+
,misc-uniqueptr-reset-release,
8+
,modernize-use-default-member-init
39
,modernize-use-override,
10+
,performance-faster-string-find,
11+
,performance-inefficient-algorithm,
12+
,performance-inefficient-vector-operation,
13+
,performance-move-const-arg,
14+
,performance-trivially-destructible,
415
WarningsAsErrors: '*'
516
HeaderFilterRegex: ''
17+
CheckOptions:
18+
- key: misc-definitions-in-headers.HeaderFileExtensions
19+
value: 'h,hh,hpp,hxx,icc'
20+
- key: modernize-use-default-member-init.UseAssignment
21+
value: true
622
...

interface/AtlasPdfs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class RooStarMomentMorph : public RooAbsPdf {
333333

334334
class CacheElem : public RooAbsCacheElement {
335335
public:
336-
CacheElem(RooAbsPdf& sumPdf, RooChangeTracker& tracker, const RooArgList& flist) : _sumPdf(&sumPdf), _tracker(&tracker), _fractionsCalculated(false) {
336+
CacheElem(RooAbsPdf& sumPdf, RooChangeTracker& tracker, const RooArgList& flist) : _sumPdf(&sumPdf), _tracker(&tracker) {
337337
_frac.add(flist) ;
338338
} ;
339339
void operModeHook(RooAbsArg::OperMode) override {};
@@ -346,7 +346,7 @@ class RooStarMomentMorph : public RooAbsPdf {
346346
RooRealVar* frac(Int_t i ) ;
347347
const RooRealVar* frac(Int_t i ) const ;
348348
void calculateFractions(const RooStarMomentMorph& self, Bool_t verbose=kTRUE) const;
349-
mutable bool _fractionsCalculated;
349+
mutable bool _fractionsCalculated = false;
350350
} ;
351351
mutable RooObjCacheManager _cacheMgr ; // The cache manager
352352
mutable RooArgSet* _curNormSet ; //! Current normalization set

interface/CMSHistV.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class CMSHistV {
2020

2121
private:
2222
const T& hpdf_;
23-
int begin_, end_, nbins_;
23+
int begin_ = 0;
24+
int end_ = 0;
25+
int nbins_;
2426
struct Block {
2527
int index, begin, end;
2628
Block(int i, int begin_, int end_) : index(i), begin(begin_), end(end_) {}
@@ -32,7 +34,7 @@ class CMSHistV {
3234
template <class T>
3335
CMSHistV<T>::CMSHistV(const T& hpdf, const RooAbsData& data,
3436
bool includeZeroWeights)
35-
: hpdf_(hpdf), begin_(0), end_(0) {
37+
: hpdf_(hpdf) {
3638
hpdf.updateCache();
3739
std::vector<int> bins;
3840
RooArgSet obs(hpdf.x_.arg());

interface/CachingNLL.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ class CachingPdf : public CachingPdfBase {
8686
RooAbsReal *pdfOriginal_;
8787
RooArgSet pdfPieces_;
8888
RooAbsReal *pdf_;
89-
const RooAbsData *lastData_;
89+
const RooAbsData *lastData_ = 0;
9090
ValuesCache cache_;
9191
std::vector<uint8_t> nonZeroW_;
9292
unsigned int nonZeroWEntries_;
93-
bool includeZeroWeights_;
93+
bool includeZeroWeights_ = false;
9494
virtual void newData_(const RooAbsData &data) ;
9595
virtual void realFill_(const RooAbsData &data, std::vector<Double_t> &values) ;
9696
};
@@ -157,8 +157,8 @@ class CachingAddNLL : public RooAbsReal {
157157
mutable std::vector<Double_t> workingArea_;
158158
mutable bool isRooRealSum_, fastExit_;
159159
mutable int canBasicIntegrals_, basicIntegrals_;
160-
double zeroPoint_;
161-
double constantZeroPoint_; // this is arbitrary and kept constant for all the lifetime of the PDF
160+
double zeroPoint_ = 0;
161+
double constantZeroPoint_ = 0; // this is arbitrary and kept constant for all the lifetime of the PDF
162162
};
163163

164164
class CachingSimNLL : public RooAbsReal {
@@ -199,7 +199,8 @@ class CachingSimNLL : public RooAbsReal {
199199
const RooAbsData *dataOriginal_;
200200
const RooArgSet *nuis_;
201201
RooSetProxy params_, catParams_;
202-
bool hideRooCategories_, hideConstants_;
202+
bool hideRooCategories_ = false;
203+
bool hideConstants_ = false;
203204
RooArgSet piecesForCloning_;
204205
std::unique_ptr<RooSimultaneous> factorizedPdf_;
205206
std::vector<RooAbsPdf *> constrainPdfs_;
@@ -219,10 +220,10 @@ class CachingSimNLL : public RooAbsReal {
219220
std::vector<double> constrainZeroPointsFastPoisson_;
220221
std::vector<RooAbsReal*> channelMasks_;
221222
std::vector<bool> internalMasks_;
222-
bool maskConstraints_;
223+
bool maskConstraints_ = false;
223224
RooArgSet activeParameters_, activeCatParameters_;
224-
double maskingOffset_; // offset to ensure that interal or constraint masking doesn't change NLL value
225-
double maskingOffsetZero_; // and associated zero point
225+
double maskingOffset_ = 0; // offset to ensure that interal or constraint masking doesn't change NLL value
226+
double maskingOffsetZero_ = 0; // and associated zero point
226227
};
227228

228229
}

interface/CascadeMinimizer.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ class CascadeMinimizer {
4747
Mode mode_;
4848
static int strategy_;
4949
RooRealVar * poi_;
50-
const RooArgSet *nuisances_;
50+
const RooArgSet *nuisances_ = nullptr;
5151
/// automatically enlarge bounds for POIs if they're within 10% from the boundary
52-
bool autoBounds_;
53-
const RooArgSet *poisForAutoBounds_, *poisForAutoMax_;
52+
bool autoBounds_ = false;
53+
const RooArgSet *poisForAutoBounds_ = nullptr;
54+
const RooArgSet *poisForAutoMax_ = nullptr;
5455

5556
bool improveOnce(int verbose, bool noHesse=false);
5657
bool autoBoundsOk(int verbose) ;

interface/CloseCoutSentry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CloseCoutSentry {
2222
void static reallyClear() ;
2323
static FILE *trueStdOut_;
2424
static CloseCoutSentry *owner_;
25-
bool stdOutIsMine_;
25+
bool stdOutIsMine_ = false;
2626
};
2727

2828
#endif

interface/Combine.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ extern std::string defineBackgroundOnlyModelParameterExpression_;
3535

3636
namespace {
3737
struct ToCleanUp {
38-
TFile *tfile; std::string file, path;
39-
ToCleanUp() : tfile(0), file(""), path("") {}
38+
TFile *tfile = nullptr;
39+
std::string file;
40+
std::string path;
4041
~ToCleanUp() {
4142
if (tfile) { tfile->Close(); delete tfile; }
4243
if (!file.empty()) {

interface/FastTemplate.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ template <typename T, typename U=Double_t> class FastHisto_t : public FastTempla
180180
U GetEdge(unsigned int i) const { return GetXmin(i); }
181181
U GetWidth(unsigned int i) const { return GetBinWidth(i); }
182182

183-
void Dump() const ;
183+
void Dump() const override ;
184184

185185
FastHisto_t() : FastTemplate_t<T>(), axis_(), normX_(false) {}
186186
FastHisto_t(const TH1 &hist, bool normX=false);
@@ -195,15 +195,15 @@ template <typename T, typename U=Double_t> class FastHisto_t : public FastTempla
195195
else this->CopyValues(other);
196196
return *this;
197197
}
198-
FastHisto_t<T,U>& operator=(const TH1 &other) {
198+
FastHisto_t<T,U>& operator=(const TH1 &other) override {
199199
if ((int)this->size() != other.GetNbinsX()) {
200200
FastHisto_t<T,U> fh(other);
201201
swap(fh);
202202
}
203203
else this->CopyValues(other);
204204
return *this;
205205
}
206-
~FastHisto_t(){}
206+
~FastHisto_t() override {}
207207
};
208208
template <typename T, typename U=Double_t> class FastHisto2D_t : public FastTemplate_t<T> {
209209
private:
@@ -260,7 +260,7 @@ template <typename T, typename U=Double_t> class FastHisto2D_t : public FastTemp
260260
// For each X, normalize along Y
261261
void NormalizeXSlices() ;
262262

263-
void Dump() const ;
263+
void Dump() const override ;
264264

265265
T GetMaxOnXY() const ;
266266
T GetMaxOnX(const U &y) const ;
@@ -281,7 +281,7 @@ template <typename T, typename U=Double_t> class FastHisto2D_t : public FastTemp
281281
else this->CopyValues(other);
282282
return *this;
283283
}
284-
FastHisto2D_t& operator=(const TH1 &other) {
284+
FastHisto2D_t& operator=(const TH1 &other) override {
285285
if(other.GetDimension() != 2) {
286286
throw std::invalid_argument("FastHisto2D_t assignment error: right hand histogram must be 2-dimensional");
287287
}
@@ -292,7 +292,7 @@ template <typename T, typename U=Double_t> class FastHisto2D_t : public FastTemp
292292
else this->CopyValues(other);
293293
return *this;
294294
}
295-
~FastHisto2D_t(){}
295+
~FastHisto2D_t() override {}
296296
};
297297

298298
template <typename T, typename U=Double_t> class FastHisto3D_t : public FastTemplate_t<T> {
@@ -361,7 +361,7 @@ template <typename T, typename U=Double_t> class FastHisto3D_t : public FastTemp
361361
// For each X, normalize along Y
362362
void NormalizeXSlices() ;
363363

364-
void Dump() const ;
364+
void Dump() const override ;
365365

366366
FastHisto3D_t() : FastTemplate_t<T>(), axisX_(), axisY_(), axisZ_(), normX_(false), normY_(false), normZ_(false) {}
367367
FastHisto3D_t(const TH3 &hist, bool normX=false, bool normY=false, bool normZ=false);
@@ -380,7 +380,7 @@ template <typename T, typename U=Double_t> class FastHisto3D_t : public FastTemp
380380
else this->CopyValues(other);
381381
return *this;
382382
}
383-
FastHisto3D_t<T,U>& operator=(const TH1 &other) {
383+
FastHisto3D_t<T,U>& operator=(const TH1 &other) override {
384384
if(other.GetDimension() != 3) {
385385
throw std::invalid_argument("FastHisto3D_t assignment error: right hand histogram must be 3-dimensional");
386386
}
@@ -391,7 +391,7 @@ template <typename T, typename U=Double_t> class FastHisto3D_t : public FastTemp
391391
else this->CopyValues(other);
392392
return *this;
393393
}
394-
~FastHisto3D_t(){}
394+
~FastHisto3D_t() override {}
395395
};
396396

397397
#include "FastTemplate.hpp"

interface/FastTemplateFunc.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ template <typename T> class FastTemplateFunc_t : public RooAbsReal{
1616
FastTemplateFunc_t() : RooAbsReal(), obsList("obsList", "obsList", this){}
1717
FastTemplateFunc_t(const char *name, const char *title, RooArgList& inObsList) : RooAbsReal(name, title), obsList("obsList", "obsList", this){ setProxyList(obsList, inObsList); }
1818
FastTemplateFunc_t(const FastTemplateFunc_t& other, const char* name=0) : RooAbsReal(other, name), obsList("obsList", this, other.obsList){}
19-
inline ~FastTemplateFunc_t() override{}
19+
inline ~FastTemplateFunc_t() override {}
2020

2121
void setProxyList(RooListProxy& proxyList, RooArgList& varList){
2222
for (RooAbsArg *var : varList) {
@@ -53,18 +53,18 @@ template <typename T, typename U=Double_t> class FastHistoFunc_t : public FastTe
5353
}
5454
}
5555
FastHistoFunc_t(const FastHistoFunc_t& other, const char* name=0) : FastTemplateFunc_t<T>(other, name), tpl(other.tpl), fullIntegral(other.fullIntegral){}
56-
~FastHistoFunc_t(){}
57-
TObject* clone(const char* newname) const { return new FastHistoFunc_t(*this, newname); }
56+
~FastHistoFunc_t() override {}
57+
TObject* clone(const char* newname) const override { return new FastHistoFunc_t(*this, newname); }
5858

5959
FastHisto_t<T,U> getHistogram() const{ return tpl; }
6060
const Int_t getFullIntegralCode() const{ return 2; }
6161

62-
Double_t evaluate() const{
62+
Double_t evaluate() const override {
6363
T x = (T)(dynamic_cast<RooAbsReal*>((this->obsList).at(0))->getVal());
6464
Double_t value=tpl.GetAt(x);
6565
return value;
6666
}
67-
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const{
67+
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const override {
6868
Int_t code=1;
6969
const Int_t code_prime[1]={ 2 };
7070
for (int ic=0; ic<(this->obsList).getSize(); ic++){
@@ -77,7 +77,7 @@ template <typename T, typename U=Double_t> class FastHistoFunc_t : public FastTe
7777
if (code==1) code=0;
7878
return code;
7979
}
80-
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const{
80+
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const override {
8181
if (code==0) return evaluate();
8282
U xmin = (U)(dynamic_cast<RooRealVar*>((this->obsList).at(0))->getMin(rangeName));
8383
U xmax = (U)(dynamic_cast<RooRealVar*>((this->obsList).at(0))->getMax(rangeName));
@@ -114,19 +114,19 @@ template <typename T, typename U=Double_t> class FastHisto2DFunc_t : public Fast
114114
}
115115
}
116116
FastHisto2DFunc_t(const FastHisto2DFunc_t& other, const char* name=0) : FastTemplateFunc_t<T>(other, name), tpl(other.tpl), fullIntegral(other.fullIntegral){}
117-
~FastHisto2DFunc_t(){}
118-
TObject* clone(const char* newname) const { return new FastHisto2DFunc_t(*this, newname); }
117+
~FastHisto2DFunc_t() override {}
118+
TObject* clone(const char* newname) const override { return new FastHisto2DFunc_t(*this, newname); }
119119

120120
FastHisto2D_t<T,U> getHistogram() const{ return tpl; }
121121
const Int_t getFullIntegralCode() const{ return /*2*3*/6; }
122122

123-
Double_t evaluate() const{
123+
Double_t evaluate() const override {
124124
U x = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(0))->getVal());
125125
U y = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(1))->getVal());
126126
Double_t value=tpl.GetAt(x, y);
127127
return value;
128128
}
129-
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const{
129+
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const override {
130130
Int_t code=1;
131131
const Int_t code_prime[2]={ 2, 3 };
132132
for (int ic=0; ic<(this->obsList).getSize(); ic++){
@@ -139,7 +139,7 @@ template <typename T, typename U=Double_t> class FastHisto2DFunc_t : public Fast
139139
if (code==1) code=0;
140140
return code;
141141
}
142-
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const{
142+
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const override {
143143
if (code==0) return evaluate();
144144
U xmin, xmax, ymin, ymax;
145145
if (code%2==0){
@@ -206,20 +206,20 @@ template <typename T, typename U=Double_t> class FastHisto3DFunc_t : public Fast
206206
}
207207
}
208208
FastHisto3DFunc_t(const FastHisto3DFunc_t& other, const char* name=0) : FastTemplateFunc_t<T>(other, name), tpl(other.tpl), fullIntegral(other.fullIntegral){}
209-
~FastHisto3DFunc_t(){}
210-
TObject* clone(const char* newname) const { return new FastHisto3DFunc_t(*this, newname); }
209+
~FastHisto3DFunc_t() override {}
210+
TObject* clone(const char* newname) const override { return new FastHisto3DFunc_t(*this, newname); }
211211

212212
FastHisto3D_t<T,U> getHistogram() const{ return tpl; }
213213
const Int_t getFullIntegralCode() const{ return /*2*3*5*/30; }
214214

215-
Double_t evaluate() const{
215+
Double_t evaluate() const override {
216216
U x = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(0))->getVal());
217217
U y = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(1))->getVal());
218218
U z = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(2))->getVal());
219219
Double_t value=tpl.GetAt(x, y, z);
220220
return value;
221221
}
222-
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const{
222+
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const override {
223223
Int_t code=1;
224224
const Int_t code_prime[3]={ 2, 3, 5 };
225225
for (int ic=0; ic<(this->obsList).getSize(); ic++){
@@ -232,7 +232,7 @@ template <typename T, typename U=Double_t> class FastHisto3DFunc_t : public Fast
232232
if (code==1) code=0;
233233
return code;
234234
}
235-
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const{
235+
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const override {
236236
if (code==0) return evaluate();
237237
U xmin, xmax, ymin, ymax, zmin, zmax;
238238
if (code%2==0){

interface/FitDiagnostics.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ class FitDiagnostics : public FitterAlgoBase {
6060
int fitStatus_, numbadnll_;
6161
double mu_, muErr_, muLoErr_, muHiErr_, nll_nll0_, nll_bonly_, nll_sb_;
6262
std::unique_ptr<TFile> fitOut;
63-
double* globalObservables_;
64-
double* nuisanceParameters_;
65-
double* processNormalizations_;
66-
double* processNormalizationsShapes_;
63+
double* globalObservables_ = nullptr;
64+
double* nuisanceParameters_ = nullptr;
65+
double* processNormalizations_ = nullptr;
66+
double* processNormalizationsShapes_ = nullptr;
67+
68+
TTree *t_fit_b_ = nullptr;
69+
TTree *t_fit_sb_ = nullptr;
70+
TTree *t_prefit_ = nullptr;
6771

68-
TTree *t_fit_b_, *t_fit_sb_, *t_prefit_;
69-
7072
void getNormalizationsSimple(RooAbsPdf *pdf, const RooArgSet &obs, RooArgSet &out);
7173
void createFitResultTrees(const RooStats::ModelConfig &,bool,bool);
7274
void resetFitResultTrees(bool);
@@ -112,7 +114,7 @@ class FitDiagnostics : public FitterAlgoBase {
112114
const RooAbsCollection & centralValues() override;
113115
private:
114116
RooAbsPdf *pdf_;
115-
RooAbsData *data_;
117+
RooAbsData *data_ = nullptr;
116118
RooArgSet snapshot_;
117119
};
118120
};

0 commit comments

Comments
 (0)