Skip to content

Commit 54da0a7

Browse files
committed
GCC14: Avoid using deprecated std::atomic_load and use std::atomic<std::shared_ptr<T>> instead
1 parent 5b035c6 commit 54da0a7

File tree

2 files changed

+34
-33
lines changed

2 files changed

+34
-33
lines changed

L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class L1MuGlobalMuonTrigger : public edm::one::EDProducer<edm::one::SharedResour
100100
L1MuGMTReadoutRecord* currentReadoutRecord() const { return m_ReadoutRingbuffer.back(); };
101101

102102
/// for debug: return the debug block (in order to fill it)
103-
L1MuGMTDebugBlock* DebugBlockForFill() const { return m_db.get(); };
103+
L1MuGMTDebugBlock* DebugBlockForFill() const { return m_db.load(std::memory_order_acquire).get(); };
104104

105105
private:
106106
L1MuGMTPSB* m_PSB;
@@ -116,9 +116,9 @@ class L1MuGlobalMuonTrigger : public edm::one::EDProducer<edm::one::SharedResour
116116
bool m_writeLUTsAndRegs;
117117
bool m_sendMipIso;
118118

119-
static std::shared_ptr<L1MuGMTConfig> m_config;
119+
static std::atomic<std::shared_ptr<L1MuGMTConfig>> m_config;
120120

121-
static std::shared_ptr<L1MuGMTDebugBlock> m_db;
121+
static std::atomic<std::shared_ptr<L1MuGMTDebugBlock>> m_db;
122122

123123
unsigned long long m_L1MuGMTScalesCacheID;
124124
unsigned long long m_L1MuTriggerScalesCacheID;

