Skip to content
Snippets Groups Projects
Commit 78bff888 authored by Frank Winklmeier's avatar Frank Winklmeier
Browse files

IsolationSelection: thread-checker fixes

Mark `IIsolationCloseByCorrectionTool::getCloseByIsoCorrection` as not
thread-safe because it mutates the constant cache. Needs to be cleaned
up eventually (see discussion on !58355).
parent 89f86539
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
*/
/// @author Nils Krumnack
......@@ -9,6 +9,7 @@
#define ASG_ANALYSIS_ALGORITHMS__ISOLATION_CLOSE_BY_CORRECTION_ALG_H
#include <AnaAlgorithm/AnaAlgorithm.h>
#include <CxxUtils/checker_macros.h>
#include <IsolationSelection/IIsolationCloseByCorrectionTool.h>
#include <SelectionHelpers/OutOfValidityEventHelper.h>
#include <SystematicsHandles/SysCopyHandle.h>
......@@ -18,7 +19,8 @@ namespace CP
{
/// \brief an algorithm for calling \ref IIsolationCloseByCorrectionTool
class IsolationCloseByCorrectionAlg final : public EL::AnaAlgorithm
class ATLAS_NOT_THREAD_SAFE IsolationCloseByCorrectionAlg final : public EL::AnaAlgorithm
// ^ use of IsolationCloseByCorrectionTool
{
/// \brief the standard constructor
public:
......
......@@ -19,9 +19,9 @@ atlas_add_library( IsolationSelectionLib
IsolationSelection/*.h Root/*.cxx
PUBLIC_HEADERS IsolationSelection
PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
LINK_LIBRARIES AthContainers AsgTools xAODBase xAODEgamma xAODMuon xAODEventInfo xAODPFlow ${extra_libs} AsgDataHandlesLib
LINK_LIBRARIES AthContainers AsgTools xAODBase xAODEgamma xAODMuon xAODEventInfo xAODPFlow ${extra_libs} AsgDataHandlesLib CxxUtils
xAODPrimitives PATCoreLib PATInterfaces InDetTrackSelectionToolLib xAODTracking ${ROOT_LIBRARIES} TrackVertexAssociationToolLib InDetTrackSelectionToolLib
PRIVATE_LINK_LIBRARIES CxxUtils PathResolver FourMomUtils )
PRIVATE_LINK_LIBRARIES PathResolver FourMomUtils )
if( NOT XAOD_STANDALONE )
atlas_add_component( IsolationSelection
......
PhysicsAnalysis/AnalysisCommon/IsolationSelection
......@@ -8,6 +8,7 @@
#include <AsgDataHandles/ReadHandleKey.h>
#include <AsgTools/IAsgTool.h>
#include <AsgTools/CurrentContext.h>
#include <CxxUtils/checker_macros.h>
#include <IsolationSelection/Defs.h>
#include <PATCore/AcceptData.h>
#include <PATCore/AcceptInfo.h>
......@@ -35,7 +36,7 @@ namespace CP {
const std::vector<xAOD::Iso::IsolationType>& types,
const xAOD::IParticleContainer& closePar) const = 0;
virtual CorrectionCode getCloseByIsoCorrection(xAOD::ElectronContainer* Electrons = nullptr, xAOD::MuonContainer* Muons = nullptr,
virtual CorrectionCode getCloseByIsoCorrection ATLAS_NOT_THREAD_SAFE (xAOD::ElectronContainer* Electrons = nullptr, xAOD::MuonContainer* Muons = nullptr,
xAOD::PhotonContainer* Photons = nullptr) const = 0;
virtual CorrectionCode subtractCloseByContribution(xAOD::IParticle& x, const xAOD::IParticleContainer& closebyPar) const = 0;
......
......@@ -10,6 +10,7 @@
#include <AsgTools/AsgTool.h>
#include <AsgTools/PropertyWrapper.h>
#include <AsgTools/ToolHandle.h>
#include <CxxUtils/checker_macros.h>
#ifndef XAOD_STANDALONE
#include <StoreGate/ReadDecorHandleKeyArray.h>
#endif
......@@ -57,7 +58,8 @@ namespace CP {
virtual asg::AcceptData acceptCorrected(const xAOD::IParticle& x, const xAOD::IParticleContainer& closePar) const override;
virtual CorrectionCode getCloseByIsoCorrection(xAOD::ElectronContainer* Electrons, xAOD::MuonContainer* Muons,
/// not thread-safe because of const_cast
virtual CorrectionCode getCloseByIsoCorrection ATLAS_NOT_THREAD_SAFE (xAOD::ElectronContainer* Electrons, xAOD::MuonContainer* Muons,
xAOD::PhotonContainer* Photons) const override;
virtual CorrectionCode subtractCloseByContribution(xAOD::IParticle& x, const xAOD::IParticleContainer& closebyPar) const override;
......@@ -75,7 +77,7 @@ namespace CP {
float& energy) const override;
/// Helper struct to collect all relevant objects for the procedure
using PrimaryCollection = std::set<xAOD::IParticle*>;
using PrimaryCollection = std::set<const xAOD::IParticle*>;
struct ObjectCache {
ObjectCache() = default;
const xAOD::Vertex* prim_vtx{nullptr};
......@@ -97,7 +99,7 @@ namespace CP {
// Function to pipe each container given by the interfaces through. It loops over all
// particles and removes the isolation overlap between the objects
CorrectionCode performCloseByCorrection(const EventContext& ctx, ObjectCache& cache) const;
CorrectionCode performCloseByCorrection ATLAS_NOT_THREAD_SAFE (const EventContext& ctx, ObjectCache& cache) const;
// Helper function to obtain the isolation cones to use for a given particle
const IsoVector& getIsolationTypes(const xAOD::IParticle* particle) const;
......
......@@ -133,7 +133,7 @@ namespace CP {
}
}
if (!passSelectionQuality(particle)) continue;
cache.prim_parts.insert(const_cast<xAOD::IParticle*>(particle));
cache.prim_parts.insert(particle);
}
}
void IsolationCloseByCorrectionTool::loadAssociatedObjects(const EventContext& ctx, ObjectCache& cache) const {
......@@ -148,7 +148,7 @@ namespace CP {
}
PflowSet IsolationCloseByCorrectionTool::getAssocFlowElements(const EventContext& ctx, const xAOD::IParticle* particle) const {
ObjectCache cache{};
cache.prim_parts = {const_cast<xAOD::IParticle*>(particle)};
cache.prim_parts = {particle};
loadAssociatedObjects(ctx, cache);
return cache.flows;
}
......@@ -180,7 +180,9 @@ namespace CP {
}
}
}
CorrectionCode IsolationCloseByCorrectionTool::getCloseByIsoCorrection(xAOD::ElectronContainer* Electrons, xAOD::MuonContainer* Muons,
/// not thread-safe because of const_cast
CorrectionCode IsolationCloseByCorrectionTool::getCloseByIsoCorrection ATLAS_NOT_THREAD_SAFE (xAOD::ElectronContainer* Electrons, xAOD::MuonContainer* Muons,
xAOD::PhotonContainer* Photons) const {
if (!m_isInitialised) {
ATH_MSG_ERROR("The IsolationCloseByCorrectionTool was not initialised!!!");
......@@ -203,9 +205,10 @@ namespace CP {
return performCloseByCorrection(ctx, cache);
}
CorrectionCode IsolationCloseByCorrectionTool::performCloseByCorrection(const EventContext& ctx, ObjectCache& cache) const {
for (xAOD::IParticle* Particle : cache.prim_parts) {
if (subtractCloseByContribution(ctx, Particle, cache) == CorrectionCode::Error) {
CorrectionCode IsolationCloseByCorrectionTool::performCloseByCorrection ATLAS_NOT_THREAD_SAFE (const EventContext& ctx, ObjectCache& cache) const {
for (const xAOD::IParticle* Particle : cache.prim_parts) {
auto Particle_nc = const_cast<xAOD::IParticle*>(Particle); // this needs to be fixed
if (subtractCloseByContribution(ctx, Particle_nc, cache) == CorrectionCode::Error) {
ATH_MSG_ERROR("Failed to correct the isolation of particle with pt: " << Particle->pt() * MeVtoGeV << " GeV"
<< " eta: " << Particle->eta()
<< " phi: " << Particle->phi());
......
......@@ -7,6 +7,7 @@
// Gaudi/Athena include(s):
#include "AthenaBaseComps/AthHistogramAlgorithm.h"
#include "CxxUtils/checker_macros.h"
#include "GaudiKernel/SystemOfUnits.h"
#include "MuonTesterTree/MuonTesterTreeDict.h"
#include "StoreGate/ReadDecorHandleKey.h"
......@@ -37,7 +38,7 @@
*/
namespace CP {
class TestIsolationCloseByCorrAlg : public AthHistogramAlgorithm {
class ATLAS_NOT_THREAD_SAFE TestIsolationCloseByCorrAlg : public AthHistogramAlgorithm {
public:
TestIsolationCloseByCorrAlg(const std::string& name, ISvcLocator* svcLoc);
virtual ~TestIsolationCloseByCorrAlg() = default;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment