From 69e299d277c4897f10c52ff9e651b5de5a54bd63 Mon Sep 17 00:00:00 2001 From: christos <christos@cern.ch> Date: Mon, 5 Apr 2021 20:46:25 +0200 Subject: [PATCH] StoregateSvc:retrieve. Avoid un-needed allocation of std:string due to static_cast<std::string> , when the TKEY type is already std::string --- Control/StoreGate/StoreGate/StoreGateSvc.h | 12 +++++ Control/StoreGate/StoreGate/StoreGateSvc.icc | 46 ++++++++++++++------ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/Control/StoreGate/StoreGate/StoreGateSvc.h b/Control/StoreGate/StoreGate/StoreGateSvc.h index 81a075c63f4..555c0392fc5 100644 --- a/Control/StoreGate/StoreGate/StoreGateSvc.h +++ b/Control/StoreGate/StoreGate/StoreGateSvc.h @@ -228,10 +228,22 @@ public: template <typename T, typename TKEY> StatusCode retrieve(const T*& ptr, const TKEY& key) const; + /// Retrieve an object with "key", into a const T*. + /// Overload for std::string KEY type + template <typename T> + StatusCode retrieve(const T*& ptr, const std::string& key) const; + + /// Retrieve an object with "key", into a T* template <typename T, typename TKEY> StatusCode retrieve(T*& ptr, const TKEY& key) const; + /// Retrieve an object with "key", into a T*. + /// Overload for std::string KEY type + template <typename T> + StatusCode retrieve(T*& ptr, const std::string& key) const; + + /// Variant of the above which doesn't return a status code. /// Just returns null if the object isn't found. template <typename T, class TKEY> diff --git a/Control/StoreGate/StoreGate/StoreGateSvc.icc b/Control/StoreGate/StoreGate/StoreGateSvc.icc index cd865110a46..3b57f582655 100644 --- a/Control/StoreGate/StoreGate/StoreGateSvc.icc +++ b/Control/StoreGate/StoreGate/StoreGateSvc.icc @@ -363,19 +363,17 @@ StatusCode StoreGateSvc::retrieve(T*& ptr) const ////////////////////////////////////////////////////////////////// // Retrieve the keyed object as a const pointer +// Overload for std::string key type ////////////////////////////////////////////////////////////////// -template <typename T, typename TKEY> -StatusCode StoreGateSvc::retrieve(const T*& ptr, const TKEY& key) const +template <typename T> +StatusCode StoreGateSvc::retrieve(const T*& ptr, const std::string& key) const { if (m_storeID == StoreID::EVENT_STORE && s_pSlot != nullptr) { rememberBadRetrieve (ClassID_traits<T>::ID(), key); } -#ifndef __clang__ - BOOST_CONCEPT_ASSERT( (KeyConcept<TKEY>) ); -#endif SG::DataProxy* dp =proxy (ClassID_traits<T>::ID(), - static_cast<std::string> (key), + key, false); if (!dp || !dp->isValid()) { warning() @@ -401,24 +399,34 @@ StatusCode StoreGateSvc::retrieve(const T*& ptr, const TKEY& key) const } ////////////////////////////////////////////////////////////////// -// Retrieve the keyed object as a non-const pointer +// Retrieve the keyed object as a const pointer ////////////////////////////////////////////////////////////////// template <typename T, typename TKEY> -StatusCode StoreGateSvc::retrieve(T*& ptr, const TKEY& key) const +StatusCode StoreGateSvc::retrieve(const T*& ptr, const TKEY& key) const +{ +#ifndef __clang__ + BOOST_CONCEPT_ASSERT( (KeyConcept<TKEY>) ); +#endif + return this->retrieve(ptr, static_cast<std::string>(key)); +} + +////////////////////////////////////////////////////////////////// +// Retrieve the keyed object as a non-const pointer +// Overload for std::string key type +////////////////////////////////////////////////////////////////// +template <typename T> +StatusCode StoreGateSvc::retrieve(T*& ptr, const std::string& key) const { if (m_storeID == StoreID::EVENT_STORE && s_pSlot != nullptr) { rememberBadRetrieve (ClassID_traits<T>::ID(), key); } -#ifndef __clang__ - BOOST_CONCEPT_ASSERT( (KeyConcept<TKEY>) ); -#endif SG::DataProxy* dp =proxy (ClassID_traits<T>::ID(), - static_cast<std::string> (key), + key, false); if (!dp || !dp->isValid() || dp->isConst()) { SG_MSG_WARNING("retrieve(non-const): No valid proxy for object " - << (std::string)key << ' ' + << key << ' ' << " of type " << ClassID_traits<T>::typeName() << "(CLID " << ClassID_traits<T>::ID() << ") \n Try to use a const retrieve" ); @@ -440,6 +448,18 @@ StatusCode StoreGateSvc::retrieve(T*& ptr, const TKEY& key) const return StatusCode::SUCCESS; } +////////////////////////////////////////////////////////////////// +// Retrieve the keyed object as a non-const pointer +////////////////////////////////////////////////////////////////// +template <typename T, typename TKEY> +StatusCode StoreGateSvc::retrieve(T*& ptr, const TKEY& key) const +{ +#ifndef __clang__ + BOOST_CONCEPT_ASSERT( (KeyConcept<TKEY>) ); +#endif + return this->retrieve(ptr, static_cast<std::string>(key)); +} + /// Retrieve all objects of type T: returns an SG::ConstIterator range template <typename T> StatusCode -- GitLab