diff --git a/LArCalorimeter/LArCellRec/src/LArCellMaskingTool.cxx b/LArCalorimeter/LArCellRec/src/LArCellMaskingTool.cxx index e5212b082ea888f675bdce41a45a529d729ec33e..3d5208feb7438fcaea2b9ed98efe11bb90b9ce14 100644 --- a/LArCalorimeter/LArCellRec/src/LArCellMaskingTool.cxx +++ b/LArCalorimeter/LArCellRec/src/LArCellMaskingTool.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ /******************************************************************** @@ -25,6 +25,8 @@ LArCellMaskingTool::LArCellMaskingTool( m_onlineID(nullptr), m_offlineID(nullptr) { + m_mapInitialized = false; + declareInterface<ICaloCellMakerTool>(this); //List of strings to determine detector parts to be masked. //Syntax: barrel_endcap pos_neg Feedthrough slot channel (integers separated by white space) @@ -64,7 +66,8 @@ StatusCode LArCellMaskingTool::initialize() } -StatusCode LArCellMaskingTool::fillIncludedCellsMap(const LArOnOffIdMapping* cabling) { +StatusCode LArCellMaskingTool::fillIncludedCellsMap(const LArOnOffIdMapping* cabling) const +{ std::vector<std::string>::const_iterator it=m_rejLArChannels.begin(); std::vector<std::string>::const_iterator it_e= m_rejLArChannels.end(); @@ -155,13 +158,17 @@ StatusCode LArCellMaskingTool::fillIncludedCellsMap(const LArOnOffIdMapping* cab StatusCode LArCellMaskingTool::process(CaloCellContainer * theCont ) { + const EventContext& ctx = Gaudi::Hive::currentContext(); + if (! m_mapInitialized) { - //To make this (practically never used) method re-entrant, - //protect the following with a mutex - SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl{m_cablingKey}; - const LArOnOffIdMapping* cabling=*cablingHdl; - ATH_CHECK(fillIncludedCellsMap(cabling)); - m_mapInitialized=true; + // FIXME: Can we do this in start()? + std::lock_guard<std::mutex> lock (m_mutex); + if (!m_mapInitialized) { + SG::ReadCondHandle<LArOnOffIdMapping> cablingHdl (m_cablingKey, ctx); + const LArOnOffIdMapping* cabling=*cablingHdl; + ATH_CHECK(fillIncludedCellsMap(cabling)); + m_mapInitialized=true; + } } //Build bitmap to keep track which cells have been added to reducedCellContainer; diff --git a/LArCalorimeter/LArCellRec/src/LArCellMaskingTool.h b/LArCalorimeter/LArCellRec/src/LArCellMaskingTool.h index baa90be624d6e309c3d052d1453160eac2000210..4654e72b36bbcec4224d5ff396becd32a4acee14 100644 --- a/LArCalorimeter/LArCellRec/src/LArCellMaskingTool.h +++ b/LArCalorimeter/LArCellRec/src/LArCellMaskingTool.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration */ #ifndef LARCELLREC_LARCELLMASKINGTOOL_H @@ -13,7 +13,9 @@ #include "CaloInterface/ICaloCellMakerTool.h" #include "StoreGate/ReadCondHandleKey.h" #include "LArCabling/LArOnOffIdMapping.h" +#include "CxxUtils/checker_macros.h" #include <bitset> +#include <mutex> class LArCellMaskingTool: public AthAlgTool, @@ -36,18 +38,19 @@ public: virtual StatusCode finalize(); private: - StatusCode fillIncludedCellsMap(const LArOnOffIdMapping* cabling); + StatusCode fillIncludedCellsMap(const LArOnOffIdMapping* cabling) const; const LArOnlineID* m_onlineID; const CaloCell_ID* m_offlineID; SG::ReadCondHandleKey<LArOnOffIdMapping> m_cablingKey{this,"CablingKey","LArOnOffIdMap","SG Key of LArOnOffIdMapping object"}; std::vector<std::string> m_rejLArChannels; - std::bitset<200000> m_includedCellsMap; //Slightly too big but who cares.... + mutable std::bitset<200000> m_includedCellsMap ATLAS_THREAD_SAFE; //Slightly too big but who cares.... - bool m_mapInitialized=false; + mutable std::atomic<bool> m_mapInitialized; IdentifierHash m_offlinehashMax; IdentifierHash m_onlinehashMax; + mutable std::mutex m_mutex; }; #endif