From 216e102bc45630164f05ae8b361d27a546ee215f Mon Sep 17 00:00:00 2001 From: Frank Winklmeier <frank.winklmeier@cern.ch> Date: Wed, 20 Nov 2024 16:04:07 +0100 Subject: [PATCH] RatesAnalysis: fix cppcheck defects Use `starts_with`, `try_emplace`, remove unused variables and fix uninitialized ones. --- .../RatesAnalysis/RatesAnalysisAlg.h | 4 ++-- .../RatesAnalysis/RatesHistoBase.h | 11 ++++------ .../RatesAnalysis/src/RatesAnalysisAlg.cxx | 20 ++++++++++--------- .../RatesAnalysis/src/RatesHistoBase.cxx | 3 +-- .../RatesAnalysis/src/RatesScanTrigger.cxx | 6 ++---- .../RatesAnalysis/src/RatesTrigger.cxx | 4 +++- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/Trigger/TrigCost/RatesAnalysis/RatesAnalysis/RatesAnalysisAlg.h b/Trigger/TrigCost/RatesAnalysis/RatesAnalysis/RatesAnalysisAlg.h index 33c15c1941a6..bfd38fbbcbaa 100644 --- a/Trigger/TrigCost/RatesAnalysis/RatesAnalysis/RatesAnalysisAlg.h +++ b/Trigger/TrigCost/RatesAnalysis/RatesAnalysis/RatesAnalysisAlg.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef RATESANALYSIS_RATESANALYSISALG_H @@ -130,7 +130,7 @@ class RatesAnalysisAlg: public ::AthAnalysisAlgorithm { * @brief Register some existing triggers based on wild-card match, e.g. "L1_.*" for all L1. * @param pattern Wild-card string to match in trigger name */ - StatusCode addExisting(const std::string pattern); + StatusCode addExisting(const std::string& pattern); /** * Set the pass/fail decision for an item. diff --git a/Trigger/TrigCost/RatesAnalysis/RatesAnalysis/RatesHistoBase.h b/Trigger/TrigCost/RatesAnalysis/RatesAnalysis/RatesHistoBase.h index 9976e9107fc0..6eff1b488ef8 100644 --- a/Trigger/TrigCost/RatesAnalysis/RatesAnalysis/RatesHistoBase.h +++ b/Trigger/TrigCost/RatesAnalysis/RatesAnalysis/RatesHistoBase.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #ifndef RATESANALYSIS_RATESHISTOBASE_H @@ -110,12 +110,9 @@ class RatesHistoBase : public AthMessaging { std::unique_ptr<TH1> m_rateVsMu; //!< Histogram of rate as a fn. of the input event's mu std::unique_ptr<TH1> m_rateVsTrain; //!< Histogram of rate as a fn. of position in bunch train std::unique_ptr<TH1> m_data; //!< Histogram of raw rates quantites, for when we need to normalise offline (e.g. grid processing) - TH1* m_rateVsMuCachedPtr; //!< Cached, non-owning pointer - TH1* m_rateVsTrainCachedPtr; //!< Cached, non-owning pointer - TH1* m_dataCachedPtr; //!< Cached, non-owning pointer - bool m_givenRateVsMu; //!< m_rateVsMu has been given to the THistSvc and should not be deleted - bool m_givenRateVsTrain; //!< m_rateVsTrain has been given to the THistSvc and should not be deleted - bool m_givenData; //!< m_data has been given to the THistSvc and should not be deleted + TH1* m_rateVsMuCachedPtr{}; //!< Cached, non-owning pointer + TH1* m_rateVsTrainCachedPtr{}; //!< Cached, non-owning pointer + TH1* m_dataCachedPtr{}; //!< Cached, non-owning pointer }; #endif //> !RATESANALYSIS_RATESHISTOBASE_H diff --git a/Trigger/TrigCost/RatesAnalysis/src/RatesAnalysisAlg.cxx b/Trigger/TrigCost/RatesAnalysis/src/RatesAnalysisAlg.cxx index 1a1f36277aed..c92ecf49b7b0 100644 --- a/Trigger/TrigCost/RatesAnalysis/src/RatesAnalysisAlg.cxx +++ b/Trigger/TrigCost/RatesAnalysis/src/RatesAnalysisAlg.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ // RatesAnalysis includes @@ -31,7 +31,8 @@ RatesAnalysisAlg::RatesAnalysisAlg( const std::string& name, ISvcLocator* pSvcLo m_weightedEventCounter(0), m_scalingHist(nullptr), m_bcidHist(nullptr), - m_metadataTree(nullptr) + m_metadataTree(nullptr), + m_weightingValues() {} RatesAnalysisAlg::~RatesAnalysisAlg() {} @@ -151,20 +152,21 @@ StatusCode RatesAnalysisAlg::newTrigger(const std::string& name, if (m_doTriggerGroups) { for (const std::string& group : groups) { // Ignore BW and PS groups - if (group.find("BW") == 0 || group.find("PS") == 0 || group.find("STREAM:express") == 0) continue; - if (m_groups.count(group) == 0) { - m_groups.emplace(group, std::make_unique<RatesGroup>(group, msgSvc(), m_doHistograms, m_enableLumiExtrapolation)); + if (group.starts_with("BW") || group.starts_with("PS") || group.starts_with("STREAM:express")) continue; + + const auto [it, inserted] = m_groups.try_emplace(group, std::make_unique<RatesGroup>(group, msgSvc(), m_doHistograms, m_enableLumiExtrapolation)); + if (inserted) { // As the group is formed from at least one active trigger - it must be active itself (counter example - CPS group of a PS=-1 trigger) - m_activeGroups.insert( m_groups.at(group).get() ); + m_activeGroups.insert( it->second.get() ); } - m_groups.at(group)->addToGroup( newTriggerPtr ); + it->second->addToGroup( newTriggerPtr ); // For CPS, we let the trigger know that it is special if (isCPS(group)) { if (newTriggerPtr->getCPSID() != 0) ATH_MSG_WARNING("Trigger " << name << " can only be in one coherent prescale group."); newTriggerPtr->setCPS(group); // This changes the CPSID const size_t CPSID = newTriggerPtr->getCPSID(); // Find the lowest prescale of any member in this CPS group - if (m_lowestPrescale.count(CPSID) == 0) m_lowestPrescale[CPSID] = FLT_MAX; + m_lowestPrescale.try_emplace(CPSID, FLT_MAX); if (prescale < m_lowestPrescale[CPSID]) m_lowestPrescale[CPSID] = prescale; } } @@ -191,7 +193,7 @@ StatusCode RatesAnalysisAlg::addAllExisting() { return addExisting(".*"); } -StatusCode RatesAnalysisAlg::addExisting(const std::string pattern) { +StatusCode RatesAnalysisAlg::addExisting(const std::string& pattern) { // Check we have the TDT ATH_CHECK(checkGotTDT()); diff --git a/Trigger/TrigCost/RatesAnalysis/src/RatesHistoBase.cxx b/Trigger/TrigCost/RatesAnalysis/src/RatesHistoBase.cxx index 96303d0bd3d3..24ee936eba6b 100644 --- a/Trigger/TrigCost/RatesAnalysis/src/RatesHistoBase.cxx +++ b/Trigger/TrigCost/RatesAnalysis/src/RatesHistoBase.cxx @@ -10,8 +10,7 @@ RatesHistoBase::RatesHistoBase(const std::string& name, IMessageSvc* msgSvc, const bool doHistograms) : AthMessaging(msgSvc, name), m_name(name), - m_doHistograms(doHistograms), m_rateVsMu(nullptr), m_rateVsTrain(nullptr), m_data(nullptr), - m_rateVsMuCachedPtr(nullptr), m_rateVsTrainCachedPtr(nullptr), m_dataCachedPtr(nullptr) + m_doHistograms(doHistograms) { if (doHistograms) { m_rateVsMu = std::make_unique<TH1D>("",TString(name + ";#mu;Rate / Unit #mu [Hz]"),226,-.5,225.5); diff --git a/Trigger/TrigCost/RatesAnalysis/src/RatesScanTrigger.cxx b/Trigger/TrigCost/RatesAnalysis/src/RatesScanTrigger.cxx index a48f20b24ac8..8a4443b7b6b4 100644 --- a/Trigger/TrigCost/RatesAnalysis/src/RatesScanTrigger.cxx +++ b/Trigger/TrigCost/RatesAnalysis/src/RatesScanTrigger.cxx @@ -15,12 +15,10 @@ RatesScanTrigger::RatesScanTrigger( const std::string& name, const std::string& seedName, const double seedPrescale, const ExtrapStrat_t extrapolation) : RatesTrigger(name, msgSvc, prescale, -1, seedName, seedPrescale, /*base histograms*/false, extrapolation), - m_rateScanHist(nullptr), m_rateScanHistCachedPtr(nullptr), m_thresholdPassed(0), m_behaviour(behaviour) + m_rateScanHist(std::make_unique<TH1D>("", TString(name + ";Threshold;Rate [Hz]"), thresholdBins, thresholdMin, thresholdMax)), + m_rateScanHistCachedPtr(m_rateScanHist.get()), m_thresholdPassed(0), m_behaviour(behaviour) { - m_rateScanHist = std::make_unique<TH1D>("", TString(name + ";Threshold;Rate [Hz]"), thresholdBins, thresholdMin, thresholdMax); m_rateScanHist->Sumw2(true); - - m_rateScanHistCachedPtr = m_rateScanHist.get(); } RatesScanTrigger::RatesScanTrigger( const std::string& name, diff --git a/Trigger/TrigCost/RatesAnalysis/src/RatesTrigger.cxx b/Trigger/TrigCost/RatesAnalysis/src/RatesTrigger.cxx index 93594c5316da..484ebe07429a 100644 --- a/Trigger/TrigCost/RatesAnalysis/src/RatesTrigger.cxx +++ b/Trigger/TrigCost/RatesAnalysis/src/RatesTrigger.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration */ #include "RatesAnalysis/RatesTrigger.h" @@ -16,6 +16,8 @@ RatesTrigger::RatesTrigger(const std::string& name, IMessageSvc* msgSvc, const d m_rateAccumulator2(0.), m_rateExpressAccumulator(0.), m_rateExpressAccumulator2(0.), + m_ratesActive(0.), + m_ratesActive2(0.), m_CPSID(0), m_coherentFactor(0.), m_uniqueGroup(nullptr), -- GitLab