Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made CSCIndexer const thread-safe #38458

Merged
merged 1 commit into from Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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