Skip to content

Commit

Permalink
Merge pull request #38475 from Dr15Jones/threadSafeFebConnectorSpec
Browse files Browse the repository at this point in the history
Made FebConnectorSpec const thread-safe
  • Loading branch information
cmsbuild committed Jun 23, 2022
2 parents 86c38c4 + 27f0b69 commit 0aff7a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
8 changes: 6 additions & 2 deletions CondFormats/RPCObjects/interface/FebConnectorSpec.h
Expand Up @@ -9,6 +9,7 @@
#include "CondFormats/RPCObjects/interface/ChamberLocationSpec.h"
#include "CondFormats/RPCObjects/interface/FebLocationSpec.h"
#include <string>
#include <atomic>

/** \class FebConnectorSpec
* Specifies the input for LinkBoard. In hardware the data goes through
Expand All @@ -24,6 +25,9 @@ class FebConnectorSpec {
public:
FebConnectorSpec(int num = -1) : theLinkBoardInputNum(num), theRawId(0) {}
FebConnectorSpec(int num, const ChamberLocationSpec& chamber, const FebLocationSpec& feb);
FebConnectorSpec(FebConnectorSpec const&);

FebConnectorSpec& operator=(FebConnectorSpec const&);

/// this FEB channel in LinkBoard
int linkBoardInputNum() const { return theLinkBoardInputNum; }
Expand All @@ -35,7 +39,7 @@ class FebConnectorSpec {
const ChamberStripSpec strip(int pinNumber) const;

/// DetUnit to which data belongs
const uint32_t& rawId() const;
uint32_t rawId() const;

const ChamberLocationSpec& chamber() const { return theChamber; }
const FebLocationSpec& feb() const { return theFeb; }
Expand All @@ -58,7 +62,7 @@ class FebConnectorSpec {
FebLocationSpec theFeb;

int theAlgo;
mutable uint32_t theRawId COND_TRANSIENT;
mutable std::atomic<uint32_t> theRawId COND_TRANSIENT;

COND_SERIALIZABLE;
};
Expand Down
26 changes: 22 additions & 4 deletions CondFormats/RPCObjects/src/FebConnectorSpec.cc
Expand Up @@ -6,6 +6,22 @@
FebConnectorSpec::FebConnectorSpec(int num, const ChamberLocationSpec& chamber, const FebLocationSpec& feb)
: theLinkBoardInputNum(num), theChamber(chamber), theFeb(feb), theAlgo(0), theRawId(0) {}

FebConnectorSpec::FebConnectorSpec(FebConnectorSpec const& iOther)
: theLinkBoardInputNum(iOther.theLinkBoardInputNum),
theChamber(iOther.theChamber),
theFeb(iOther.theFeb),
theAlgo(iOther.theAlgo),
theRawId(iOther.theRawId.load()) {}

FebConnectorSpec& FebConnectorSpec::operator=(FebConnectorSpec const& iOther) {
theLinkBoardInputNum = iOther.theLinkBoardInputNum;
theChamber = iOther.theChamber;
theFeb = iOther.theFeb;
theAlgo = iOther.theAlgo;
theRawId.store(iOther.theRawId.load());
return *this;
}

const ChamberStripSpec FebConnectorSpec::strip(int pinNumber) const {
int nStrips = theAlgo / 10000;
int firstChamberStrip = (theAlgo - 10000 * nStrips) / 100;
Expand Down Expand Up @@ -61,11 +77,13 @@ const int FebConnectorSpec::cablePinNum(int istrip) const {
return thePin;
}

const uint32_t& FebConnectorSpec::rawId() const {
uint32_t FebConnectorSpec::rawId() const {
DBSpecToDetUnit toDU;
if (!theRawId)
theRawId = toDU(theChamber, theFeb);
return theRawId;
if (!theRawId) {
uint32_t expected = 0;
theRawId.compare_exchange_strong(expected, toDU(theChamber, theFeb));
}
return theRawId.load();
}

std::string FebConnectorSpec::print(int depth) const {
Expand Down

0 comments on commit 0aff7a1

Please sign in to comment.