diff --git a/Event/xAOD/xAODMissingET/Root/MissingET_v1.cxx b/Event/xAOD/xAODMissingET/Root/MissingET_v1.cxx index c76ee8387db53126a4f16830dfb07090558b25a4..1ea40279b06071c21ad161fbff5a074d6ff3fcf2 100644 --- a/Event/xAOD/xAODMissingET/Root/MissingET_v1.cxx +++ b/Event/xAOD/xAODMissingET/Root/MissingET_v1.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 */ @@ -20,8 +20,6 @@ MissingET_v1::MissingET_v1( bool createStore ) createPrivateStore(); setName(this->name()); } - else - m_nameHash = 0; } MissingET_v1::MissingET_v1( const std::string& name, diff --git a/Event/xAOD/xAODMissingET/xAODMissingET/selection.xml b/Event/xAOD/xAODMissingET/xAODMissingET/selection.xml index 781949aae28e37c11a61a29a9cc654cbd8de74e9..5caac7fccb78e9bda7a8f2f8a5c78cadc3d06bb7 100644 --- a/Event/xAOD/xAODMissingET/xAODMissingET/selection.xml +++ b/Event/xAOD/xAODMissingET/xAODMissingET/selection.xml @@ -5,6 +5,12 @@ <class name="xAOD::MissingET_v1" > <field name="m_nameHash" transient="true" /> </class> + <read sourceClass="xAOD::MissingET_v1" version="[1-]" + targetClass="xAOD::MissingET_v1" source="" target="m_nameHash" > + <![CDATA[ + m_nameHash.reset(); + ]]> + </read> <class name="DataVector<xAOD::MissingET_v1>" /> <class name="xAOD::MissingETContainer_v1" id="F49162FE-6BC0-49BC-A7DA-A792136BD939" /> diff --git a/Event/xAOD/xAODMissingET/xAODMissingET/versions/MissingET_v1.h b/Event/xAOD/xAODMissingET/xAODMissingET/versions/MissingET_v1.h index c11056709e94508f23e417d3d45f70287852834e..8b273fa702aac04ffe30cfaade0f7efd28d2a221 100644 --- a/Event/xAOD/xAODMissingET/xAODMissingET/versions/MissingET_v1.h +++ b/Event/xAOD/xAODMissingET/xAODMissingET/versions/MissingET_v1.h @@ -1,7 +1,7 @@ // -*- c++ -*- /* - 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 XAODMISSINGET_VERSIONS_MISSINGET_V1_H @@ -9,8 +9,9 @@ #include "AthContainers/AuxElement.h" -#include "xAODBase/IParticle.h" +#include "CxxUtils/CachedValue.h" +#include "xAODBase/IParticle.h" #include "xAODMissingET/versions/MissingETBase.h" #include <string> @@ -108,12 +109,12 @@ namespace xAOD float& f_mpy(); /*!< @brief Returns reference to @f$ p_{y} @f$ store */ float& f_sumet(); /*!< @brief Returns reference to @f$ \Sigma E_{\rm T} @f$ store */ std::string& f_name(); /*!< @brief Returns reference to MET object name store */ - const std::string& f_nameConst(); /*!< @brief Returns const reference to the MET object name store*/ + const std::string& f_nameConst() const; /*!< @brief Returns const reference to the MET object name store*/ MissingETBase::Types::bitmask_t& f_source(); /*!< @brief Returns reference to MET object source store */ /*!@}*/ private: - std::size_t m_nameHash;/*!< @brief Stores the hash for the current f_name string */ + CxxUtils::CachedValue<std::size_t> m_nameHash; /*!< @brief Stores the hash for the current f_name string */ static const SG::AuxElement::Accessor<float> m_acc_mpx; static const SG::AuxElement::Accessor<float> m_acc_mpy; diff --git a/Event/xAOD/xAODMissingET/xAODMissingET/versions/MissingET_v1.icc b/Event/xAOD/xAODMissingET/xAODMissingET/versions/MissingET_v1.icc index 5dbe64ade328efe712c289957836859af299ef0d..4d4360ce8c611b3f2f7f1f9e35f47c57e2d39cdf 100644 --- a/Event/xAOD/xAODMissingET/xAODMissingET/versions/MissingET_v1.icc +++ b/Event/xAOD/xAODMissingET/xAODMissingET/versions/MissingET_v1.icc @@ -1,7 +1,7 @@ // -*- c++ -*- /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ @@ -16,7 +16,10 @@ inline float xAOD::MissingET_v1::mpy() const { return m_acc_mpy(*this); } inline float xAOD::MissingET_v1::sumet() const { return m_acc_sumet(*this); } inline const std::string& xAOD::MissingET_v1::name() const { static const SG::AuxElement::Accessor<std::string> acc("name"); return acc(*this); } -inline std::size_t xAOD::MissingET_v1::nameHash() const { return m_nameHash; } +inline std::size_t xAOD::MissingET_v1::nameHash() const { + if (!m_nameHash.isValid()) { m_nameHash.set(std::hash<std::string>()(this->f_nameConst())); } + return *m_nameHash.ptr(); +} inline MissingETBase::Types::bitmask_t xAOD::MissingET_v1::source() const { static const SG::AuxElement::Accessor<MissingETBase::Types::bitmask_t> acc("source"); return acc(*this); } //////////////////////////////////////////// @@ -28,7 +31,7 @@ inline float& xAOD::MissingET_v1::f_mpy() { return m_acc_mpy(*this); } inline float& xAOD::MissingET_v1::f_sumet() { return m_acc_sumet(*this); } inline std::string& xAOD::MissingET_v1::f_name() { static const SG::AuxElement::Accessor<std::string> acc("name"); return acc(*this); } -inline const std::string& xAOD::MissingET_v1::f_nameConst() { static const SG::AuxElement::ConstAccessor<std::string> acc("name"); return acc(*this); } +inline const std::string& xAOD::MissingET_v1::f_nameConst() const { static const SG::AuxElement::ConstAccessor<std::string> acc("name"); return acc(*this); } inline MissingETBase::Types::bitmask_t& xAOD::MissingET_v1::f_source() { static const SG::AuxElement::Accessor<MissingETBase::Types::bitmask_t> acc("source"); return acc(*this); } inline void xAOD::MissingET_v1::setMpx(float mpx) { this->f_mpx() = mpx; } @@ -40,7 +43,10 @@ inline void xAOD::MissingET_v1::setName(const std::string& name) { updateHash(); } -inline void xAOD::MissingET_v1::updateHash() { m_nameHash = std::hash<std::string>()(this->f_nameConst()); } +inline void xAOD::MissingET_v1::updateHash() { + m_nameHash.reset(); + m_nameHash.set(std::hash<std::string>()(this->f_nameConst())); +} inline void xAOD::MissingET_v1::setSource(MissingETBase::Types::bitmask_t src) { this->f_source() = src; } /////////////////////////////////////////////////// diff --git a/Event/xAOD/xAODMissingETAthenaPool/src/xAODMissingETContainerCnv.cxx b/Event/xAOD/xAODMissingETAthenaPool/src/xAODMissingETContainerCnv.cxx index 86faffcd9b55d78697489df27d1e6a6fc3080df2..4ec4bf69026bd30f103ac912d5887814688076ce 100644 --- a/Event/xAOD/xAODMissingETAthenaPool/src/xAODMissingETContainerCnv.cxx +++ b/Event/xAOD/xAODMissingETAthenaPool/src/xAODMissingETContainerCnv.cxx @@ -1,15 +1,6 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ - -// Local include(s): -#include "xAODMissingETContainerCnv.h" - -xAOD::MissingETContainer* -xAODMissingETContainerCnv::createTransientWithKey (const std::string& key) -{ - xAOD::MissingETContainer* c = xAODMissingETContainerCnvBase::createTransientWithKey (key); - for(xAOD::MissingET* metObj : *c) metObj->updateHash(); - return c; -} +// Dummy source file so that the build system knows that this +// is a custom converter. diff --git a/Event/xAOD/xAODMissingETAthenaPool/src/xAODMissingETContainerCnv.h b/Event/xAOD/xAODMissingETAthenaPool/src/xAODMissingETContainerCnv.h index 9319756a26e0760fdc7361a7f884fe6b180a2cb5..aeb417649fff988b8cc2f2f8f2de40e7b43eb285 100644 --- a/Event/xAOD/xAODMissingETAthenaPool/src/xAODMissingETContainerCnv.h +++ b/Event/xAOD/xAODMissingETAthenaPool/src/xAODMissingETContainerCnv.h @@ -1,41 +1,21 @@ // Dear emacs, this is -*- c++ -*- /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // $Id: xAODMissingETContainerCnv.h 795699 2017-02-05 23:26:05Z khoo $ #ifndef XAODMISSINGETATHENAPOOL_XAODMISSINGETCONTAINERCNV_H #define XAODMISSINGETATHENAPOOL_XAODMISSINGETCONTAINERCNV_H -// System include(s): -#include <string> - // Gaudi/Athena include(s): #include "AthenaPoolCnvSvc/T_AthenaPoolxAODCnv.h" // EDM include(s): -#include "xAODMissingET/MissingET.h" #include "xAODMissingET/MissingETContainer.h" /// Type definition for the converter's base typedef T_AthenaPoolxAODCnv< xAOD::MissingETContainer > - xAODMissingETContainerCnvBase; - -/** - * @short POOL converter for the xAOD::MissingETContainer class - * - * We need to extend the default version to handle maintaining the name hashing - * in the interface class. - */ -class xAODMissingETContainerCnv : public xAODMissingETContainerCnvBase -{ -public: - using xAODMissingETContainerCnvBase::xAODMissingETContainerCnvBase; - - /// Function reading in the persistent object - virtual xAOD::MissingETContainer* createTransientWithKey (const std::string& key) override; -}; // class xAODMissingETContainerCnv - + xAODMissingETContainerCnv; #endif // XAODMISSINGETATHENAPOOL_XAODMISSINGETCONTAINERCNV_H