From ccabf0b5fa10a6342e99f2af9e5521059e03e7a0 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Tue, 5 Nov 2024 13:29:48 +0000 Subject: [PATCH 1/2] some safety to be case insentivie after Luke comment --- CMakeLists.txt | 14 ++++++++------ covariance/covarianceXsec.cpp | 9 +++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7b1b7c5e..cef69e882 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,10 +88,14 @@ target_compile_options(MaCh3Warnings INTERFACE -Wredundant-decls # Warn about multiple declarations of the same entity. Useful for code cleanup. -Wstrict-aliasing=2 # Helps detect potential aliasing issues that could lead to undefined behavior. -Wuseless-cast # Warn if you perform a cast to the same type (only in GCC >= 4.8) - # -Wpadded # Warn when padding is added to a structure or class for alignment - -Wnull-dereference # Warn if a null dereference is detected (only in GCC >= 6.0) - -Wold-style-cast # Warn for c-style casts - -Wconversion # Warn on type conversions that may lose data + -Wnull-dereference # Warn if a null dereference is detected (only in GCC >= 6.0) + -Wold-style-cast # Warn for c-style casts + -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 + #-Wfloat-equal # Warn if floating-point values are compared directly + #-Wpadded # Warn when padding is added to a structure or class for alignment ) # KS Some compiler options are only available in GCC, in case we move to other compilers we will have to expand this if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") @@ -223,8 +227,6 @@ if (MaCh3_PYTHON_ENABLED) add_subdirectory(python) endif() - - #This is to export the target properties of MaCh3 #Anything that links to "MaCh3" will get all of these target properties add_library(MaCh3 INTERFACE) diff --git a/covariance/covarianceXsec.cpp b/covariance/covarianceXsec.cpp index fa503a3b4..3bee92a81 100644 --- a/covariance/covarianceXsec.cpp +++ b/covariance/covarianceXsec.cpp @@ -515,9 +515,14 @@ void covarianceXsec::SetGroupOnlyParameters(const std::string& Group) { // Checks if parameter belongs to a given group bool covarianceXsec::IsParFromGroup(const int i, const std::string& Group) { // ******************************************** + std::string groupLower = Group; + std::string paramGroupLower = _ParameterGroup[i]; - if(Group == _ParameterGroup[i]) return true; - else return false; + // KS: Convert both strings to lowercase, this way comparison will be case insensitive + std::transform(groupLower.begin(), groupLower.end(), groupLower.begin(), ::tolower); + std::transform(paramGroupLower.begin(), paramGroupLower.end(), paramGroupLower.begin(), ::tolower); + + return groupLower == paramGroupLower; } // ******************************************** From 00af9e81bdb4dffc2ab77083f24f2be2337e86c8 Mon Sep 17 00:00:00 2001 From: Kamil Skwarczynski Date: Tue, 5 Nov 2024 13:41:26 +0000 Subject: [PATCH 2/2] remove some reprition realted with DetId --- covariance/covarianceXsec.cpp | 8 ++++---- covariance/covarianceXsec.h | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/covariance/covarianceXsec.cpp b/covariance/covarianceXsec.cpp index 3bee92a81..2dec5c917 100644 --- a/covariance/covarianceXsec.cpp +++ b/covariance/covarianceXsec.cpp @@ -201,7 +201,7 @@ const std::vector covarianceXsec::GetGlobalSystIndexFromDetID(const int Det std::vector returnVec; for (auto &pair : _fSystToGlobalSystIndexMap[Type]) { auto &SystIndex = pair.second; - if ((GetParDetID(SystIndex) & DetID)) { //If parameter applies to required DetID + if (AppliesToDetID(SystIndex, DetID)) { //If parameter applies to required DetID returnVec.push_back(SystIndex); } } @@ -216,8 +216,8 @@ const std::vector covarianceXsec::GetSystIndexFromDetID(int DetID, const S std::vector returnVec; for (auto &pair : _fSystToGlobalSystIndexMap[Type]) { auto &SplineIndex = pair.first; - auto &SystIndex = pair.second; - if ((GetParDetID(SystIndex) & DetID)) { //If parameter applies to required DetID + auto &systIndex = pair.second; + if (AppliesToDetID(systIndex, DetID)) { //If parameter applies to required DetID returnVec.push_back(SplineIndex); } } @@ -306,7 +306,7 @@ template void covarianceXsec::IterateOverParams(const int DetID, FilterFunc filter, ActionFunc action) { // ******************************************** for (int i = 0; i < _fNumPar; ++i) { - if ((GetParDetID(i) & DetID) && filter(i)) { // Common filter logic + if ((AppliesToDetID(i, DetID)) && filter(i)) { // Common filter logic action(i); // Specific action for each function } } diff --git a/covariance/covarianceXsec.h b/covariance/covarianceXsec.h index 0936cc362..1dd61affa 100644 --- a/covariance/covarianceXsec.h +++ b/covariance/covarianceXsec.h @@ -127,7 +127,12 @@ class covarianceXsec : public covarianceBase { /// @param DetID The Detector ID used to filter parameters. template void IterateOverParams(const int DetID, FilterFunc filter, ActionFunc action); - + /// @brief Check if parameter is affecting given det ID + /// @param SystIndex number of parameter + /// @param DetID The Detector ID used to filter parameters. + bool AppliesToDetID(const int SystIndex, const int DetID) const { + return (GetParDetID(SystIndex) & DetID) != 0; + } /// @brief Initializes the systematic parameters from the configuration file. /// This function loads parameters like normalizations and splines from the provided YAML file. /// @note This is used internally during the object's initialization process.