From 4c2227e046e3f3efc095090fcbc1125a70f0485a Mon Sep 17 00:00:00 2001 From: Christos Anastopoulos <christos.anastopoulos@cern.ch> Date: Thu, 21 May 2020 11:00:56 +0000 Subject: [PATCH] Add ATLAS_THREAD_SAFETY_CHECKER to LArCellRec --- .../LArCellRec/ATLAS_CHECK_THREAD_SAFETY | 1 + LArCalorimeter/LArCellRec/CMakeLists.txt | 8 +- .../LArCellRec/src/LArCellDeadOTXCorr.h | 186 +++++++++--------- .../LArCellRec/src/LArCellEmMiscalib.h | 6 +- .../LArCellRec/src/LArCellHVCorr.cxx | 1 + .../LArCellRec/src/LArCellRescaler.h | 5 +- .../LArCellRec/src/LArNonLinearity.cxx | 2 +- 7 files changed, 111 insertions(+), 98 deletions(-) create mode 100644 LArCalorimeter/LArCellRec/ATLAS_CHECK_THREAD_SAFETY diff --git a/LArCalorimeter/LArCellRec/ATLAS_CHECK_THREAD_SAFETY b/LArCalorimeter/LArCellRec/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 00000000000..1774de260de --- /dev/null +++ b/LArCalorimeter/LArCellRec/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +LArCalorimeter/LArCellRec diff --git a/LArCalorimeter/LArCellRec/CMakeLists.txt b/LArCalorimeter/LArCellRec/CMakeLists.txt index 8bd8478b945..bde13e2f655 100644 --- a/LArCalorimeter/LArCellRec/CMakeLists.txt +++ b/LArCalorimeter/LArCellRec/CMakeLists.txt @@ -18,6 +18,7 @@ atlas_depends_on_subdirs( PUBLIC Control/AthenaBaseComps Control/AthenaKernel Control/StoreGate + Control/CxxUtils DetectorDescription/AtlasDetDescr DetectorDescription/Identifier GaudiKernel @@ -45,12 +46,15 @@ find_package( CLHEP ) find_package( ROOT COMPONENTS Core Tree MathCore Hist RIO pthread ) find_package( TBB ) -# Component(s) in the package: +#Component(s) in the package: atlas_add_component( LArCellRec src/*.cxx src/components/*.cxx INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} ${CLHEP_INCLUDE_DIRS} ${TBB_INCLUDE_DIRS} - LINK_LIBRARIES ${ROOT_LIBRARIES} ${CLHEP_LIBRARIES} AtlasHepMCLib ${TBB_LIBRARIES} CaloConditions CaloDetDescrLib CaloEvent CaloIdentifier CaloRecLib CaloUtilsLib AthAllocators AthenaBaseComps AthenaKernel StoreGateLib SGtests AtlasDetDescr Identifier GaudiKernel LArIdentifier LArRawEvent LArRecConditions LArCOOLConditions LArSimEvent CaloTriggerToolLib AthenaPoolUtilities xAODEventInfo xAODTrigL1Calo GeneratorObjects LArRecEvent LArCablingLib TrigT1CaloCalibConditions TrigT1CaloCondSvcLib ) + LINK_LIBRARIES ${ROOT_LIBRARIES} ${CLHEP_LIBRARIES} AtlasHepMCLib ${TBB_LIBRARIES} CaloConditions CaloDetDescrLib CaloEvent CaloIdentifier + CaloRecLib CaloUtilsLib AthAllocators AthenaBaseComps AthenaKernel StoreGateLib CxxUtils SGtests AtlasDetDescr Identifier GaudiKernel LArIdentifier + LArRawEvent LArRecConditions LArCOOLConditions LArSimEvent CaloTriggerToolLib AthenaPoolUtilities xAODEventInfo xAODTrigL1Calo GeneratorObjects + LArRecEvent LArCablingLib TrigT1CaloCalibConditions TrigT1CaloCondSvcLib ) # Install files from the package: atlas_install_python_modules( python/*.py ) diff --git a/LArCalorimeter/LArCellRec/src/LArCellDeadOTXCorr.h b/LArCalorimeter/LArCellRec/src/LArCellDeadOTXCorr.h index f8a728430ee..44259ee5383 100644 --- a/LArCalorimeter/LArCellRec/src/LArCellDeadOTXCorr.h +++ b/LArCalorimeter/LArCellRec/src/LArCellDeadOTXCorr.h @@ -41,6 +41,7 @@ #include "StoreGate/ReadCondHandle.h" #include "tbb/concurrent_unordered_map.h" +#include "CxxUtils/checker_macros.h" #include "LArRecConditions/LArBadChannelCont.h" #include "LArCabling/LArOnOffIdMapping.h" @@ -95,97 +96,100 @@ class LArCellDeadOTXCorr private: SG::ReadCondHandleKey<LArBadFebCont> m_badFebKey{this,"BadFebKey","LArBadFeb","Key of Bad-Feb object"}; SG::ReadCondHandleKey<LArOnOffIdMapping> m_cablingKey{this, "CablingKey", "LArOnOffIdMap","Cabling key"}; - //std::string m_TTLocation; - SG::ReadHandleKey<xAOD::TriggerTowerContainer> m_TTLocation; - std::vector<double> m_triggerNoiseCut; - bool m_useL1CaloDBProp; - mutable std::atomic<bool> m_useL1CaloDB; - - CaloRec::Array<1> m_etaCalibrationSizes; - CaloRec::Array<1> m_energyCalibrationTypes; - CaloRec::Array<1> m_etaCalibrations; - CaloRec::Array<1> m_energyCalibrations; - - - static const std::map<int, int> m_typeSizeMapping; - - //CaloRec::Array<1> m_ignoredTTs; - std::vector<unsigned int> m_ignoredTTs; - - - struct IdHash - { - size_t operator() (const Identifier& id) const - { return id.get_compact(); } - }; - mutable tbb::concurrent_unordered_map<Identifier,Identifier,IdHash> m_cellTTMapping; - mutable tbb::concurrent_unordered_map<Identifier, std::pair<unsigned int, int>, IdHash> m_idIndexMapping; - - const CaloIdManager* m_caloMgr; - const CaloLVL1_ID* m_lvl1Helper; - const CaloCell_ID* m_calo_id; - const LArOnlineID* m_onlineID; - const CaloLVL1_ID* m_TT_ID; - - - L1CaloCondSvc* m_l1CondSvc; - //CaloTriggerTowerService* m_ttSvc; - ToolHandle<CaloTriggerTowerService> m_ttSvc; - // L1CaloTTIdTools* m_l1CaloTTIdTools; - - double TTID_etaWidth(double eta) const; - double TTID_phiWidth(double eta) const; - int TTID_pos_neg_z(double eta) const; - int TTID_regionIndex(double eta) const; - int TTID_etaIndex(double eta) const; - int TTID_phiIndex(double eta, double phi) const; - static const double BASEDETA; - static const double BASEDPHI; - static const double FCALDETA; - static const double ETAMAXREGION0; - static const double ETAMAXREGION1; - static const double ETAMAXREGION2; - static const double ETAMAXREGION3; - static const double ETAMIN; - static const double PHIMIN; - - - // functions used to calculate trigger energy from parabola fit - double getA(double x1, double y1, - double x2, double y2, - double x3, double y3) const; - - double getB(double a, - double x1, double y1, - double x2, double y2) const; - - double getC(double a, double b, - double x1, double y1) const; - - - /** - * @brief Compute L1 energy with 5 samples around the maximum of the pulse. - * @param ADCsamples : ADC samples of the trigger tower - * @param pedestal : pedestal of the tower - * @param eta : eta of the tower - * @param type : em=0, had=1 - * @return L1 energy - * - * - * Energy is first estimated with a Landau-Landau fit; then a calibration factor depending on eta and the energy is applied. - */ - double getL1Energy(const std::vector<uint_least16_t> & ADCsamples, int pedestal, double eta, int type) const; - - void getInitialFitParameters(const std::vector<uint_least16_t> & ADCsamples, - double & max, - double& maxPos, - unsigned int& TTADCMaxIndex) const; - - double getEtaCalibration(double eta, int type) const; - double getEnergyCalibration(double eta, int type, double energy) const; - double getMaxOverSumRatio(const std::vector<uint_least16_t>& ADCsamples, int pedestal) const; - - static const std::map<int,int> defineSizeType(); + SG::ReadHandleKey<xAOD::TriggerTowerContainer> m_TTLocation; + std::vector<double> m_triggerNoiseCut; + bool m_useL1CaloDBProp; + mutable std::atomic<bool> m_useL1CaloDB; + + CaloRec::Array<1> m_etaCalibrationSizes; + CaloRec::Array<1> m_energyCalibrationTypes; + CaloRec::Array<1> m_etaCalibrations; + CaloRec::Array<1> m_energyCalibrations; + + static const std::map<int, int> m_typeSizeMapping; + + // CaloRec::Array<1> m_ignoredTTs; + std::vector<unsigned int> m_ignoredTTs; + + struct IdHash + { + size_t operator()(const Identifier& id) const { return id.get_compact(); } + }; + + /* Using concurent unordered map for thread safety*/ + mutable tbb::concurrent_unordered_map<Identifier, Identifier, IdHash> + m_cellTTMapping ATLAS_THREAD_SAFE; + mutable tbb:: + concurrent_unordered_map<Identifier, std::pair<unsigned int, int>, IdHash> + m_idIndexMapping ATLAS_THREAD_SAFE; + + const CaloIdManager* m_caloMgr; + const CaloLVL1_ID* m_lvl1Helper; + const CaloCell_ID* m_calo_id; + const LArOnlineID* m_onlineID; + const CaloLVL1_ID* m_TT_ID; + + L1CaloCondSvc* m_l1CondSvc; + // CaloTriggerTowerService* m_ttSvc; + ToolHandle<CaloTriggerTowerService> m_ttSvc; + // L1CaloTTIdTools* m_l1CaloTTIdTools; + + double TTID_etaWidth(double eta) const; + double TTID_phiWidth(double eta) const; + int TTID_pos_neg_z(double eta) const; + int TTID_regionIndex(double eta) const; + int TTID_etaIndex(double eta) const; + int TTID_phiIndex(double eta, double phi) const; + static const double BASEDETA; + static const double BASEDPHI; + static const double FCALDETA; + static const double ETAMAXREGION0; + static const double ETAMAXREGION1; + static const double ETAMAXREGION2; + static const double ETAMAXREGION3; + static const double ETAMIN; + static const double PHIMIN; + + // functions used to calculate trigger energy from parabola fit + double getA(double x1, + double y1, + double x2, + double y2, + double x3, + double y3) const; + + double getB(double a, double x1, double y1, double x2, double y2) const; + + double getC(double a, double b, double x1, double y1) const; + + /** + * @brief Compute L1 energy with 5 samples around the maximum of the pulse. + * @param ADCsamples : ADC samples of the trigger tower + * @param pedestal : pedestal of the tower + * @param eta : eta of the tower + * @param type : em=0, had=1 + * @return L1 energy + * + * + * Energy is first estimated with a Landau-Landau fit; then a calibration + * factor depending on eta and the energy is applied. + */ + double getL1Energy(const std::vector<uint_least16_t>& ADCsamples, + int pedestal, + double eta, + int type) const; + + void getInitialFitParameters(const std::vector<uint_least16_t>& ADCsamples, + double& max, + double& maxPos, + unsigned int& TTADCMaxIndex) const; + + double getEtaCalibration(double eta, int type) const; + double getEnergyCalibration(double eta, int type, double energy) const; + double getMaxOverSumRatio(const std::vector<uint_least16_t>& ADCsamples, + int pedestal) const; + + static const std::map<int, int> defineSizeType(); }; diff --git a/LArCalorimeter/LArCellRec/src/LArCellEmMiscalib.h b/LArCalorimeter/LArCellRec/src/LArCellEmMiscalib.h index b92ff7245fd..f1eaf8f794e 100755 --- a/LArCalorimeter/LArCellRec/src/LArCellEmMiscalib.h +++ b/LArCalorimeter/LArCellRec/src/LArCellEmMiscalib.h @@ -41,7 +41,7 @@ class LArCellEmMiscalib : public CaloCellCorrection const std::string& name, const IInterface* parent) ; - virtual ~LArCellEmMiscalib() {}; + virtual ~LArCellEmMiscalib()=default; /*! Constructor */ virtual StatusCode initialize() override; @@ -55,8 +55,8 @@ class LArCellEmMiscalib : public CaloCellCorrection void smearingPerRegion(); const LArEM_ID* m_larem_id; - const DataHandle<CaloIdManager> m_caloIdMgr; - const DataHandle<CaloDetDescrManager> m_calodetdescrmgr; + const CaloIdManager* m_caloIdMgr; + const CaloDetDescrManager* m_calodetdescrmgr; IAtRndmGenSvc* m_AtRndmGenSvc; CLHEP::HepRandomEngine* m_engine; diff --git a/LArCalorimeter/LArCellRec/src/LArCellHVCorr.cxx b/LArCalorimeter/LArCellRec/src/LArCellHVCorr.cxx index 0e8de34bcf3..158d04b0f3f 100644 --- a/LArCalorimeter/LArCellRec/src/LArCellHVCorr.cxx +++ b/LArCalorimeter/LArCellRec/src/LArCellHVCorr.cxx @@ -30,6 +30,7 @@ StatusCode LArCellHVCorr::initialize() { float LArCellHVCorr::getCorrection(const Identifier id) { + //Here we ADD const-ness so const_cast is fine return const_cast<const LArCellHVCorr*>(this)->getCorrection (id); } diff --git a/LArCalorimeter/LArCellRec/src/LArCellRescaler.h b/LArCalorimeter/LArCellRec/src/LArCellRescaler.h index 9ef555c8b6f..2825a8f8b47 100755 --- a/LArCalorimeter/LArCellRec/src/LArCellRescaler.h +++ b/LArCalorimeter/LArCellRec/src/LArCellRescaler.h @@ -12,6 +12,7 @@ #include "CaloConditions/CaloCellFactor.h" #include "StoreGate/DataHandle.h" #include "AthenaKernel/IOVSvcDefs.h" +#include "CxxUtils/checker_macros.h" #include <string> class CaloCell; @@ -28,7 +29,9 @@ ToolSvc.LArCellRescaler.CorrectionKey="myCorrectionKey" */ -class LArCellRescaler : public CaloCellCorrection { +//Not safe due to callbacks +class ATLAS_NOT_THREAD_SAFE LArCellRescaler : public CaloCellCorrection +{ public: diff --git a/LArCalorimeter/LArCellRec/src/LArNonLinearity.cxx b/LArCalorimeter/LArCellRec/src/LArNonLinearity.cxx index e9d731e0dad..21853e05f95 100644 --- a/LArCalorimeter/LArCellRec/src/LArNonLinearity.cxx +++ b/LArCalorimeter/LArCellRec/src/LArNonLinearity.cxx @@ -87,7 +87,7 @@ StatusCode LArNonLinearity::initialize() ATH_MSG_INFO( " Initialize LArNonLinearity " ); // pointer to DD manager and helpers: - const DataHandle<CaloIdManager> caloIdMgr; + const CaloIdManager* caloIdMgr; ATH_CHECK( detStore()->retrieve(caloIdMgr) ); m_emID = caloIdMgr->getEM_ID(); -- GitLab