Skip to content

Commit

Permalink
Merge pull request #38458 from Dr15Jones/threadSafeCSCIndexer
Browse files Browse the repository at this point in the history
Made CSCIndexer const thread-safe
  • Loading branch information
cmsbuild committed Jun 23, 2022
2 parents 26397c3 + e7e2c9d commit 2aaffda
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
8 changes: 4 additions & 4 deletions DataFormats/MuonDetId/interface/CSCIndexer.h
Expand Up @@ -111,7 +111,7 @@ class CSCIndexer {
*
* BEWARE! Includes ME42 so claims 2 rings in station 4. There is only 1 at CSC installation 2008.
*/
IndexType ringsInStation(IndexType is) const {
static IndexType ringsInStation(IndexType is) {
const IndexType nrins[5] = {0, 3, 2, 2, 2}; // rings per station
return nrins[is];
}
Expand All @@ -121,7 +121,7 @@ class CSCIndexer {
*
* Works for ME1a (ring 4 of ME1) too.
*/
IndexType chambersInRingOfStation(IndexType is, IndexType ir) const {
static IndexType chambersInRingOfStation(IndexType is, IndexType ir) {
IndexType nc = 36; // most rings have 36 chambers
if (is > 1 && ir < 2)
nc = 18; // but 21, 31, 41 have 18
Expand Down Expand Up @@ -419,9 +419,9 @@ class CSCIndexer {
int dbIndex(const CSCDetId& id, int& channel);

private:
void fillChamberLabel() const; // const so it can be called in const function detIdFromChamberIndex
static std::vector<IndexType> fillChamberLabel();

mutable std::vector<IndexType> chamberLabel; // mutable so can be filled by fillChamberLabel
static std::vector<IndexType> const& chamberLabel();
};

#endif
24 changes: 14 additions & 10 deletions DataFormats/MuonDetId/src/CSCIndexer.cc
@@ -1,24 +1,32 @@
#include <DataFormats/MuonDetId/interface/CSCIndexer.h>
#include <iostream>

void CSCIndexer::fillChamberLabel() const {
std::vector<CSCIndexer::IndexType> CSCIndexer::fillChamberLabel() {
// Fill the member vector which permits decoding of the linear chamber index
// Logically const since initializes cache only,
// Beware that the ME42 indices 235-270 within this vector do NOT correspond to
// their 'real' linear indices (which are 469-504 for +z)
chamberLabel.resize(271); // one more than #chambers per endcap. Includes ME42.
std::vector<IndexType> tChamberLabel;

tChamberLabel.resize(271); // one more than #chambers per endcap. Includes ME42.
IndexType count = 0;
chamberLabel[count] = 0;
tChamberLabel[count] = 0;

for (IndexType is = 1; is != 5; ++is) {
IndexType irmax = ringsInStation(is);
for (IndexType ir = 1; ir != irmax + 1; ++ir) {
IndexType icmax = chambersInRingOfStation(is, ir);
for (IndexType ic = 1; ic != icmax + 1; ++ic) {
chamberLabel[++count] = is * 1000 + ir * 100 + ic;
tChamberLabel[++count] = is * 1000 + ir * 100 + ic;
}
}
}
return tChamberLabel;
}

const std::vector<CSCIndexer::IndexType>& CSCIndexer::chamberLabel() {
static const auto s_chamberLabel = fillChamberLabel();
return s_chamberLabel;
}

CSCDetId CSCIndexer::detIdFromChamberIndex_OLD(IndexType ici) const {
Expand Down Expand Up @@ -76,9 +84,7 @@ CSCDetId CSCIndexer::detIdFromChamberIndex(IndexType ici) const {
ici -= 234; // now in range 1-234
}
}
if (chamberLabel.empty())
fillChamberLabel();
IndexType label = chamberLabel[ici];
IndexType label = chamberLabel()[ici];
return detIdFromChamberLabel(ie, label);
}

Expand All @@ -99,9 +105,7 @@ CSCIndexer::IndexType CSCIndexer::chamberLabelFromChamberIndex(IndexType ici) co
ici -= 234; // now in range 1-234
}
}
if (chamberLabel.empty())
fillChamberLabel();
return chamberLabel[ici];
return chamberLabel()[ici];
}

CSCDetId CSCIndexer::detIdFromChamberLabel(IndexType ie, IndexType label) const {
Expand Down

0 comments on commit 2aaffda

Please sign in to comment.