From 34592eea16125f086c580c7af847d2f89b13013f Mon Sep 17 00:00:00 2001 From: scott snyder <snyder@bnl.gov> Date: Mon, 18 Jun 2018 15:56:01 +0200 Subject: [PATCH] CaloCellCorrection: Make CaloCellCorrection methods const. Change CaloCellCorrection::MakeCorrection and execute to be const, and to take an EventContext argument. Working to make more of the calorimeter reconstruction reentrant. --- .../CaloCellMBAverageCorr.h | 5 ++-- .../CaloCellCorrection/CaloCellPedestalCorr.h | 10 ++++---- .../CaloCellCorrection/CaloCellRandomizer.h | 3 ++- .../CaloCellCorrection/CaloCellRescaler.h | 5 ++-- .../CaloCellCorrection/CaloCellTimeCorrTool.h | 5 ++-- .../python/CaloCellPedestalCorrDefault.py | 4 ++++ .../src/CaloCellMBAverageCorr.cxx | 3 ++- .../src/CaloCellPedestalCorr.cxx | 24 ++++++++++--------- .../src/CaloCellRandomizer.cxx | 4 ++-- .../src/CaloCellRescaler.cxx | 5 ++-- .../src/CaloCellTimeCorrTool.cxx | 4 +++- 11 files changed, 44 insertions(+), 28 deletions(-) diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellMBAverageCorr.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellMBAverageCorr.h index 96745584839..13b738e1306 100755 --- a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellMBAverageCorr.h +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellMBAverageCorr.h @@ -24,9 +24,10 @@ public: virtual ~CaloCellMBAverageCorr() {}; - virtual StatusCode initialize(); + virtual StatusCode initialize() override; - void MakeCorrection(CaloCell* theCell); + void MakeCorrection (CaloCell* theCell, + const EventContext& ctx) const override; private: diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellPedestalCorr.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellPedestalCorr.h index c7dff91fe1b..c77eedecb3a 100755 --- a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellPedestalCorr.h +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellPedestalCorr.h @@ -13,6 +13,7 @@ #include "CaloInterface/ICaloLumiBCIDTool.h" #include "AthenaPoolUtilities/CondAttrListCollection.h" #include "GaudiKernel/ToolHandle.h" +#include <unordered_map> class CaloCondBlobFlt; class CaloCell; @@ -30,9 +31,10 @@ public: virtual ~CaloCellPedestalCorr() {}; - virtual StatusCode initialize(); + virtual StatusCode initialize() override; - void MakeCorrection(CaloCell* theCell); + void MakeCorrection (CaloCell* theCell, + const EventContext& ctx) const override; private: @@ -42,8 +44,8 @@ private: virtual StatusCode updateMap(IOVSVC_CALLBACK_ARGS); //=== blob storage const DataHandle<CondAttrListCollection> m_noiseAttrListColl; - std::map<unsigned int, const CaloCondBlobFlt*> m_noiseBlobMap; - std::map<unsigned int, const CaloCondBlobFlt*>::const_iterator m_lastIt; + typedef std::unordered_map<unsigned int, const CaloCondBlobFlt*> NoiseBlobMap_t; + NoiseBlobMap_t m_noiseBlobMap; ToolHandle<ICaloCoolIdTool> m_caloCoolIdTool; float m_lumi0; diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRandomizer.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRandomizer.h index 6c9ee72b782..36e0541c8de 100644 --- a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRandomizer.h +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRandomizer.h @@ -29,7 +29,8 @@ public: virtual StatusCode initialize() override; - virtual void MakeCorrection (CaloCell* theCell) override; + virtual void MakeCorrection (CaloCell* theCell, + const EventContext& ctx) const override; private: diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRescaler.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRescaler.h index a8e1ab8b536..2daaeeca264 100755 --- a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRescaler.h +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellRescaler.h @@ -35,9 +35,10 @@ public: const IInterface* parent); ~CaloCellRescaler(); - virtual StatusCode initialize(); + virtual StatusCode initialize() override; - void MakeCorrection(CaloCell* theCell); + virtual void MakeCorrection (CaloCell* theCell, + const EventContext& ctx) const override; private: diff --git a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellTimeCorrTool.h b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellTimeCorrTool.h index 197b69fd84d..c5f76206793 100644 --- a/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellTimeCorrTool.h +++ b/Calorimeter/CaloCellCorrection/CaloCellCorrection/CaloCellTimeCorrTool.h @@ -27,9 +27,10 @@ public: const IInterface* parent); ~CaloCellTimeCorrTool(); - virtual StatusCode initialize(); + virtual StatusCode initialize() override; - void MakeCorrection(CaloCell* theCell); + virtual void MakeCorrection (CaloCell* theCell, + const EventContext& ctx) const override; private: /// IOV callback method diff --git a/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py b/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py index 77f6f90e9db..3d8fdd13468 100644 --- a/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py +++ b/Calorimeter/CaloCellCorrection/python/CaloCellPedestalCorrDefault.py @@ -49,6 +49,10 @@ def CaloCellPedestalCorrDefault(name='CaloCellPedestalCorr'): theCaloCellPedestalCorr.LumiFolderName = lumiFolder if jobproperties.CaloCellFlags.doPileupOffsetBCIDCorr() and (not athenaCommonFlags.isOnline()): + import AthenaCommon.ConcurrencyFlags + if jobproperties.ConcurrencyFlags.NumThreads() >= 1: + mlog.error ("FIXME: CaloLumiBCIDTool does not work in MT") + raise RunTimeError ("FIXME: CaloLumiBCIDTool does not work in MT") from CaloTools.CaloLumiBCIDToolDefault import CaloLumiBCIDToolDefault theCaloLumiBCIDTool = CaloLumiBCIDToolDefault() ToolSvc += theCaloLumiBCIDTool diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellMBAverageCorr.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellMBAverageCorr.cxx index 2155d9a6c8d..9b0f43fd0f9 100755 --- a/Calorimeter/CaloCellCorrection/src/CaloCellMBAverageCorr.cxx +++ b/Calorimeter/CaloCellCorrection/src/CaloCellMBAverageCorr.cxx @@ -44,7 +44,8 @@ StatusCode CaloCellMBAverageCorr::initialize() // ============================================================================ -void CaloCellMBAverageCorr::MakeCorrection(CaloCell* theCell) +void CaloCellMBAverageCorr::MakeCorrection (CaloCell* theCell, + const EventContext& /*ctx*/) const { float pedestal = m_caloMBAverageTool->average(theCell); theCell->addEnergy(-pedestal); diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx index fb7500c582d..32de6d8292c 100755 --- a/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx +++ b/Calorimeter/CaloCellCorrection/src/CaloCellPedestalCorr.cxx @@ -49,7 +49,6 @@ CaloCellPedestalCorr::CaloCellPedestalCorr( declareProperty("LumiFolderName",m_lumiFolderName="/TRIGGER/LUMI/LBLESTONL"); declareProperty("LumiBCIDTool",m_caloLumiBCIDTool,"Tool for BCID pileup offset average correction"); declareProperty("isMC",m_isMC,"Data/MC flag"); - m_lastIt=m_noiseBlobMap.begin(); } //======================================================== @@ -147,7 +146,7 @@ StatusCode CaloCellPedestalCorr::updateMap(IOVSVC_CALLBACK_ARGS_K(keys) ) unsigned int sysId = static_cast<unsigned int>(iColl->first); //=== delete old CaloCondBlobFlt (which does not own the blob) - std::map<unsigned int, const CaloCondBlobFlt*>::iterator iOld = m_noiseBlobMap.find(sysId); + NoiseBlobMap_t::iterator iOld = m_noiseBlobMap.find(sysId); if(iOld != m_noiseBlobMap.end()){ delete iOld->second; } @@ -160,13 +159,13 @@ StatusCode CaloCellPedestalCorr::updateMap(IOVSVC_CALLBACK_ARGS_K(keys) ) m_noiseBlobMap[sysId] = flt; }//end iColl - m_lastIt=m_noiseBlobMap.begin(); return StatusCode::SUCCESS; } // ============================================================================ -void CaloCellPedestalCorr::MakeCorrection(CaloCell* theCell) +void CaloCellPedestalCorr::MakeCorrection (CaloCell* theCell, + const EventContext& ctx) const { float pedestal=0.; @@ -176,19 +175,22 @@ void CaloCellPedestalCorr::MakeCorrection(CaloCell* theCell) unsigned int subHash; const unsigned int iCool = m_caloCoolIdTool->getCoolChannelId(cellHash,subHash); //std::cout << "Got iCool=" << iCool << " subhash=" << subHash << std::endl; - if (m_lastIt->first!=iCool) { - m_lastIt=m_noiseBlobMap.find(iCool); - } - //The following checks would make sense but were obmitted to speed up execution: - //1. m_lastIt!=m_noiseBlobMap.end() eg, if iCool exists + NoiseBlobMap_t::const_iterator it = m_noiseBlobMap.find (iCool); + //The following checks would make sense but were omitted to speed up execution: + //1. it!=m_noiseBlobMap.end() eg, if iCool exists //2. subHash < flt->getNChans() - const CaloCondBlobFlt* const flt = m_lastIt->second; + const CaloCondBlobFlt* const flt = it->second; const unsigned int dbGain = CaloCondUtils::getDbCaloGain(theCell->gain()); pedestal = flt->getCalib(subHash, dbGain, m_lumi0); } if (!m_caloLumiBCIDTool.empty() ) { - pedestal = pedestal + m_caloLumiBCIDTool->average(theCell,0); + // FIXME: CaloLumiBCIDTool has threading issues. + // Refuse to proceed if we're running with multiple threads. + if (ctx.slot() > 1) { + std::abort(); + } + pedestal = pedestal + m_caloLumiBCIDTool->average(theCell,0); } theCell->addEnergy(-pedestal); diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellRandomizer.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellRandomizer.cxx index f4d49f600c3..80355e2805a 100644 --- a/Calorimeter/CaloCellCorrection/src/CaloCellRandomizer.cxx +++ b/Calorimeter/CaloCellCorrection/src/CaloCellRandomizer.cxx @@ -75,9 +75,9 @@ StatusCode CaloCellRandomizer::initialize() // ============================================================================ -void CaloCellRandomizer::MakeCorrection (CaloCell* theCell) +void CaloCellRandomizer::MakeCorrection (CaloCell* theCell, + const EventContext& ctx) const { - const EventContext& ctx = Gaudi::Hive::currentContext(); CLHEP::HepRandomEngine* engine = m_randomEngine->getEngine (ctx); int sampl = 0; diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellRescaler.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellRescaler.cxx index f378a92feb3..588babd9293 100755 --- a/Calorimeter/CaloCellCorrection/src/CaloCellRescaler.cxx +++ b/Calorimeter/CaloCellCorrection/src/CaloCellRescaler.cxx @@ -49,8 +49,9 @@ StatusCode CaloCellRescaler::initialize() { } -void CaloCellRescaler::MakeCorrection(CaloCell* theCell) { - +void CaloCellRescaler::MakeCorrection (CaloCell* theCell, + const EventContext& /*ctx*/) const +{ const CaloDetDescrElement* caloDDE = theCell->caloDDE(); if (caloDDE) { theCell->scaleEnergy( m_factorToCells[caloDDE->getSampling()] ); diff --git a/Calorimeter/CaloCellCorrection/src/CaloCellTimeCorrTool.cxx b/Calorimeter/CaloCellCorrection/src/CaloCellTimeCorrTool.cxx index c90c10c5af7..fee98be0c19 100644 --- a/Calorimeter/CaloCellCorrection/src/CaloCellTimeCorrTool.cxx +++ b/Calorimeter/CaloCellCorrection/src/CaloCellTimeCorrTool.cxx @@ -51,7 +51,9 @@ StatusCode CaloCellTimeCorrTool::load(IOVSVC_CALLBACK_ARGS) { } -void CaloCellTimeCorrTool::MakeCorrection(CaloCell* theCell) { +void CaloCellTimeCorrTool::MakeCorrection (CaloCell* theCell, + const EventContext& /*ctx*/) const +{ if (m_corrValues) { const IdentifierHash& hash_id=theCell->caloDDE()->calo_hash(); if (hash_id<m_corrValues->getNChans()) { -- GitLab