diff --git a/Calibration/Tools/interface/EcalRingCalibrationTools.h b/Calibration/Tools/interface/EcalRingCalibrationTools.h index 4447ec459fef4..12c1f386b7f5a 100644 --- a/Calibration/Tools/interface/EcalRingCalibrationTools.h +++ b/Calibration/Tools/interface/EcalRingCalibrationTools.h @@ -11,6 +11,8 @@ ***************************************/ #include +#include +#include #include "DataFormats/EcalDetId/interface/EBDetId.h" #include "DataFormats/EcalDetId/interface/EEDetId.h" @@ -33,21 +35,23 @@ class EcalRingCalibrationTools static std::vector getDetIdsInModule(short int); static std::vector getDetIdsInECAL(); - static const short N_RING_TOTAL = 248; - static const short N_RING_BARREL = 170 ; - static const short N_RING_ENDCAP = 78; + static const short N_RING_TOTAL = 248; + static const short N_RING_BARREL = 170; + static const short N_RING_ENDCAP = 78; static const short N_MODULES_BARREL = 144; - static void setCaloGeometry(const CaloGeometry* geometry) { caloGeometry_ = geometry; }; + static void setCaloGeometry(const CaloGeometry* geometry); private: - - static void initializeFromGeometry(); //needed only for the endcap + static void initializeFromGeometry(CaloGeometry const* geometry); // needed only for the endcap - static bool isInitializedFromGeometry_; - static short endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX]; //array needed only for the endcaps - static const CaloGeometry* caloGeometry_; + static std::atomic isInitializedFromGeometry_; + + [[cms::thread_guard("isInitializedFromGeometry_")]] + static short endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX]; // array needed only for the endcaps + + static std::once_flag once_; }; #endif diff --git a/Calibration/Tools/src/EcalRingCalibrationTools.cc b/Calibration/Tools/src/EcalRingCalibrationTools.cc index 90fbc8a1f1ae9..cf90f5173e03e 100644 --- a/Calibration/Tools/src/EcalRingCalibrationTools.cc +++ b/Calibration/Tools/src/EcalRingCalibrationTools.cc @@ -10,11 +10,10 @@ #include - //by default is not initialized, gets initialized at first call -bool EcalRingCalibrationTools::isInitializedFromGeometry_ = false; -const CaloGeometry* EcalRingCalibrationTools::caloGeometry_ = 0; +std::atomic EcalRingCalibrationTools::isInitializedFromGeometry_(false); short EcalRingCalibrationTools::endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX]; +std::once_flag EcalRingCalibrationTools::once_; short EcalRingCalibrationTools::getRingIndex(DetId id) @@ -33,8 +32,9 @@ short EcalRingCalibrationTools::getRingIndex(DetId id) if (id.subdetId() == EcalEndcap) { //needed only for the EE, it can be replaced at some point with something smarter - if (!isInitializedFromGeometry_) - initializeFromGeometry(); + if (not isInitializedFromGeometry_) + throw std::logic_error("EcalRingCalibrationTools::initializeFromGeometry Ecal Endcap geometry is not initialized"); + EEDetId eid(id); short endcapRingIndex = endcapRingIndex_[eid.ix()-1][eid.iy()-1] + N_RING_BARREL; if (eid.zside() == 1) endcapRingIndex += N_RING_ENDCAP/2; @@ -71,7 +71,6 @@ short EcalRingCalibrationTools::getModuleIndex(DetId id) std::vector EcalRingCalibrationTools::getDetIdsInRing(short etaIndex) { - std::vector ringIds; if (etaIndex < 0) return ringIds; @@ -94,8 +93,8 @@ std::vector EcalRingCalibrationTools::getDetIdsInRing(short etaIndex) else if (etaIndex < N_RING_TOTAL) { //needed only for the EE, it can be replaced at some point maybe with something smarter - if (!isInitializedFromGeometry_) - initializeFromGeometry(); + if (not isInitializedFromGeometry_) + throw std::logic_error("EcalRingCalibrationTools::initializeFromGeometry Ecal Endcap geometry is not initialized"); int zside= (etaIndex < N_RING_BARREL + (N_RING_ENDCAP/2) ) ? -1 : 1; short eeEtaIndex = (etaIndex - N_RING_BARREL)%(N_RING_ENDCAP/2); @@ -112,7 +111,6 @@ std::vector EcalRingCalibrationTools::getDetIdsInRing(short etaIndex) std::vector EcalRingCalibrationTools::getDetIdsInECAL() { - std::vector ringIds; for(int ieta= - EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) @@ -121,8 +119,8 @@ std::vector EcalRingCalibrationTools::getDetIdsInECAL() ringIds.push_back(EBDetId(ieta,iphi)); //needed only for the EE, it can be replaced at some point maybe with something smarter - if (!isInitializedFromGeometry_) - initializeFromGeometry(); + if (not isInitializedFromGeometry_) + throw std::logic_error("EcalRingCalibrationTools::initializeFromGeometry Ecal Endcap geometry is not initialized"); for (int ix=0;ix EcalRingCalibrationTools::getDetIdsInModule(short moduleIndex return ringIds; } -void EcalRingCalibrationTools::initializeFromGeometry() -{ +void EcalRingCalibrationTools::setCaloGeometry(const CaloGeometry* geometry) +{ + std::call_once(once_, EcalRingCalibrationTools::initializeFromGeometry, geometry); +} - if (!caloGeometry_) - { - edm::LogError("EcalRingCalibrationTools") << "BIG ERROR::Initializing without geometry handle" ; - return; - } +void EcalRingCalibrationTools::initializeFromGeometry(CaloGeometry const* geometry) +{ + if (not geometry) + throw std::invalid_argument("EcalRingCalibrationTools::initializeFromGeometry called with a nullptr argument"); - float m_cellPosEta[EEDetId::IX_MAX][EEDetId::IY_MAX]; + float cellPosEta[EEDetId::IX_MAX][EEDetId::IY_MAX]; for (int ix=0; ixgetSubdetectorGeometry(DetId::Ecal, EcalEndcap); - - if (!endcapGeometry) + for (int iy=0; iygetSubdetectorGeometry(DetId::Ecal, EcalEndcap); + if (not endcapGeometry) + throw std::logic_error("EcalRingCalibrationTools::initializeFromGeometry Ecal Endcap geometry not found"); - const std::vector& m_endcapCells= caloGeometry_->getValidDetIds(DetId::Ecal, EcalEndcap); + std::vector const& endcapCells = geometry->getValidDetIds(DetId::Ecal, EcalEndcap); - for (std::vector::const_iterator endcapIt = m_endcapCells.begin(); - endcapIt!=m_endcapCells.end(); + for (std::vector::const_iterator endcapIt = endcapCells.begin(); + endcapIt!=endcapCells.end(); ++endcapIt) { EEDetId ee(*endcapIt); @@ -237,15 +231,13 @@ void EcalRingCalibrationTools::initializeFromGeometry() const CaloCellGeometry *cellGeometry = endcapGeometry->getGeometry(*endcapIt) ; int ics=ee.ix() - 1 ; int ips=ee.iy() - 1 ; - m_cellPosEta[ics][ips] = fabs(cellGeometry->getPosition().eta()); - + cellPosEta[ics][ips] = fabs(cellGeometry->getPosition().eta()); //std::cout<<"EE Xtal, |eta| is "<getPosition().eta())<etaBoundary[ring] && m_cellPosEta[ix][iy]etaBoundary[ring] && cellPosEta[ix][iy]& m_barrelCells= caloGeometry_->getValidDetIds(DetId::Ecal, EcalBarrel); + std::vector const& barrelCells = geometry->getValidDetIds(DetId::Ecal, EcalBarrel); - for (std::vector::const_iterator barrelIt = m_barrelCells.begin(); - barrelIt!=m_barrelCells.end(); + for (std::vector::const_iterator barrelIt = barrelCells.begin(); + barrelIt!=barrelCells.end(); ++barrelIt) { EBDetId eb(*barrelIt); } - //EB isInitializedFromGeometry_ = true; diff --git a/HLTrigger/special/src/HLTEcalPhiSymFilter.cc b/HLTrigger/special/src/HLTEcalPhiSymFilter.cc index 0a5b9cf1a884d..9305e55a6952b 100644 --- a/HLTrigger/special/src/HLTEcalPhiSymFilter.cc +++ b/HLTrigger/special/src/HLTEcalPhiSymFilter.cc @@ -80,7 +80,7 @@ HLTEcalPhiSymFilter::filter(edm::StreamID, edm::Event & event, const edm::EventS //Get iRing-geometry edm::ESHandle geoHandle; setup.get().get(geoHandle); - EcalRingCalibrationTools::setCaloGeometry(&(*geoHandle)); + EcalRingCalibrationTools::setCaloGeometry(geoHandle.product()); EcalRingCalibrationTools CalibRing; static const short N_RING_BARREL = EcalRingCalibrationTools::N_RING_BARREL;