Skip to content

Commit

Permalink
Apply a few more clang-tidy checks
Browse files Browse the repository at this point in the history
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 .
```
  • Loading branch information
guitargeek committed Nov 23, 2024
1 parent 865a330 commit d832875
Show file tree
Hide file tree
Showing 30 changed files with 163 additions and 164 deletions.
16 changes: 16 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
---
Checks: -*,
,boost-use-to-string,
,bugprone-string-constructor,
,misc-definitions-in-headers,
,misc-string-compare,
,misc-uniqueptr-reset-release,
,modernize-use-default-member-init
,modernize-use-override,
,performance-faster-string-find,
,performance-inefficient-algorithm,
,performance-inefficient-vector-operation,
,performance-move-const-arg,
,performance-trivially-destructible,
WarningsAsErrors: '*'
HeaderFilterRegex: ''
CheckOptions:
- key: misc-definitions-in-headers.HeaderFileExtensions
value: 'h,hh,hpp,hxx,icc'
- key: modernize-use-default-member-init.UseAssignment
value: true
...
4 changes: 2 additions & 2 deletions interface/AtlasPdfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class RooStarMomentMorph : public RooAbsPdf {

class CacheElem : public RooAbsCacheElement {
public:
CacheElem(RooAbsPdf& sumPdf, RooChangeTracker& tracker, const RooArgList& flist) : _sumPdf(&sumPdf), _tracker(&tracker), _fractionsCalculated(false) {
CacheElem(RooAbsPdf& sumPdf, RooChangeTracker& tracker, const RooArgList& flist) : _sumPdf(&sumPdf), _tracker(&tracker) {
_frac.add(flist) ;
} ;
void operModeHook(RooAbsArg::OperMode) override {};
Expand All @@ -346,7 +346,7 @@ class RooStarMomentMorph : public RooAbsPdf {
RooRealVar* frac(Int_t i ) ;
const RooRealVar* frac(Int_t i ) const ;
void calculateFractions(const RooStarMomentMorph& self, Bool_t verbose=kTRUE) const;
mutable bool _fractionsCalculated;
mutable bool _fractionsCalculated = false;
} ;
mutable RooObjCacheManager _cacheMgr ; // The cache manager
mutable RooArgSet* _curNormSet ; //! Current normalization set
Expand Down
6 changes: 4 additions & 2 deletions interface/CMSHistV.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class CMSHistV {

private:
const T& hpdf_;
int begin_, end_, nbins_;
int begin_ = 0;
int end_ = 0;
int nbins_;
struct Block {
int index, begin, end;
Block(int i, int begin_, int end_) : index(i), begin(begin_), end(end_) {}
Expand All @@ -32,7 +34,7 @@ class CMSHistV {
template <class T>
CMSHistV<T>::CMSHistV(const T& hpdf, const RooAbsData& data,
bool includeZeroWeights)
: hpdf_(hpdf), begin_(0), end_(0) {
: hpdf_(hpdf) {
hpdf.updateCache();
std::vector<int> bins;
RooArgSet obs(hpdf.x_.arg());
Expand Down
17 changes: 9 additions & 8 deletions interface/CachingNLL.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ class CachingPdf : public CachingPdfBase {
RooAbsReal *pdfOriginal_;
RooArgSet pdfPieces_;
RooAbsReal *pdf_;
const RooAbsData *lastData_;
const RooAbsData *lastData_ = 0;
ValuesCache cache_;
std::vector<uint8_t> nonZeroW_;
unsigned int nonZeroWEntries_;
bool includeZeroWeights_;
bool includeZeroWeights_ = false;
virtual void newData_(const RooAbsData &data) ;
virtual void realFill_(const RooAbsData &data, std::vector<Double_t> &values) ;
};
Expand Down Expand Up @@ -157,8 +157,8 @@ class CachingAddNLL : public RooAbsReal {
mutable std::vector<Double_t> workingArea_;
mutable bool isRooRealSum_, fastExit_;
mutable int canBasicIntegrals_, basicIntegrals_;
double zeroPoint_;
double constantZeroPoint_; // this is arbitrary and kept constant for all the lifetime of the PDF
double zeroPoint_ = 0;
double constantZeroPoint_ = 0; // this is arbitrary and kept constant for all the lifetime of the PDF
};

class CachingSimNLL : public RooAbsReal {
Expand Down Expand Up @@ -199,7 +199,8 @@ class CachingSimNLL : public RooAbsReal {
const RooAbsData *dataOriginal_;
const RooArgSet *nuis_;
RooSetProxy params_, catParams_;
bool hideRooCategories_, hideConstants_;
bool hideRooCategories_ = false;
bool hideConstants_ = false;
RooArgSet piecesForCloning_;
std::unique_ptr<RooSimultaneous> factorizedPdf_;
std::vector<RooAbsPdf *> constrainPdfs_;
Expand All @@ -219,10 +220,10 @@ class CachingSimNLL : public RooAbsReal {
std::vector<double> constrainZeroPointsFastPoisson_;
std::vector<RooAbsReal*> channelMasks_;
std::vector<bool> internalMasks_;
bool maskConstraints_;
bool maskConstraints_ = false;
RooArgSet activeParameters_, activeCatParameters_;
double maskingOffset_; // offset to ensure that interal or constraint masking doesn't change NLL value
double maskingOffsetZero_; // and associated zero point
double maskingOffset_ = 0; // offset to ensure that interal or constraint masking doesn't change NLL value
double maskingOffsetZero_ = 0; // and associated zero point
};

}
Expand Down
7 changes: 4 additions & 3 deletions interface/CascadeMinimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ class CascadeMinimizer {
Mode mode_;
static int strategy_;
RooRealVar * poi_;
const RooArgSet *nuisances_;
const RooArgSet *nuisances_ = nullptr;
/// automatically enlarge bounds for POIs if they're within 10% from the boundary
bool autoBounds_;
const RooArgSet *poisForAutoBounds_, *poisForAutoMax_;
bool autoBounds_ = false;
const RooArgSet *poisForAutoBounds_ = nullptr;
const RooArgSet *poisForAutoMax_ = nullptr;

bool improveOnce(int verbose, bool noHesse=false);
bool autoBoundsOk(int verbose) ;
Expand Down
2 changes: 1 addition & 1 deletion interface/CloseCoutSentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CloseCoutSentry {
void static reallyClear() ;
static FILE *trueStdOut_;
static CloseCoutSentry *owner_;
bool stdOutIsMine_;
bool stdOutIsMine_ = false;
};

#endif
5 changes: 3 additions & 2 deletions interface/Combine.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ extern std::string defineBackgroundOnlyModelParameterExpression_;

namespace {
struct ToCleanUp {
TFile *tfile; std::string file, path;
ToCleanUp() : tfile(0), file(""), path("") {}
TFile *tfile = nullptr;
std::string file;
std::string path;
~ToCleanUp() {
if (tfile) { tfile->Close(); delete tfile; }
if (!file.empty()) {
Expand Down
18 changes: 9 additions & 9 deletions interface/FastTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ template <typename T, typename U=Double_t> class FastHisto_t : public FastTempla
U GetEdge(unsigned int i) const { return GetXmin(i); }
U GetWidth(unsigned int i) const { return GetBinWidth(i); }

void Dump() const ;
void Dump() const override ;

FastHisto_t() : FastTemplate_t<T>(), axis_(), normX_(false) {}
FastHisto_t(const TH1 &hist, bool normX=false);
Expand All @@ -195,15 +195,15 @@ template <typename T, typename U=Double_t> class FastHisto_t : public FastTempla
else this->CopyValues(other);
return *this;
}
FastHisto_t<T,U>& operator=(const TH1 &other) {
FastHisto_t<T,U>& operator=(const TH1 &other) override {
if ((int)this->size() != other.GetNbinsX()) {
FastHisto_t<T,U> fh(other);
swap(fh);
}
else this->CopyValues(other);
return *this;
}
~FastHisto_t(){}
~FastHisto_t() override {}
};
template <typename T, typename U=Double_t> class FastHisto2D_t : public FastTemplate_t<T> {
private:
Expand Down Expand Up @@ -260,7 +260,7 @@ template <typename T, typename U=Double_t> class FastHisto2D_t : public FastTemp
// For each X, normalize along Y
void NormalizeXSlices() ;

void Dump() const ;
void Dump() const override ;

T GetMaxOnXY() const ;
T GetMaxOnX(const U &y) const ;
Expand All @@ -281,7 +281,7 @@ template <typename T, typename U=Double_t> class FastHisto2D_t : public FastTemp
else this->CopyValues(other);
return *this;
}
FastHisto2D_t& operator=(const TH1 &other) {
FastHisto2D_t& operator=(const TH1 &other) override {
if(other.GetDimension() != 2) {
throw std::invalid_argument("FastHisto2D_t assignment error: right hand histogram must be 2-dimensional");
}
Expand All @@ -292,7 +292,7 @@ template <typename T, typename U=Double_t> class FastHisto2D_t : public FastTemp
else this->CopyValues(other);
return *this;
}
~FastHisto2D_t(){}
~FastHisto2D_t() override {}
};

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

void Dump() const ;
void Dump() const override ;

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

#include "FastTemplate.hpp"
Expand Down
32 changes: 16 additions & 16 deletions interface/FastTemplateFunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ template <typename T> class FastTemplateFunc_t : public RooAbsReal{
FastTemplateFunc_t() : RooAbsReal(), obsList("obsList", "obsList", this){}
FastTemplateFunc_t(const char *name, const char *title, RooArgList& inObsList) : RooAbsReal(name, title), obsList("obsList", "obsList", this){ setProxyList(obsList, inObsList); }
FastTemplateFunc_t(const FastTemplateFunc_t& other, const char* name=0) : RooAbsReal(other, name), obsList("obsList", this, other.obsList){}
inline ~FastTemplateFunc_t() override{}
inline ~FastTemplateFunc_t() override {}

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

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

Double_t evaluate() const{
Double_t evaluate() const override {
T x = (T)(dynamic_cast<RooAbsReal*>((this->obsList).at(0))->getVal());
Double_t value=tpl.GetAt(x);
return value;
}
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const{
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const override {
Int_t code=1;
const Int_t code_prime[1]={ 2 };
for (int ic=0; ic<(this->obsList).getSize(); ic++){
Expand All @@ -77,7 +77,7 @@ template <typename T, typename U=Double_t> class FastHistoFunc_t : public FastTe
if (code==1) code=0;
return code;
}
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const{
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const override {
if (code==0) return evaluate();
U xmin = (U)(dynamic_cast<RooRealVar*>((this->obsList).at(0))->getMin(rangeName));
U xmax = (U)(dynamic_cast<RooRealVar*>((this->obsList).at(0))->getMax(rangeName));
Expand Down Expand Up @@ -114,19 +114,19 @@ template <typename T, typename U=Double_t> class FastHisto2DFunc_t : public Fast
}
}
FastHisto2DFunc_t(const FastHisto2DFunc_t& other, const char* name=0) : FastTemplateFunc_t<T>(other, name), tpl(other.tpl), fullIntegral(other.fullIntegral){}
~FastHisto2DFunc_t(){}
TObject* clone(const char* newname) const { return new FastHisto2DFunc_t(*this, newname); }
~FastHisto2DFunc_t() override {}
TObject* clone(const char* newname) const override { return new FastHisto2DFunc_t(*this, newname); }

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

Double_t evaluate() const{
Double_t evaluate() const override {
U x = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(0))->getVal());
U y = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(1))->getVal());
Double_t value=tpl.GetAt(x, y);
return value;
}
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const{
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const override {
Int_t code=1;
const Int_t code_prime[2]={ 2, 3 };
for (int ic=0; ic<(this->obsList).getSize(); ic++){
Expand All @@ -139,7 +139,7 @@ template <typename T, typename U=Double_t> class FastHisto2DFunc_t : public Fast
if (code==1) code=0;
return code;
}
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const{
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const override {
if (code==0) return evaluate();
U xmin, xmax, ymin, ymax;
if (code%2==0){
Expand Down Expand Up @@ -206,20 +206,20 @@ template <typename T, typename U=Double_t> class FastHisto3DFunc_t : public Fast
}
}
FastHisto3DFunc_t(const FastHisto3DFunc_t& other, const char* name=0) : FastTemplateFunc_t<T>(other, name), tpl(other.tpl), fullIntegral(other.fullIntegral){}
~FastHisto3DFunc_t(){}
TObject* clone(const char* newname) const { return new FastHisto3DFunc_t(*this, newname); }
~FastHisto3DFunc_t() override {}
TObject* clone(const char* newname) const override { return new FastHisto3DFunc_t(*this, newname); }

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

Double_t evaluate() const{
Double_t evaluate() const override {
U x = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(0))->getVal());
U y = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(1))->getVal());
U z = (U)(dynamic_cast<RooAbsReal*>((this->obsList).at(2))->getVal());
Double_t value=tpl.GetAt(x, y, z);
return value;
}
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const{
Int_t getAnalyticalIntegral(RooArgSet& allVars, RooArgSet& analVars, const char* rangeName=0) const override {
Int_t code=1;
const Int_t code_prime[3]={ 2, 3, 5 };
for (int ic=0; ic<(this->obsList).getSize(); ic++){
Expand All @@ -232,7 +232,7 @@ template <typename T, typename U=Double_t> class FastHisto3DFunc_t : public Fast
if (code==1) code=0;
return code;
}
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const{
Double_t analyticalIntegral(Int_t code, const char* rangeName=0) const override {
if (code==0) return evaluate();
U xmin, xmax, ymin, ymax, zmin, zmax;
if (code%2==0){
Expand Down
16 changes: 9 additions & 7 deletions interface/FitDiagnostics.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ class FitDiagnostics : public FitterAlgoBase {
int fitStatus_, numbadnll_;
double mu_, muErr_, muLoErr_, muHiErr_, nll_nll0_, nll_bonly_, nll_sb_;
std::unique_ptr<TFile> fitOut;
double* globalObservables_;
double* nuisanceParameters_;
double* processNormalizations_;
double* processNormalizationsShapes_;
double* globalObservables_ = nullptr;
double* nuisanceParameters_ = nullptr;
double* processNormalizations_ = nullptr;
double* processNormalizationsShapes_ = nullptr;

TTree *t_fit_b_ = nullptr;
TTree *t_fit_sb_ = nullptr;
TTree *t_prefit_ = nullptr;

TTree *t_fit_b_, *t_fit_sb_, *t_prefit_;

void getNormalizationsSimple(RooAbsPdf *pdf, const RooArgSet &obs, RooArgSet &out);
void createFitResultTrees(const RooStats::ModelConfig &,bool,bool);
void resetFitResultTrees(bool);
Expand Down Expand Up @@ -112,7 +114,7 @@ class FitDiagnostics : public FitterAlgoBase {
const RooAbsCollection & centralValues() override;
private:
RooAbsPdf *pdf_;
RooAbsData *data_;
RooAbsData *data_ = nullptr;
RooArgSet snapshot_;
};
};
Expand Down
6 changes: 3 additions & 3 deletions interface/FnTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ class FnTimer {

private:
std::string name_;
unsigned calls_;
unsigned calls_ = 0;
std::chrono::time_point<std::chrono::high_resolution_clock> start_;
std::chrono::time_point<std::chrono::high_resolution_clock> end_;
double elapsed_;
double elapsed_overhead_;
double elapsed_ = 0.;
double elapsed_overhead_ = 0.;
};


Expand Down
Loading

0 comments on commit d832875

Please sign in to comment.