L1Trigger/GlobalMuonTrigger/src/L1MuGlobalMuonTrigger.cc

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@
5454
// Constructors --
5555
//----------------
5656
L1MuGlobalMuonTrigger::L1MuGlobalMuonTrigger(const edm::ParameterSet& ps) {
57-
produces<std::vector<L1MuGMTCand> >();
57+
produces<std::vector<L1MuGMTCand>>();
5858
produces<L1MuGMTReadoutCollection>();
5959
m_sendMipIso = ps.getUntrackedParameter<bool>("SendMipIso", false);
6060
if (m_sendMipIso) {
61-
produces<std::vector<unsigned> >();
61+
produces<std::vector<unsigned>>();
6262
}
6363

6464
m_L1MuGMTScalesCacheID = 0ULL;
@@ -71,11 +71,10 @@ L1MuGlobalMuonTrigger::L1MuGlobalMuonTrigger(const edm::ParameterSet& ps) {
7171
m_ExtendedCands.reserve(20);
7272

7373
// set configuration parameters
74-
if (!std::atomic_load(&m_config)) { // Atomically load m_config
74+
if (!m_config.load(std::memory_order_acquire)) {
7575
auto temp = std::make_shared<L1MuGMTConfig>(ps);
76-
std::shared_ptr<L1MuGMTConfig> empty = nullptr; // Explicit nullptr for CAS
77-
std::atomic_compare_exchange_strong_explicit(
78-
&m_config, &empty, temp, std::memory_order_acq_rel, std::memory_order_acquire);
76+
std::shared_ptr<L1MuGMTConfig> expected = nullptr;
77+
m_config.compare_exchange_strong(expected, temp, std::memory_order_acq_rel, std::memory_order_acquire);
7978
}
8079
m_writeLUTsAndRegs = ps.getUntrackedParameter<bool>("WriteLUTsAndRegs", false);
8180

@@ -123,11 +122,11 @@ L1MuGlobalMuonTrigger::L1MuGlobalMuonTrigger(const edm::ParameterSet& ps) {
123122
edm::LogVerbatim("GMT_info") << "creating GMT Sorter";
124123
m_Sorter = new L1MuGMTSorter(*this); // barrel
125124

126-
if (!std::atomic_load(&m_db)) { // Atomically load m_db
127-
auto temp = std::make_shared<L1MuGMTDebugBlock>(m_config->getBxMin(), m_config->getBxMax());
128-
std::shared_ptr<L1MuGMTDebugBlock> empty = nullptr; // Explicit nullptr for CAS
129-
std::atomic_compare_exchange_strong_explicit(
130-
&m_db, &empty, temp, std::memory_order_acq_rel, std::memory_order_acquire);
125+
if (!m_db.load(std::memory_order_acquire)) {
126+
auto config = m_config.load(std::memory_order_acquire);
127+
auto temp = std::make_shared<L1MuGMTDebugBlock>(config->getBxMin(), config->getBxMax());
128+
std::shared_ptr<L1MuGMTDebugBlock> expected = nullptr;
129+
m_db.compare_exchange_strong(expected, temp, std::memory_order_acq_rel, std::memory_order_acquire);
131130
}
132131
usesResource("L1MuGlobalMuonTrigger");
133132
///EventSetup Tokens
@@ -174,34 +173,35 @@ void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
174173
// configure from the event setup
175174

176175
unsigned long long L1MuGMTScalesCacheID = es.get<L1MuGMTScalesRcd>().cacheIdentifier();
176+
auto config = m_config.load();
177177
if (L1MuGMTScalesCacheID != m_L1MuGMTScalesCacheID) {
178178
edm::ESHandle<L1MuGMTScales> gmtscales_h = es.getHandle(m_gmtScalesToken);
179-
m_config->setGMTScales(gmtscales_h.product());
179+
config->setGMTScales(gmtscales_h.product());
180180
}
181181

182182
unsigned long long L1MuTriggerScalesCacheID = es.get<L1MuTriggerScalesRcd>().cacheIdentifier();
183183
if (L1MuTriggerScalesCacheID != m_L1MuTriggerScalesCacheID) {
184184
edm::ESHandle<L1MuTriggerScales> trigscales_h = es.getHandle(m_trigScalesToken);
185-
m_config->setTriggerScales(trigscales_h.product());
185+
config->setTriggerScales(trigscales_h.product());
186186
}
187187

188188
unsigned long long L1MuTriggerPtScaleCacheID = es.get<L1MuTriggerPtScaleRcd>().cacheIdentifier();
189189
if (L1MuTriggerPtScaleCacheID != m_L1MuTriggerPtScaleCacheID) {
190190
edm::ESHandle<L1MuTriggerPtScale> trigptscale_h = es.getHandle(m_trigPtScaleToken);
191-
m_config->setTriggerPtScale(trigptscale_h.product());
191+
config->setTriggerPtScale(trigptscale_h.product());
192192
}
193193

194194
unsigned long long L1MuGMTParametersCacheID = es.get<L1MuGMTParametersRcd>().cacheIdentifier();
195195
if (L1MuGMTParametersCacheID != m_L1MuGMTParametersCacheID) {
196196
edm::ESHandle<L1MuGMTParameters> gmtparams_h = es.getHandle(m_gmtParamsToken);
197-
m_config->setGMTParams(gmtparams_h.product());
198-
m_config->setDefaults();
197+
config->setGMTParams(gmtparams_h.product());
198+
config->setDefaults();
199199
}
200200

201201
unsigned long long L1MuGMTChannelMaskCacheID = es.get<L1MuGMTChannelMaskRcd>().cacheIdentifier();
202202
if (L1MuGMTChannelMaskCacheID != m_L1MuGMTChannelMaskCacheID) {
203203
edm::ESHandle<L1MuGMTChannelMask> gmtchanmask_h = es.getHandle(m_gmtChanMaskToken);
204-
m_config->setGMTChanMask(gmtchanmask_h.product());
204+
config->setGMTChanMask(gmtchanmask_h.product());
205205
if (L1MuGMTConfig::Debug(1)) {
206206
std::string onoff;
207207
const L1MuGMTChannelMask* theChannelMask = L1MuGMTConfig::getGMTChanMask();
@@ -224,10 +224,10 @@ void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
224224
unsigned long long L1CaloGeometryCacheID = es.get<L1CaloGeometryRecord>().cacheIdentifier();
225225
if (L1CaloGeometryCacheID != m_L1CaloGeometryCacheID) {
226226
edm::ESHandle<L1CaloGeometry> caloGeom_h = es.getHandle(m_caloGeomToken);
227-
m_config->setCaloGeom(caloGeom_h.product());
227+
config->setCaloGeom(caloGeom_h.product());
228228
}
229229

230-
m_config->createLUTsRegs();
230+
config->createLUTsRegs();
231231

232232
// write LUTs and Regs if required
233233

@@ -236,8 +236,8 @@ void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
236236

237237
mkdir(dir.c_str(), S_ISUID | S_ISGID | S_ISVTX | S_IRUSR | S_IWUSR | S_IXUSR);
238238

239-
m_config->dumpLUTs(dir);
240-
m_config->dumpRegs(dir);
239+
config->dumpLUTs(dir);
240+
config->dumpRegs(dir);
241241
}
242242

243243
// process the event
@@ -259,11 +259,12 @@ void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
259259
delete (*irr);
260260
m_ReadoutRingbuffer.clear();
261261

262-
if (m_db)
263-
m_db->reset(); // reset debug block
262+
auto x_db = m_db.load();
263+
if (x_db)
264+
x_db->reset(); // reset debug block
264265

265266
for (int bx = bx_min; bx <= bx_max; bx++) {
266-
m_db->SetBX(bx);
267+
x_db->SetBX(bx);
267268

268269
// create new element in readout ring buffer
269270
m_ReadoutRingbuffer.push_back(new L1MuGMTReadoutRecord(bx));
@@ -376,7 +377,7 @@ void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
376377
}
377378

378379
// produce the output
379-
std::unique_ptr<std::vector<L1MuGMTCand> > GMTCands(new std::vector<L1MuGMTCand>);
380+
std::unique_ptr<std::vector<L1MuGMTCand>> GMTCands(new std::vector<L1MuGMTCand>);
380381
std::vector<L1MuGMTExtendedCand>::const_iterator iexc;
381382
for (iexc = m_ExtendedCands.begin(); iexc != m_ExtendedCands.end(); iexc++) {
382383
GMTCands->push_back(*iexc);
@@ -387,15 +388,15 @@ void L1MuGlobalMuonTrigger::produce(edm::Event& e, const edm::EventSetup& es) {
387388
e.put(std::move(GMTRRC));
388389

389390
if (m_sendMipIso) {
390-
std::unique_ptr<std::vector<unsigned> > mipiso(new std::vector<unsigned>);
391+
std::unique_ptr<std::vector<unsigned>> mipiso(new std::vector<unsigned>);
391392
for (int i = 0; i < 32; i++) {
392-
mipiso->push_back(m_db->IsMIPISO(0, i));
393+
mipiso->push_back(x_db->IsMIPISO(0, i));
393394
}
394395
e.put(std::move(mipiso));
395396
}
396397

397398
// delete registers and LUTs
398-
m_config->clearLUTsRegs();
399+
config->clearLUTsRegs();
399400
}
400401

401402
//
@@ -452,5 +453,5 @@ std::unique_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutColle
452453

453454
// static data members
454455

455-
std::shared_ptr<L1MuGMTConfig> L1MuGlobalMuonTrigger::m_config;
456-
std::shared_ptr<L1MuGMTDebugBlock> L1MuGlobalMuonTrigger::m_db;
456+
std::atomic<std::shared_ptr<L1MuGMTConfig>> L1MuGlobalMuonTrigger::m_config;
457+
std::atomic<std::shared_ptr<L1MuGMTDebugBlock>> L1MuGlobalMuonTrigger::m_db;

0 commit comments

Comments
 (0)