From 687c40ec9a6290e261795fd1d51b117faabf6cac Mon Sep 17 00:00:00 2001
From: Frank Winklmeier <frank.winklmeier@cern.ch>
Date: Tue, 29 Nov 2022 13:00:44 +0100
Subject: [PATCH] DerivationFrameworkBPhys: thread-checker fixes

`BPhysVertexTrackBase`/`CfAthAlgTool` and derivatives are not thread-safe.
---
 .../DerivationFrameworkBPhys/CMakeLists.txt   | 23 ++++++++++---------
 .../ATLAS_CHECK_THREAD_SAFETY                 |  1 +
 .../BMuonTrackIsoTool.h                       |  2 +-
 .../BPhysVertexTrackBase.h                    |  3 ++-
 .../BVertexClosestTrackTool.h                 |  4 ++--
 .../BVertexTrackIsoTool.h                     |  2 +-
 .../Bmumu_reco_mumu.h                         |  4 ++--
 .../DerivationFrameworkBPhys/CfAthAlgTool.h   |  3 ++-
 .../DerivationFrameworkBPhys/Select_Bmumu.h   |  4 ++--
 .../TriggerCountToMetadata.h                  |  4 ++--
 10 files changed, 27 insertions(+), 23 deletions(-)
 create mode 100644 PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/ATLAS_CHECK_THREAD_SAFETY

diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/CMakeLists.txt b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/CMakeLists.txt
index 79daf7d41e06..e320233b16f0 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/CMakeLists.txt
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/CMakeLists.txt
@@ -4,23 +4,24 @@
 atlas_subdir( DerivationFrameworkBPhys )
 
 # External dependencies:
