From 8398024d17d69f104696ab396eb287383923329e Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Wed, 16 Oct 2019 16:14:23 +0200 Subject: [PATCH] TrigDecisionTool: Fix cppcheck warnings. - Redundant map lookup. - Pass std::string by const reference, not value. - Prefer preincrement to postincrement for iterators. --- .../TrigDecisionTool/Root/CacheGlobalMemory.cxx | 15 ++++++++------- .../TrigDecisionTool/Root/ChainGroup.cxx | 6 +++--- .../TrigDecisionTool/ChainGroup.h | 6 +++--- .../TrigDecisionTool/ChainGroup.icc | 4 ++-- .../TrigDecisionTool/DecisionAccess.h | 10 +++++----- .../TrigDecisionTool/DecisionAccess.icc | 8 ++++---- 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Trigger/TrigAnalysis/TrigDecisionTool/Root/CacheGlobalMemory.cxx b/Trigger/TrigAnalysis/TrigDecisionTool/Root/CacheGlobalMemory.cxx index 12d1f837446..9725b0beeab 100644 --- a/Trigger/TrigAnalysis/TrigDecisionTool/Root/CacheGlobalMemory.cxx +++ b/Trigger/TrigAnalysis/TrigDecisionTool/Root/CacheGlobalMemory.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /********************************************************************************** @@ -86,10 +86,11 @@ const Trig::ChainGroup* Trig::CacheGlobalMemory::createChainGroup(const std::vec // create a proper key std::vector< std::string > key=Trig::keyWrap(triggerNames); - if (m_chainGroups.find(key)==m_chainGroups.end()) { - m_chainGroups[key]=new ChainGroup( key, *this ); - updateChainGroup(m_chainGroups[key]); - m_chainGroupsRef[key]=m_chainGroups[key]; + auto res = m_chainGroups.try_emplace (key, nullptr); + if (res.second) { + res.first->second = new ChainGroup( key, *this ); + updateChainGroup(res.first->second); + m_chainGroupsRef[key] = res.first->second; } // this overwrites the pointer in the map each time in case the alias needs defining if (alias!="") { @@ -205,7 +206,7 @@ void Trig::CacheGlobalMemory::update(const TrigConf::HLTChainList* confChains, } // std::map<std::string, std::vector<std::string> >::iterator mstIt; - for (mstIt=m_streams.begin(); mstIt != m_streams.end(); mstIt++) { + for (mstIt=m_streams.begin(); mstIt != m_streams.end(); ++mstIt) { const std::string alias("STREAM_"+mstIt->first); std::vector< std::string > key_alias=Trig::keyWrap(Trig::convertStringToVector(alias)); ChGrIt preIt = m_chainGroupsRef.find(key_alias); @@ -220,7 +221,7 @@ void Trig::CacheGlobalMemory::update(const TrigConf::HLTChainList* confChains, } } - for (mstIt=m_groups.begin(); mstIt != m_groups.end(); mstIt++) { + for (mstIt=m_groups.begin(); mstIt != m_groups.end(); ++mstIt) { const std::string alias("GROUP_"+mstIt->first); std::vector< std::string > key_alias=Trig::keyWrap(Trig::convertStringToVector(alias)); ChGrIt preIt = m_chainGroupsRef.find(key_alias); diff --git a/Trigger/TrigAnalysis/TrigDecisionTool/Root/ChainGroup.cxx b/Trigger/TrigAnalysis/TrigDecisionTool/Root/ChainGroup.cxx index fadc62c56ff..5ebf66333df 100644 --- a/Trigger/TrigAnalysis/TrigDecisionTool/Root/ChainGroup.cxx +++ b/Trigger/TrigAnalysis/TrigDecisionTool/Root/ChainGroup.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /********************************************************************************** @@ -222,7 +222,7 @@ bool Trig::ChainGroup::isPassed(unsigned int condition) const std::vector<std::string> triggers = getListOfTriggers(); const std::vector<std::string>& express_names = expressStream->linkColNames(); std::vector<std::string>::const_iterator p1, p2; - for (p1=triggers.begin(); p1!=triggers.end(); p1++) { + for (p1=triggers.begin(); p1!=triggers.end(); ++p1) { for (p2=express_names.begin(); p2!=express_names.end(); ++p2) { if ( (*p1) == (*p2) ) { //essentially implements a OR across all triggers in the CG (as is done upstream) @@ -642,7 +642,7 @@ Trig::ChainGroup::update(const TrigConf::HLTChainList* confChains, if (!(confChains && confItems) ) return; for(std::vector< std::string >::const_iterator it = m_patterns.begin(); - it != m_patterns.end(); it++) { + it != m_patterns.end(); ++it) { // find chains matching pattern boost::regex compiled(*it); boost::cmatch what; diff --git a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/ChainGroup.h b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/ChainGroup.h index 3eb835c0325..e0d518468eb 100644 --- a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/ChainGroup.h +++ b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/ChainGroup.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef TRIGGER_DECISION_TOOL_CHAIN_GROUP_H @@ -128,9 +128,9 @@ namespace Trig { template<class CONTAINER> std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > features(EventPtr_t eventStore, unsigned int condition = TrigDefs::Physics, - const std::string container = "", + const std::string& container = "", const unsigned int featureCollectionMode = TrigDefs::oneFeaturePerLeg, - const std::string featureName = "feature") const; + const std::string& featureName = "feature") const; // const std::vector< std::string >& patterns() const {return m_patterns;} diff --git a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/ChainGroup.icc b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/ChainGroup.icc index 55c63dd2345..b707eb4989c 100644 --- a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/ChainGroup.icc +++ b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/ChainGroup.icc @@ -1,7 +1,7 @@ template<class CONTAINER> std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > Trig::ChainGroup::features(EventPtr_t eventStore, - unsigned int condition, const std::string container, - const unsigned int featureCollectionMode, const std::string featureName) const { + unsigned int condition, const std::string& container, + const unsigned int featureCollectionMode, const std::string& featureName) const { bool errState = false; diff --git a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/DecisionAccess.h b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/DecisionAccess.h index 22bb65723c3..edfd8d0342c 100644 --- a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/DecisionAccess.h +++ b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/DecisionAccess.h @@ -1,7 +1,7 @@ // -*- c++ -*- /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef TRIGGER_DECISION_TOOL_DecisionAccess_H @@ -117,9 +117,9 @@ namespace Trig { template<class CONTAINER> std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > features(const Trig::ChainGroup* group, const unsigned int condition = TrigDefs::Physics, - const std::string container = "", + const std::string& container = "", const unsigned int featureCollectionMode = TrigDefs::oneFeaturePerLeg, - const std::string featureName = "feature") const; + const std::string& featureName = "feature") const; /** * @brief Runs 3+. Returns features related to given chain @@ -133,9 +133,9 @@ namespace Trig { template<class CONTAINER> std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > features(const std::string& chainName = "HLT_.*", const unsigned int condition = TrigDefs::Physics, - const std::string container = "", + const std::string& container = "", const unsigned int featureCollectionMode = TrigDefs::oneFeaturePerLeg, - const std::string featureName = "feature") const; + const std::string& featureName = "feature") const; /** * @brief gives back feature matching (by seeding relation) diff --git a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/DecisionAccess.icc b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/DecisionAccess.icc index f19fc60cb2d..13b59e5bd82 100644 --- a/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/DecisionAccess.icc +++ b/Trigger/TrigAnalysis/TrigDecisionTool/TrigDecisionTool/DecisionAccess.icc @@ -46,9 +46,9 @@ const std::vector<Trig::Feature<T> > Trig::DecisionAccess::ancestors(const HLT:: template<class CONTAINER> std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > Trig::DecisionAccess::features(const Trig::ChainGroup* group, const unsigned int condition, - const std::string container, + const std::string& container, const unsigned int featureCollectionMode, - const std::string featureName) const { + const std::string& featureName) const { // const TrigCompositeUtils::DecisionContainer* terminusNode = SG::get(m_HLTSummaryKeyIn/*, context*/); return group->features<CONTAINER>(cgm()->store(), condition, container, featureCollectionMode, featureName); } @@ -56,9 +56,9 @@ std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > Trig::DecisionAccess::fea template<class CONTAINER> std::vector< TrigCompositeUtils::LinkInfo<CONTAINER> > Trig::DecisionAccess::features(const std::string& chainName, const unsigned int condition, - const std::string container, + const std::string& container, const unsigned int featureCollectionMode, - const std::string featureName) const { + const std::string& featureName) const { const Trig::ChainGroup *g = cgm()->createChainGroup(Trig::convertStringToVector(chainName)); return features<CONTAINER>(g, condition, container, featureCollectionMode, featureName); } -- GitLab