Skip to content

Commit

Permalink
make static config pointers thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Riley authored and Dan Riley committed Feb 14, 2022
1 parent 09bb0b7 commit 48bb44b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 35 deletions.
5 changes: 3 additions & 2 deletions L1Trigger/DTTrackFinder/interface/L1MuDTTrackFinder.h
Expand Up @@ -25,6 +25,7 @@
//---------------

#include <vector>
#include <memory>

//----------------------
// Base Class Headers --
Expand Down Expand Up @@ -99,7 +100,7 @@ class L1MuDTTrackFinder {
int numberOfTracks(int bx);

/// return configuration
static L1MuDTTFConfig* config() { return m_config; }
static L1MuDTTFConfig* config() { return m_config.get(); }

std::vector<L1MuDTTrackCand>& getcache0() { return _cache0; }

Expand All @@ -121,7 +122,7 @@ class L1MuDTTrackFinder {
L1MuDTMuonSorter* m_ms; ///< DT Muon Sorter
edm::EDGetTokenT<L1MuDTChambPhContainer> m_DTDigiToken;

static L1MuDTTFConfig* m_config; ///< Track Finder configuration
static std::shared_ptr<L1MuDTTFConfig> m_config; ///< Track Finder configuration
};

#endif
13 changes: 6 additions & 7 deletions L1Trigger/DTTrackFinder/src/L1MuDTTrackFinder.cc
Expand Up @@ -53,8 +53,11 @@ using namespace std;

L1MuDTTrackFinder::L1MuDTTrackFinder(const edm::ParameterSet& ps, edm::ConsumesCollector&& iC) {
// set configuration parameters
if (m_config == nullptr)
m_config = new L1MuDTTFConfig(ps);
if (not m_config) {
auto temp = std::make_shared<L1MuDTTFConfig>(ps);
std::shared_ptr<L1MuDTTFConfig> empty;
std::atomic_compare_exchange_strong(&m_config, &empty, temp);
}

if (m_config->Debug(1))
cout << endl;
Expand Down Expand Up @@ -96,10 +99,6 @@ L1MuDTTrackFinder::~L1MuDTTrackFinder() {
m_wsvec.clear();

delete m_ms;

if (m_config)
delete m_config;
m_config = nullptr;
}

//--------------
Expand Down Expand Up @@ -322,4 +321,4 @@ int L1MuDTTrackFinder::numberOfTracks(int bx) {

// static data members

L1MuDTTFConfig* L1MuDTTrackFinder::m_config = nullptr;
std::shared_ptr<L1MuDTTFConfig> L1MuDTTrackFinder::m_config;
8 changes: 5 additions & 3 deletions L1Trigger/GlobalMuonTrigger/interface/L1MuGlobalMuonTrigger.h
Expand Up @@ -17,6 +17,8 @@
// C++ Headers --
//---------------

#include <memory>

//----------------------
// Base Class Headers --
//----------------------
Expand Down Expand Up @@ -98,7 +100,7 @@ class L1MuGlobalMuonTrigger : public edm::one::EDProducer<edm::one::SharedResour
L1MuGMTReadoutRecord* currentReadoutRecord() const { return m_ReadoutRingbuffer.back(); };

/// for debug: return the debug block (in order to fill it)
L1MuGMTDebugBlock* DebugBlockForFill() const { return m_db; };
L1MuGMTDebugBlock* DebugBlockForFill() const { return m_db.get(); };

private:
L1MuGMTPSB* m_PSB;
Expand All @@ -114,9 +116,9 @@ class L1MuGlobalMuonTrigger : public edm::one::EDProducer<edm::one::SharedResour
bool m_writeLUTsAndRegs;
bool m_sendMipIso;

static L1MuGMTConfig* m_config;
static std::shared_ptr<L1MuGMTConfig> m_config;

static L1MuGMTDebugBlock* m_db;
static std::shared_ptr<L1MuGMTDebugBlock> m_db;

unsigned long long m_L1MuGMTScalesCacheID;
unsigned long long m_L1MuTriggerScalesCacheID;
Expand Down
26 changes: 12 additions & 14 deletions L1Trigger/GlobalMuonTrigger/src/L1MuGlobalMuonTrigger.cc
Expand Up @@ -71,8 +71,11 @@ L1MuGlobalMuonTrigger::L1MuGlobalMuonTrigger(const edm::ParameterSet& ps) {
m_ExtendedCands.reserve(20);

// set configuration parameters
if (!m_config)
m_config = new L1MuGMTConfig(ps);
if (not m_config) {
auto temp = std::make_shared<L1MuGMTConfig>(ps);
std::shared_ptr<L1MuGMTConfig> empty;
std::atomic_compare_exchange_strong(&m_config, &empty, temp);
}
m_writeLUTsAndRegs = ps.getUntrackedParameter<bool>("WriteLUTsAndRegs", false);

// build GMT
Expand Down Expand Up @@ -119,8 +122,11 @@ L1MuGlobalMuonTrigger::L1MuGlobalMuonTrigger(const edm::ParameterSet& ps) {
edm::LogVerbatim("GMT_info") << "creating GMT Sorter";
m_Sorter = new L1MuGMTSorter(*this); // barrel

if (!m_db)
m_db = new L1MuGMTDebugBlock(m_config->getBxMin(), m_config->getBxMax());
if (not m_db) {
auto temp = std::make_shared<L1MuGMTDebugBlock>(m_config->getBxMin(), m_config->getBxMax());
std::shared_ptr<L1MuGMTDebugBlock> empty;
std::atomic_compare_exchange_strong(&m_db, &empty, temp);
}
usesResource("L1MuGlobalMuonTrigger");
///EventSetup Tokens
m_gmtScalesToken = esConsumes<L1MuGMTScales, L1MuGMTScalesRcd>();
Expand All @@ -135,10 +141,6 @@ L1MuGlobalMuonTrigger::L1MuGlobalMuonTrigger(const edm::ParameterSet& ps) {
// Destructor --
//--------------
L1MuGlobalMuonTrigger::~L1MuGlobalMuonTrigger() {
if (m_db)
delete m_db;
m_db = nullptr;

delete m_Sorter;
delete m_Merger[1]; // endcap Merger
delete m_Merger[0]; // barrel Merger
Expand All @@ -152,10 +154,6 @@ L1MuGlobalMuonTrigger::~L1MuGlobalMuonTrigger() {
delete m_Matcher[0]; // barrel matcher
delete m_PSB;

if (m_config)
delete m_config;
m_config = nullptr;

// copied from produce() by Jim B, 7 Aug 2007
std::vector<L1MuGMTReadoutRecord*>::iterator irr = m_ReadoutRingbuffer.begin();
for (; irr != m_ReadoutRingbuffer.end(); irr++)
Expand Down Expand Up @@ -452,5 +450,5 @@ std::unique_ptr<L1MuGMTReadoutCollection> L1MuGlobalMuonTrigger::getReadoutColle

// static data members

L1MuGMTConfig* L1MuGlobalMuonTrigger::m_config = nullptr;
L1MuGMTDebugBlock* L1MuGlobalMuonTrigger::m_db = nullptr;
std::shared_ptr<L1MuGMTConfig> L1MuGlobalMuonTrigger::m_config;
std::shared_ptr<L1MuGMTDebugBlock> L1MuGlobalMuonTrigger::m_db;
6 changes: 4 additions & 2 deletions L1Trigger/L1TMuonBarrel/interface/L1MuBMTrackFinder.h
Expand Up @@ -27,6 +27,8 @@

#include <vector>
#include <iostream>
#include <memory>

//----------------------
// Base Class Headers --
//----------------------
Expand Down Expand Up @@ -114,7 +116,7 @@ class L1MuBMTrackFinder {
int numberOfTracks(int bx);

/// return configuration
static const L1MuBMTFConfig* config() { return m_config; }
static const L1MuBMTFConfig* config() { return m_config.get(); }

l1t::RegionalMuonCandBxCollection& getcache() { return _cache; }
l1t::RegionalMuonCandBxCollection& getcache0() { return _cache0; }
Expand All @@ -141,7 +143,7 @@ class L1MuBMTrackFinder {
std::vector<L1MuBMWedgeSorter*> m_wsvec; ///< Wedge Sorters
L1MuBMMuonSorter* m_ms; ///< BM Muon Sorter

static L1MuBMTFConfig* m_config; ///< Track Finder configuration
static std::shared_ptr<L1MuBMTFConfig> m_config; ///< Track Finder configuration

edm::EDGetTokenT<L1MuDTChambPhContainer> m_DTDigiToken;
edm::ESGetToken<L1TMuonBarrelParams, L1TMuonBarrelParamsRcd> m_mbParamsToken;
Expand Down
13 changes: 6 additions & 7 deletions L1Trigger/L1TMuonBarrel/src/L1MuBMTrackFinder.cc
Expand Up @@ -60,8 +60,11 @@ using namespace std;
L1MuBMTrackFinder::L1MuBMTrackFinder(const edm::ParameterSet& ps, edm::ConsumesCollector&& iC)
: _cache0(144, -9, 8), _cache(36, -9, 8) {
// set configuration parameters
if (m_config == nullptr)
m_config = new L1MuBMTFConfig(ps);
if (not m_config) {
auto temp = std::make_shared<L1MuBMTFConfig>(ps);
std::shared_ptr<L1MuBMTFConfig> empty;
std::atomic_compare_exchange_strong(&m_config, &empty, temp);
}

if (L1MuBMTFConfig::Debug(1))
cout << endl;
Expand Down Expand Up @@ -101,10 +104,6 @@ L1MuBMTrackFinder::~L1MuBMTrackFinder() {
m_wsvec.clear();

delete m_ms;

if (m_config)
delete m_config;
m_config = nullptr;
}

//--------------
Expand Down Expand Up @@ -528,4 +527,4 @@ int L1MuBMTrackFinder::setAdd(int ust, int rel_add) {

// static data members

L1MuBMTFConfig* L1MuBMTrackFinder::m_config = nullptr;
std::shared_ptr<L1MuBMTFConfig> L1MuBMTrackFinder::m_config;

0 comments on commit 48bb44b

Please sign in to comment.