+find_package( Boost )
+find_package( CLHEP )
 find_package( ROOT COMPONENTS Core MathCore )
 find_package( HepPDT )
 
 # Component(s) in the package:
 atlas_add_component( DerivationFrameworkBPhys
    DerivationFrameworkBPhys/*.h src/*.cxx src/components/*.cxx
-   PRIVATE_INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${HEPPDT_INCLUDE_DIRS}
-   LINK_LIBRARIES xAODMuon AthenaBaseComps JpsiUpsilonToolsLib
-   MuonSelectorToolsLib TrkVertexAnalysisUtilsLib
-   xAODTracking xAODBPhysLib AthenaBaseComps AthenaKernel RecoToolInterfaces EventPrimitives
-   DerivationFrameworkInterfaces BPhysToolsLib TrackVertexAssociationToolLib
-   xAODBase xAODMetaData  AsgTools CaloInterfaceLib TrkVertexFitterInterfaces
-   PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} ${HEPPDT_LIBRARIES} TrackToCaloLib InDetConversionFinderToolsLib
-   xAODEventInfo AthenaPoolUtilities xAODPrimitives TrigDecisionToolLib
-   ITrackToVertex TrkVKalVrtFitterLib
-   InDetTrackSelectionToolLib  InDetV0FinderLib TrkV0FitterLib )
-
+   INCLUDE_DIRS ${Boost_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${HEPPDT_INCLUDE_DIRS} ${ROOT_INCLUDE_DIRS}
+   LINK_LIBRARIES ${Boost_LIBRARIES} ${CLHEP_LIBRARIES} ${HEPPDT_LIBRARIES} ${ROOT_LIBRARIES}
+   AthContainers AthLinks AthenaBaseComps AthenaKernel AthenaPoolUtilities BPhysToolsLib
+   CaloEvent CxxUtils DerivationFrameworkInterfaces EventKernel EventPrimitives GaudiKernel GeoPrimitives
+   ITrackToVertex InDetConversionFinderToolsLib InDetTrackSelectionToolLib InDetV0FinderLib JpsiUpsilonToolsLib
+   MuonAnalysisInterfacesLib RecoToolInterfaces StoreGateLib TrackToCaloLib TrackVertexAssociationToolLib
+   TrigDecisionToolLib TrkCaloExtension TrkEventPrimitives TrkExInterfaces TrkParameters TrkSurfaces
+   TrkToolInterfaces TrkV0FitterLib TrkVKalVrtFitterLib TrkVertexAnalysisUtilsLib TrkVertexFitterInterfaces
+   TrkVertexSeedFinderUtilsLib xAODBPhysLib xAODBase xAODCore xAODEventInfo xAODMetaData xAODMuon
+   xAODPrimitives xAODTracking xAODTruth )
 
 # Install files from the package:
 atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8})
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/ATLAS_CHECK_THREAD_SAFETY b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/ATLAS_CHECK_THREAD_SAFETY
new file mode 100644
index 000000000000..89401b298a56
--- /dev/null
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/ATLAS_CHECK_THREAD_SAFETY
@@ -0,0 +1 @@
+PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BMuonTrackIsoTool.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BMuonTrackIsoTool.h
index 679bd6721a80..1c1c3689a892 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BMuonTrackIsoTool.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BMuonTrackIsoTool.h
@@ -29,7 +29,7 @@ namespace InDet {
 
 namespace DerivationFramework {
   
-  class BMuonTrackIsoTool : public BPhysVertexTrackBase {
+  class ATLAS_NOT_THREAD_SAFE BMuonTrackIsoTool : public BPhysVertexTrackBase {
 
   private:
     typedef BPhysVertexTrackBase super;
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BPhysVertexTrackBase.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BPhysVertexTrackBase.h
index 3cfa756e1fef..45f65bcd812a 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BPhysVertexTrackBase.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BPhysVertexTrackBase.h
@@ -20,6 +20,7 @@
 #define DERIVATIONFRAMEWORK_BPhysVertexTrackBase_H
 
 #include "AthenaBaseComps/AthAlgTool.h"
+#include "CxxUtils/checker_macros.h"
 #include "DerivationFrameworkInterfaces/IAugmentationTool.h"
 #include "GaudiKernel/ToolHandle.h"
 #include "xAODEventInfo/EventInfo.h"
@@ -52,7 +53,7 @@ namespace DerivationFramework {
   typedef std::vector<const xAOD::Muon*>          MuonBag;
   typedef InDet::IInDetTrackSelectionTool         TrkSelTool;
   
-  class BPhysVertexTrackBase : public AthAlgTool,
+  class ATLAS_NOT_THREAD_SAFE BPhysVertexTrackBase : public AthAlgTool,
     virtual public IAugmentationTool {
 
   protected:
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BVertexClosestTrackTool.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BVertexClosestTrackTool.h
index b2b149a36c69..cb15b43387cc 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BVertexClosestTrackTool.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BVertexClosestTrackTool.h
@@ -28,7 +28,7 @@ namespace InDet {
 
 namespace DerivationFramework {
   
-  class BVertexClosestTrackTool : virtual public BPhysVertexTrackBase {
+  class ATLAS_NOT_THREAD_SAFE BVertexClosestTrackTool : virtual public BPhysVertexTrackBase {
 
   private:
     typedef BPhysVertexTrackBase super;
@@ -37,7 +37,7 @@ namespace DerivationFramework {
     // internal helper class
     //
   protected:
-    class CtItem : public BaseItem {
+    class ATLAS_NOT_THREAD_SAFE CtItem : public BaseItem {
 
       public:
 	CtItem(const std::string& Name="_none_",
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BVertexTrackIsoTool.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BVertexTrackIsoTool.h
index 9b88b7af4f99..402e0af617e2 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BVertexTrackIsoTool.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/BVertexTrackIsoTool.h
@@ -28,7 +28,7 @@ namespace InDet {
 
 namespace DerivationFramework {
   
-  class BVertexTrackIsoTool : virtual public BPhysVertexTrackBase {
+  class ATLAS_NOT_THREAD_SAFE BVertexTrackIsoTool : virtual public BPhysVertexTrackBase {
     
   private:
     typedef BPhysVertexTrackBase super;
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/Bmumu_reco_mumu.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/Bmumu_reco_mumu.h
index 3a5e116f637d..090c1496de7b 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/Bmumu_reco_mumu.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/Bmumu_reco_mumu.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 ///////////////////////////////////////////////////////////////////
@@ -39,7 +39,7 @@ namespace Trk {
  */
 namespace DerivationFramework {
 
-  class Bmumu_reco_mumu : public CfAthAlgTool, public IAugmentationTool {
+  class ATLAS_NOT_THREAD_SAFE Bmumu_reco_mumu : public CfAthAlgTool, public IAugmentationTool {
     public: 
       Bmumu_reco_mumu(const std::string& t, const std::string& n,
 		      const IInterface* p);
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/CfAthAlgTool.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/CfAthAlgTool.h
index 2bfb69efe65b..977586903cb2 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/CfAthAlgTool.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/CfAthAlgTool.h
@@ -25,13 +25,14 @@
 #include "GaudiKernel/ServiceHandle.h"
 #include "AthenaKernel/ICutFlowSvc.h"
 #include "AthenaBaseComps/AthAlgTool.h"
+#include "CxxUtils/checker_macros.h"
 
 #include <string>
 #include <map>
 
 namespace DerivationFramework {
   
-  class CfAthAlgTool : public AthAlgTool {
+  class ATLAS_NOT_THREAD_SAFE CfAthAlgTool : public AthAlgTool {
   public:
     // constructor with parameters
     CfAthAlgTool(const std::string& t, const std::string& n,
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/Select_Bmumu.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/Select_Bmumu.h
index a592a2463597..27dcaa7952d1 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/Select_Bmumu.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/Select_Bmumu.h
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
+  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 
 //============================================================================
@@ -51,7 +51,7 @@ namespace SG {
  */
 namespace DerivationFramework {
 
-  class Select_Bmumu : public CfAthAlgTool, public IAugmentationTool {
+  class ATLAS_NOT_THREAD_SAFE Select_Bmumu : public CfAthAlgTool, public IAugmentationTool {
     public: 
       Select_Bmumu(const std::string& t, const std::string& n, const IInterface* p);
 
diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/TriggerCountToMetadata.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/TriggerCountToMetadata.h
index 69290703ebd6..6062780de941 100644
--- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/TriggerCountToMetadata.h
+++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkBPhys/DerivationFrameworkBPhys/TriggerCountToMetadata.h
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
 */
 //============================================================================
 // 
@@ -32,7 +32,7 @@ namespace Trig{
 
 namespace DerivationFramework {
 
-  class TriggerCountToMetadata : virtual public CfAthAlgTool, virtual public IAugmentationTool {
+  class ATLAS_NOT_THREAD_SAFE TriggerCountToMetadata : virtual public CfAthAlgTool, virtual public IAugmentationTool {
 
     public: 
       TriggerCountToMetadata(const std::string& t, const std::string& n, const IInterface* p);
-- 
GitLab