From b8699a0434cf4e6a29c257736e01c1bcfee967a4 Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Fri, 19 Jun 2020 15:16:32 +0200 Subject: [PATCH] StoreGate: Fix cppcheck warnings. - Move DataHandle comparison functions inline. - Don't pass large objects by value. --- Control/StoreGate/StoreGate/DataHandle.h | 43 ++++++------------- Control/StoreGate/StoreGate/StoreGate.h | 6 +-- Control/StoreGate/StoreGate/tools/SGImplSvc.h | 8 ++-- Control/StoreGate/src/SGImplSvc.cxx | 10 ++--- Control/StoreGate/src/StoreGate.cxx | 6 +-- Control/StoreGate/test/DataHandle_test.cxx | 2 + 6 files changed, 29 insertions(+), 46 deletions(-) diff --git a/Control/StoreGate/StoreGate/DataHandle.h b/Control/StoreGate/StoreGate/DataHandle.h index a3c3a93c6533..ddd4b87fb1d2 100644 --- a/Control/StoreGate/StoreGate/DataHandle.h +++ b/Control/StoreGate/StoreGate/DataHandle.h @@ -19,17 +19,6 @@ #include "CxxUtils/checker_macros.h" #include <iterator> -template <typename DATA> -class DataHandle; - -template <class DATA> -bool operator== (const DataHandle<DATA>& h1, - const DataHandle<DATA>& h2); - -template <class DATA> -bool operator!= (const DataHandle<DATA>& h1, - const DataHandle<DATA>& h2); - /** @class DataHandle * @brief an iterator over instances of a given type in StoreGateSvc. It d-casts * and caches locally the pointed-at object, to speed-up subsequent accesses. @@ -131,11 +120,19 @@ public: virtual CLID clid() const override { return ClassID_traits<DATA>::ID(); } friend - bool operator==<>(const DataHandle<DATA>& h1, - const DataHandle<DATA>& h2); + bool operator== ATLAS_NOT_THREAD_SAFE (const DataHandle<DATA>& h1, + const DataHandle<DATA>& h2) + { + return h1.m_proxy == h2.m_proxy; + } + friend - bool operator!=<>(const DataHandle<DATA>& h1, - const DataHandle<DATA>& h2); + bool operator!= ATLAS_NOT_THREAD_SAFE (const DataHandle<DATA>& h1, + const DataHandle<DATA>& h2) + { + return h1.m_proxy != h2.m_proxy; + } + private: // OK since DataHandle should only be used locally, not shared between threads. @@ -146,22 +143,6 @@ private: }; -/// \name Comparison ops (compare proxies) -//@{ -template <class DATA> -bool operator== ATLAS_NOT_THREAD_SAFE (const DataHandle<DATA>& h1, - const DataHandle<DATA>& h2) -{ - return (h1.m_proxy == h2.m_proxy); -} -template <class DATA> -bool operator!= ATLAS_NOT_THREAD_SAFE (const DataHandle<DATA>& h1, - const DataHandle<DATA>& h2) -{ - return (h1.m_proxy != h2.m_proxy); -} -//@} - #include "StoreGate/DataHandle.icc" /* FIXME LEGACY - No dependency on ActiveStoreSvc here, but a number of Muon AtlasEvent packages are diff --git a/Control/StoreGate/StoreGate/StoreGate.h b/Control/StoreGate/StoreGate/StoreGate.h index 52e83e85cfa5..d0999a5db85b 100644 --- a/Control/StoreGate/StoreGate/StoreGate.h +++ b/Control/StoreGate/StoreGate/StoreGate.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef STOREGATE_STOREGATE_H @@ -28,11 +28,11 @@ public: static ActiveStoreSvc* activeStoreSvc(); /** multipleton: get a store by name * @param sgID name of the StoreGateSvc ptr to be returned */ - static StoreGateSvc* pointer(std::string sgID); + static StoreGateSvc* pointer(const std::string& sgID); /** multipleton: get a store by name * @param sgID name of the StoreGateSvc ptr to be returned * @throws std::runtime_error if not found*/ - static StoreGateSvc& instance(std::string sgID); + static StoreGateSvc& instance(const std::string& sgID); friend class NullType; //remove compiler warning diff --git a/Control/StoreGate/StoreGate/tools/SGImplSvc.h b/Control/StoreGate/StoreGate/tools/SGImplSvc.h index eef4075a2ae3..7b4034c2ab55 100644 --- a/Control/StoreGate/StoreGate/tools/SGImplSvc.h +++ b/Control/StoreGate/StoreGate/tools/SGImplSvc.h @@ -247,14 +247,14 @@ public: //@{ /// register a callback function(2) with an already registered function(1) - StatusCode regFcn (const CallBackID c1, - const CallBackID c2, + StatusCode regFcn (const CallBackID& c1, + const CallBackID& c2, const IOVSvcCallBackFcn& fcn, bool trigger = false); /// register a callback function(2) with an already registered AlgTool StatusCode regFcn (const std::string& toolName, - const CallBackID c2, + const CallBackID& c2, const IOVSvcCallBackFcn& fcn, bool trigger = false); @@ -652,7 +652,7 @@ private: IResetable* ir, SG::DataProxy *&dp); bool bindHandleToProxyAndRegister (const CLID& id, const std::string& key, IResetable* ir, SG::DataProxy *&dp, - const CallBackID c, + const CallBackID& c, const IOVSvcCallBackFcn& fcn, bool trigger); diff --git a/Control/StoreGate/src/SGImplSvc.cxx b/Control/StoreGate/src/SGImplSvc.cxx index 555427a54532..502702c18f91 100644 --- a/Control/StoreGate/src/SGImplSvc.cxx +++ b/Control/StoreGate/src/SGImplSvc.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include <algorithm> @@ -559,8 +559,8 @@ bool SGImplSvc::isSymLinked(const CLID& linkID, DataProxy* dp) StatusCode -SGImplSvc::regFcn( const CallBackID c1, - const CallBackID c2, +SGImplSvc::regFcn( const CallBackID& c1, + const CallBackID& c2, const IOVSvcCallBackFcn& fcn, bool trigger) { @@ -571,7 +571,7 @@ SGImplSvc::regFcn( const CallBackID c1, StatusCode SGImplSvc::regFcn( const std::string& toolName, - const CallBackID c2, + const CallBackID& c2, const IOVSvcCallBackFcn& fcn, bool trigger) { @@ -1449,7 +1449,7 @@ bool SGImplSvc::bindHandleToProxyAndRegister (const CLID& id, const std::string& bool SGImplSvc::bindHandleToProxyAndRegister (const CLID& id, const std::string& key, IResetable* ir, SG::DataProxy *&dp, - const CallBackID c, + const CallBackID& c, const IOVSvcCallBackFcn& fcn, bool trigger) { diff --git a/Control/StoreGate/src/StoreGate.cxx b/Control/StoreGate/src/StoreGate.cxx index 4d0a1ff90c68..7d3bccb21570 100644 --- a/Control/StoreGate/src/StoreGate.cxx +++ b/Control/StoreGate/src/StoreGate.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #include "StoreGate/StoreGate.h" @@ -88,13 +88,13 @@ StoreGate::activeStoreSvc() { } StoreGateSvc* -StoreGate::pointer(std::string sgID) { +StoreGate::pointer(const std::string& sgID) { return getStore(sgID); } StoreGateSvc& -StoreGate::instance(std::string sgID) { +StoreGate::instance(const std::string& sgID) { StoreGateSvc* ptr(pointer(sgID)); if (0 == ptr) { throw std::runtime_error("Could not locate required StoreGate instance"); diff --git a/Control/StoreGate/test/DataHandle_test.cxx b/Control/StoreGate/test/DataHandle_test.cxx index 2df9fdbab49c..e87aabcc07e2 100644 --- a/Control/StoreGate/test/DataHandle_test.cxx +++ b/Control/StoreGate/test/DataHandle_test.cxx @@ -142,6 +142,7 @@ namespace Athena_test { ++dh; assert (vp[0]->refCount() == 2); + // cppcheck-suppress postfixOperator dh2++; assert (vp[0]->refCount() == 1); @@ -152,6 +153,7 @@ namespace Athena_test { assert (vp[0]->refCount() == 2); for (int i=1; i < 4; i++) assert (vp[i]->refCount() == 0); + // cppcheck-suppress postfixOperator dh3++; assert (vp[0]->refCount() == 1); assert (vp[1]->refCount() == 1); -- GitLab