Skip to content

Commit

Permalink
enable warning if not all enums are used
Browse files Browse the repository at this point in the history
  • Loading branch information
KSkwarczynski committed Feb 10, 2025
1 parent 96d89d2 commit b387a5a
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ target_compile_options(MaCh3Warnings INTERFACE
-Wconversion # Warn on type conversions that may lose data
-Wformat-security # Warn on functions that are potentially insecure for formatting
-Walloca # Warn if `alloca` is used, as it can lead to stack overflows
#-Wswitch-enum # Warn if a `switch` statement on an enum does not cover all values
-Wswitch-enum # Warn if a `switch` statement on an enum does not cover all values
#-Wfloat-equal # Warn if floating-point values are compared directly
#-Wpadded # Warn when padding is added to a structure or class for alignment
)
Expand Down
15 changes: 8 additions & 7 deletions manager/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
/// @author Kamil Skwarczynski
/// @author Luke Pickering

// C++ includes
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
/// Run low or high memory versions of structs
/// N.B. for 64 bit systems sizeof(float) == sizeof(double) so not a huge effect
namespace M3 {
Expand Down Expand Up @@ -62,13 +69,6 @@ namespace M3 {
/// Number of overflow bins in TH2Poly,
#define _TH2PolyOverflowBins_ 9

// C++ includes
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
#include <iomanip>

#ifdef MULTITHREAD
#include "omp.h"
#endif
Expand All @@ -83,6 +83,7 @@ _Pragma("GCC diagnostic ignored \"-Wuseless-cast\"") \
_Pragma("GCC diagnostic ignored \"-Wfloat-conversion\"") \
_Pragma("GCC diagnostic ignored \"-Wold-style-cast\"") \
_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"") \
_Pragma("GCC diagnostic ignored \"-Wswitch-enum\"") \
_Pragma("GCC diagnostic ignored \"-Wconversion\"")

/// @brief KS: Restore warning checking after including external headers
Expand Down
12 changes: 8 additions & 4 deletions manager/MaCh3Logger.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#pragma once

// spdlog Includes
#include "spdlog/spdlog.h"

// C++ Includes
#include <iostream>
#include <sstream>
#include <functional>
#include <string>

#include <exception>

// MaCh3 Includes
#include "manager/Core.h"

_MaCh3_Safe_Include_Start_ //{
// spdlog Includes
#include "spdlog/spdlog.h"
_MaCh3_Safe_Include_End_ //}

/// @file MaCh3Logger.h
/// @brief KS: Based on this https://github.com/gabime/spdlog/blob/a2b4262090fd3f005c2315dcb5be2f0f1774a005/include/spdlog/spdlog.h#L284

Expand Down
3 changes: 3 additions & 0 deletions mcmc/SampleSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,9 @@ void SampleSummary::StudyInformationCriterion(M3::kInfCrit Criterion) {
// Study Watanabe-Akaike information criterion (WAIC)
StudyWAIC();
break;
case M3::kInfCrit::kInfCrits:
MACH3LOG_ERROR("kInfCrits is not a valid kInfCrit!");
throw MaCh3Exception(__FILE__, __LINE__);
default:
MACH3LOG_ERROR("UNKNOWN Information Criterion SPECIFIED!");
MACH3LOG_ERROR("You gave {}", static_cast<int>(Criterion));
Expand Down
3 changes: 2 additions & 1 deletion plotting/plottingUtils/inputManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ class InputManager {
return "MCMC";
case kSigmaVar:
return "SigmaVar";

case kNFileTypes:
return "NFileTypes";
default:
return "UNKNOWN_FILE_TYPE";
}
Expand Down
42 changes: 28 additions & 14 deletions samplePDF/Structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ inline std::string GetTF1(const SplineInterpolation i) {
case SplineInterpolation::kLinearFunc:
Func = "([1]+[0]*x)";
break;
case SplineInterpolation::kTSpline3:
case SplineInterpolation::kLinear:
case SplineInterpolation::kMonotonic:
case SplineInterpolation::kAkima:
case SplineInterpolation::kSplineInterpolations:
MACH3LOG_ERROR("Interpolation type {} not supported for TF1!", static_cast<int>(i));
throw MaCh3Exception(__FILE__, __LINE__);
default:
MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
Expand All @@ -159,27 +166,22 @@ inline RespFuncType SplineInterpolation_ToRespFuncType(const SplineInterpolation
// **************************************************
RespFuncType Type = kRespFuncTypes;
switch(i) {
// TSpline3 (third order spline in ROOT)
case SplineInterpolation::kTSpline3:
Type = RespFuncType::kTSpline3_red;
break;
case SplineInterpolation::kLinear:
Type = RespFuncType::kTSpline3_red;
break;
case SplineInterpolation::kMonotonic:
Type = RespFuncType::kTSpline3_red;
break;
// (Experimental) Akima_Spline (crd order spline which is allowed to be discontinuous in 2nd deriv)
case SplineInterpolation::kAkima:
Type = RespFuncType::kTSpline3_red;
break;
case SplineInterpolation::kLinearFunc:
Type = RespFuncType::kTF1_red;
break;
case SplineInterpolation::kSplineInterpolations:
MACH3LOG_ERROR("kSplineInterpolations is not a valid interpolation type!");
throw MaCh3Exception(__FILE__, __LINE__);
default:
MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
throw MaCh3Exception(__FILE__ , __LINE__ );
throw MaCh3Exception(__FILE__, __LINE__);
}
return Type;
}
Expand Down Expand Up @@ -207,6 +209,9 @@ inline std::string SplineInterpolation_ToString(const SplineInterpolation i) {
case SplineInterpolation::kLinearFunc:
name = "LinearFunc";
break;
case SplineInterpolation::kSplineInterpolations:
MACH3LOG_ERROR("kSplineInterpolations is not a valid interpolation type!");
throw MaCh3Exception(__FILE__, __LINE__);
default:
MACH3LOG_ERROR("UNKNOWN SPLINE INTERPOLATION SPECIFIED!");
MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
Expand Down Expand Up @@ -255,6 +260,9 @@ inline std::string SystType_ToString(const SystType i) {
case SystType::kFunc:
name = "Functional";
break;
case SystType::kSystTypes:
MACH3LOG_ERROR("kSystTypes is not a valid SystType!");
throw MaCh3Exception(__FILE__, __LINE__);
default:
MACH3LOG_ERROR("UNKNOWN SYST TYPE SPECIFIED!");
MACH3LOG_ERROR("You gave {}", static_cast<int>(i));
Expand Down Expand Up @@ -300,6 +308,9 @@ inline std::string TargetMat_ToString(const TargetMat i) {
case kTarget_Al:
name = "Aluminium";
break;
case kTarget_Ar:
name = "Argon";
break;
case kTarget_Ti:
name = "Titanium";
break;
Expand Down Expand Up @@ -419,21 +430,24 @@ inline std::string TestStatistic_ToString(TestStatistic i) {
std::string name = "";

switch(i) {
case kPoisson:
case TestStatistic::kPoisson:
name = "Poisson";
break;
case kBarlowBeeston:
case TestStatistic::kBarlowBeeston:
name = "BarlowBeeston";
break;
case kIceCube:
case TestStatistic::kIceCube:
name = "IceCube";
break;
case kPearson:
case TestStatistic::kPearson:
name = "Pearson";
break;
case kDembinskiAbdelmottele:
case TestStatistic::kDembinskiAbdelmottele:
name = "DembinskiAbdelmottele";
break;
case TestStatistic::kNTestStatistics:
MACH3LOG_ERROR("kNTestStatistics is not a valid TestStatistic!");
throw MaCh3Exception(__FILE__, __LINE__);
default:
MACH3LOG_ERROR("UNKNOWN LIKELIHOOD SPECIFIED!");
MACH3LOG_ERROR("You gave test-statistic {}", static_cast<int>(i));
Expand Down
30 changes: 14 additions & 16 deletions samplePDF/samplePDFBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void samplePDFBase::addData(std::vector<double> &data)
{
if(nDims != 0 && nDims != 1)
{
std::cerr<<"You have initialised this sample with "<<nDims<<" dimensions already and now trying to set dimentison to 1"<<std::endl;
MACH3LOG_ERROR("You have initialized this sample with {} dimensions already and now trying to set dimension to 1", nDims);
throw MaCh3Exception(__FILE__, __LINE__);
}
nDims = 1;
Expand All @@ -38,8 +38,7 @@ void samplePDFBase::addData(std::vector< std::vector <double> > &data)
{
if(nDims != 0 && nDims != 2)
{
std::cerr<<"You have initialised this sample with "<<nDims<<" dimensions already and now trying to set dimentison to 2"<<std::endl;
std::cerr<<"This will not work, you can find me here "<< __FILE__ << ":" << __LINE__ << std::endl;
MACH3LOG_ERROR("You have initialized this sample with {} dimensions already and now trying to set dimension to 2", nDims);
throw MaCh3Exception(__FILE__, __LINE__);
}
nDims = 2;
Expand All @@ -57,12 +56,11 @@ void samplePDFBase::addData(TH1D* binneddata)
{
if(nDims != 0 && nDims != 1)
{
std::cerr<<"You have initialised this sample with "<<nDims<<" dimensions already and now trying to set dimentison to 1"<<std::endl;
std::cerr<<"This will not work, you can find me here "<< __FILE__ << ":" << __LINE__ << std::endl;
MACH3LOG_ERROR("You have initialized this sample with {} dimensions already and now trying to set dimension to 1", nDims);
throw MaCh3Exception(__FILE__, __LINE__);
}
nDims = 1;
std::cout << "adding 1D data histogram : " << binneddata -> GetName() << " with " << binneddata->Integral() << " events." << std::endl;
MACH3LOG_INFO("Adding 1D data histogram: {} with {} events.", binneddata->GetName(), binneddata->Integral());
//KS: If exist delete to avoid memory leak
if(dathist != NULL) delete dathist;
dathist = binneddata;
Expand All @@ -72,12 +70,11 @@ void samplePDFBase::addData(TH2D* binneddata)
{
if(nDims != 0 && nDims != 2)
{
std::cerr<<"You have initialised this sample with "<<nDims<<" dimensions already and now trying to set dimentison to 2"<<std::endl;
std::cerr<<"This will not work, you can find me here "<< __FILE__ << ":" << __LINE__ << std::endl;
throw;
MACH3LOG_ERROR("You have initialized this sample with {} dimensions already and now trying to set dimension to 2", nDims);
throw MaCh3Exception(__FILE__, __LINE__);
}
nDims = 2;
std::cout << "adding 2D data histogram : " << binneddata -> GetName() << " with " << binneddata->Integral() << " events." << std::endl;
MACH3LOG_INFO("Adding 2D data histogram: {} with {} events.", binneddata->GetName(), binneddata->Integral());
//KS: If exist delete to avoid memory leak
if(dathist2d != NULL) delete dathist;
dathist2d = binneddata;
Expand Down Expand Up @@ -105,8 +102,8 @@ double samplePDFBase::getTestStatLLH(const double data, const double mc) const {
double negLogL = 0;
if(mc > 0 && data > 0)
{
//http://hyperphysics.phy-astr.gsu.edu/hbase/math/stirling.html
negLogL += (mc - data + data * std::log(data/mc));
//http://hyperphysics.phy-astr.gsu.edu/hbase/math/stirling.html
negLogL += (mc - data + data * std::log(data/mc));
}
else if(mc > 0 && data == 0) negLogL += mc;

Expand All @@ -117,7 +114,6 @@ double samplePDFBase::getTestStatLLH(const double data, const double mc) const {
// data is data, mc is mc, w2 is Sum(w_{i}^2) (sum of weights squared), which is sigma^2_{MC stats}
double samplePDFBase::getTestStatLLH(const double data, const double mc, const double w2) const {
// *************************

// Need some MC
if (mc == 0) return 0.0;

Expand Down Expand Up @@ -243,9 +239,11 @@ double samplePDFBase::getTestStatLLH(const double data, const double mc, const d
return getTestStatLLH(data, mc);//stat;
}
break;

case TestStatistic::kNTestStatistics:
MACH3LOG_ERROR("kNTestStatistics is not a valid TestStatistic!");
throw MaCh3Exception(__FILE__, __LINE__);
default:
std::cerr << "Couldn't find TestStatistic " << fTestStatistic << " exiting!" << std::endl;
MACH3LOG_ERROR("Couldn't find TestStatistic {} exiting!", static_cast<int>(fTestStatistic));
throw MaCh3Exception(__FILE__ , __LINE__ );
} // end switch
}
Expand All @@ -256,7 +254,7 @@ std::string samplePDFBase::GetSampleName(int Sample) {
// ***************************************************************************
if(Sample > nSamples)
{
std::cerr<<" You are asking for sample "<< Sample <<" I only have "<< nSamples<<std::endl;
MACH3LOG_ERROR("You are asking for sample {}. I only have {}", Sample, nSamples);
throw MaCh3Exception(__FILE__ , __LINE__ );
}

Expand Down

0 comments on commit b387a5a

Please sign in to comment.