From c81fd031ec1d3a7defb031f540533f70a649532f Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay <Attila.Krasznahorkay@cern.ch> Date: Sun, 24 May 2020 15:47:15 +0200 Subject: [PATCH] Made some e/gamma dynamic variable types be declared on library load. This was necessary to work around some issues with ROOT's dictionary handling. See merge request !33096 for more details. --- .../Root/EgammaTruthxAODHelpers.cxx | 46 +++++++++++++++++-- Event/xAOD/xAODEgamma/Root/Egamma_v1.cxx | 27 +++++++---- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/Event/xAOD/xAODEgamma/Root/EgammaTruthxAODHelpers.cxx b/Event/xAOD/xAODEgamma/Root/EgammaTruthxAODHelpers.cxx index 0d3506586a3..7bafae29c31 100644 --- a/Event/xAOD/xAODEgamma/Root/EgammaTruthxAODHelpers.cxx +++ b/Event/xAOD/xAODEgamma/Root/EgammaTruthxAODHelpers.cxx @@ -15,12 +15,50 @@ // ================================================================== -const xAOD::Electron* xAOD::EgammaHelpers::getRecoElectron(const xAOD::TruthParticle* particle){ - return getLink<xAOD::Electron>(particle, "recoElectronLink"); +/// Accessor for the "recoElectronLink" dynamic variable +/// +/// It is declared outside of the @c xAOD::EgammaHelpers::getRecoElectron(...) +/// call to make sure that the auxiliary ID registry would know about this type +/// as soon as the library holding this code is loaded. +/// +static const SG::AuxElement::Accessor< ElementLink< xAOD::ElectronContainer > > + recoElectronLinkAcc( "recoElectronLink" ); + +const xAOD::Electron* +xAOD::EgammaHelpers::getRecoElectron( const xAOD::TruthParticle* particle ) { + + if( ! recoElectronLinkAcc.isAvailable( *particle ) ) { + return nullptr; + } + const ElementLink< xAOD::ElectronContainer >& link = + recoElectronLinkAcc( *particle ); + if( ! link.isValid() ) { + return nullptr; + } + return *link; } -const xAOD::Photon* xAOD::EgammaHelpers::getRecoPhoton(const xAOD::TruthParticle* particle){ - return getLink<xAOD::Photon>(particle, "recoPhotonLink"); +/// Accessor for the "recoPhotonLink" dynamic variable +/// +/// It is declared outside of the @c xAOD::EgammaHelpers::getRecoPhoton(...) +/// call to make sure that the auxiliary ID registry would know about this type +/// as soon as the library holding this code is loaded. +/// +static const SG::AuxElement::Accessor< ElementLink< xAOD::PhotonContainer > > + recoPhotonLinkAcc( "recoPhotonLink" ); + +const xAOD::Photon* +xAOD::EgammaHelpers::getRecoPhoton( const xAOD::TruthParticle* particle ) { + + if( ! recoPhotonLinkAcc.isAvailable( *particle ) ) { + return nullptr; + } + const ElementLink< xAOD::PhotonContainer >& link = + recoPhotonLinkAcc( *particle ); + if( ! link.isValid() ) { + return nullptr; + } + return *link; } // ================================================================== diff --git a/Event/xAOD/xAODEgamma/Root/Egamma_v1.cxx b/Event/xAOD/xAODEgamma/Root/Egamma_v1.cxx index 32ef4d44e62..9f5c2e03040 100644 --- a/Event/xAOD/xAODEgamma/Root/Egamma_v1.cxx +++ b/Event/xAOD/xAODEgamma/Root/Egamma_v1.cxx @@ -2,8 +2,6 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ -// $Id: Egamma_v1$ - // EDM include(s): #include "xAODCore/AuxStoreAccessorMacros.h" // Local include(s): @@ -183,13 +181,26 @@ void Egamma_v1::setAuthor(uint16_t newAuthor) { acc(*this) = newAuthor; } +/// Accessor for the "ambiguityLink" dynamic variable +/// +/// It is declared outside of the @c xAOD::Egamma_v1::ambiguousObject() call to +/// make sure that the auxiliary ID registry would know about this type as soon +/// as the library holding this code is loaded. +/// +static const SG::AuxElement::Accessor< ElementLink< xAOD::EgammaContainer > > + ambiguityLinkAcc( "ambiguityLink" ); + /// ambiguous -const Egamma_v1* Egamma_v1::ambiguousObject() const{ - static const SG::AuxElement::Accessor<ElementLink<xAOD::EgammaContainer> > acc("ambiguityLink"); - if(acc.isAvailable(*this) && acc(*this).isValid()){ - return (*acc(*this)); - } - return nullptr; +const Egamma_v1* Egamma_v1::ambiguousObject() const { + + if( ! ambiguityLinkAcc.isAvailable( *this ) ) { + return nullptr; + } + const ElementLink< xAOD::EgammaContainer >& link = ambiguityLinkAcc( *this ); + if( ! link.isValid() ) { + return nullptr; + } + return *link; } -- GitLab