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

MTD geometry: replace string with string_view in MTDBaseNumber #36106

Merged
merged 3 commits into from Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 Geometry/MTDCommonData/interface/MTDBaseNumber.h
Expand Up @@ -19,20 +19,20 @@ class MTDBaseNumber {
~MTDBaseNumber() {}

void setSize(const int& size);
void addLevel(const std::string& name, const int& copyNumber);
void addLevel(const std::string_view& name, const int& copyNumber);
fabiocos marked this conversation as resolved.
Show resolved Hide resolved

int getLevels() const;
int getCopyNumber(int level) const;
int getCopyNumber(const std::string& levelName) const;
std::string const& getLevelName(int level) const;
int getCopyNumber(const std::string_view& levelName) const;
std::string_view const& getLevelName(int level) const;
int getCapacity();

void reset();

protected:
static constexpr int MAXLEVEL = 20;

std::vector<std::string> _sortedName;
std::vector<std::string_view> _sortedName;
std::vector<int> _sortedCopyNumber;
int _theLevels;
};
Expand Down
19 changes: 10 additions & 9 deletions Geometry/MTDCommonData/src/BTLNumberingScheme.cc
Expand Up @@ -44,18 +44,19 @@ uint32_t BTLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const {
const uint32_t modCopy(baseNumber.getCopyNumber(2));
const uint32_t rodCopy(baseNumber.getCopyNumber(3));

const std::string& modName(baseNumber.getLevelName(2)); // name of module volume
const std::string_view& modName(baseNumber.getLevelName(2)); // name of module volume
uint32_t pos = modName.find("Positive");

const uint32_t zside = (pos <= strlen(modName.c_str()) ? 1 : 0);
std::string baseName = modName.substr(modName.find(':') + 1);
const uint32_t zside = (pos <= modName.size() ? 1 : 0);
std::string_view baseName = modName.substr(modName.find(':') + 1);

// trick to accomodate both 54, 42 and 48 modules designs
const int modtyp(
::atoi((baseName.substr(8, 1)).c_str()) == 9 || ::atoi((baseName.substr(8, 1)).c_str()) == 5 ||
(::atoi((baseName.substr(8, 1)).c_str()) == 7 && ::atoi((baseName.substr(7, 1)).c_str()) == 1)
? ::atoi((baseName.substr(7, 1)).c_str()) + 1
: ::atoi((baseName.substr(7, 1)).c_str()));
int tmptyp = ::atoi(&baseName.at(7));
if (tmptyp == 17) {
tmptyp = 2;
} else if (tmptyp == 33) {
tmptyp = 3;
}
fabiocos marked this conversation as resolved.
Show resolved Hide resolved
const int modtyp(tmptyp);

// error checking

Expand Down
8 changes: 4 additions & 4 deletions Geometry/MTDCommonData/src/ETLNumberingScheme.cc
Expand Up @@ -36,10 +36,10 @@ uint32_t ETLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const {

const uint32_t modCopy(baseNumber.getCopyNumber(2));

const std::string& ringName(baseNumber.getLevelName(3)); // name of ring volume
const std::string_view& ringName(baseNumber.getLevelName(3)); // name of ring volume
int modtyp(0);
std::string baseName = ringName.substr(ringName.find(':') + 1);
int ringCopy(::atoi(baseName.c_str() + 4));
std::string_view baseName = ringName.substr(ringName.find(':') + 1);
int ringCopy(::atoi(baseName.data() + 4));

uint32_t discN, sectorS, sectorN;
if (!preTDR) {
Expand All @@ -55,7 +55,7 @@ uint32_t ETLNumberingScheme::getUnitID(const MTDBaseNumber& baseNumber) const {

// Side choice: up to scenario D38 is given by level 7 (HGCal v9)
int nSide(7);
const std::string& sideName(baseNumber.getLevelName(nSide));
const std::string_view& sideName(baseNumber.getLevelName(nSide));
// Side choice: from scenario D41 is given by level 8 (HGCal v10)
if (sideName.find("CALOECTSFront") != std::string::npos) {
nSide = 8;
Expand Down
6 changes: 3 additions & 3 deletions Geometry/MTDCommonData/src/MTDBaseNumber.cc
Expand Up @@ -18,7 +18,7 @@ void MTDBaseNumber::setSize(const int& size) {
}
}

void MTDBaseNumber::addLevel(const std::string& name, const int& copyNumber) {
void MTDBaseNumber::addLevel(const std::string_view& name, const int& copyNumber) {
if (_theLevels == MAXLEVEL - 1) {
throw cms::Exception("WrongMTDGeom") << "MTDBaseNumber required to add more levels than maximum allowed";
}
Expand All @@ -31,7 +31,7 @@ int MTDBaseNumber::getLevels() const { return _theLevels; }

int MTDBaseNumber::getCopyNumber(int level) const { return _sortedCopyNumber[level]; }

int MTDBaseNumber::getCopyNumber(const std::string& levelName) const {
int MTDBaseNumber::getCopyNumber(const std::string_view& levelName) const {
for (int iLevel = 0; iLevel < _theLevels; iLevel++) {
if (_sortedName[iLevel] == levelName) {
return _sortedCopyNumber[iLevel];
Expand All @@ -40,7 +40,7 @@ int MTDBaseNumber::getCopyNumber(const std::string& levelName) const {
return 0;
}

std::string const& MTDBaseNumber::getLevelName(int level) const { return _sortedName[level]; }
std::string_view const& MTDBaseNumber::getLevelName(int level) const { return _sortedName[level]; }

int MTDBaseNumber::getCapacity() { return _sortedName.capacity(); }

Expand Down
10 changes: 5 additions & 5 deletions Geometry/MTDCommonData/test/DD4hep_TestMTDIdealGeometry.cc
Expand Up @@ -310,12 +310,12 @@ void DD4hep_TestMTDIdealGeometry::theBaseNumber(cms::DDFilteredView& fv) {
thisN_.setSize(fv.navPos().size());

for (uint ii = 0; ii < fv.navPos().size(); ii++) {
std::string name((fv.geoHistory()[ii])->GetName());
name.assign(name.erase(name.rfind('_')));
int copyN(fv.copyNos()[ii]);
thisN_.addLevel(name, copyN);
std::string_view name((fv.geoHistory()[ii])->GetName());
size_t ipos = name.rfind('_');
thisN_.addLevel((static_cast<std::string_view>((fv.geoHistory()[ii])->GetName())).substr(0, ipos),
fabiocos marked this conversation as resolved.
Show resolved Hide resolved
fv.copyNos()[ii]);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("DD4hep_TestMTDIdealGeometry") << name << " " << copyN;
edm::LogVerbatim("DD4hep_TestMTDIdealGeometry") << name.substr(0, ipos) << " " << fv.copyNos()[ii];
#endif
}
}
Expand Down
6 changes: 2 additions & 4 deletions Geometry/MTDCommonData/test/TestMTDIdealGeometry.cc
Expand Up @@ -275,11 +275,9 @@ void TestMTDIdealGeometry::theBaseNumber(const DDGeoHistory& gh) {
thisN_.setSize(gh.size());

for (uint i = gh.size(); i-- > 0;) {
std::string name(gh[i].logicalPart().name().name());
int copyN(gh[i].copyno());
thisN_.addLevel(name, copyN);
thisN_.addLevel(gh[i].logicalPart().name().name(), gh[i].copyno());
#ifdef EDM_ML_DEBUG
edm::LogInfo("TestMTDIdealGeometry") << name << " " << copyN;
edm::LogInfo("TestMTDIdealGeometry") << gh[i].logicalPart().name().name() << " " << gh[i].copyno();
#endif
}
}
Expand Down
10 changes: 5 additions & 5 deletions Geometry/MTDGeometryBuilder/test/DD4hep_TestBTLPixelTopology.cc
Expand Up @@ -318,12 +318,12 @@ void DD4hep_TestBTLPixelTopology::theBaseNumber(cms::DDFilteredView& fv) {
thisN_.setSize(fv.navPos().size());

for (uint ii = 0; ii < fv.navPos().size(); ii++) {
std::string name((fv.geoHistory()[ii])->GetName());
name.assign(name.erase(name.rfind('_')));
int copyN(fv.copyNos()[ii]);
thisN_.addLevel(name, copyN);
std::string_view name((fv.geoHistory()[ii])->GetName());
size_t ipos = name.rfind('_');
thisN_.addLevel((static_cast<std::string_view>((fv.geoHistory()[ii])->GetName())).substr(0, ipos),
fv.copyNos()[ii]);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("DD4hep_TestBTLPixelTopology") << name << " " << copyN;
edm::LogVerbatim("DD4hep_TestBTLPixelTopology") << name.substr(0, ipos) << " " << fv.copyNos()[ii];
#endif
}
}
Expand Down
16 changes: 7 additions & 9 deletions Geometry/MTDNumberingBuilder/plugins/CmsMTDConstruction.cc
Expand Up @@ -122,11 +122,9 @@ void CmsMTDConstruction<DDFilteredView>::buildETLModule(DDFilteredView& fv, Geom
baseNumber_.setSize(gh.size());

for (uint i = gh.size(); i-- > 0;) {
std::string name(gh[i].logicalPart().name().name());
int copyN(gh[i].copyno());
baseNumber_.addLevel(name, copyN);
baseNumber_.addLevel(gh[i].logicalPart().name().name(), gh[i].copyno());
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("CmsMTDConstruction") << name << " " << copyN;
edm::LogVerbatim("CmsMTDConstruction") << gh[i].logicalPart().name().name() << " " << gh[i].copyno();
#endif
}

Expand Down Expand Up @@ -160,12 +158,12 @@ void CmsMTDConstruction<cms::DDFilteredView>::buildETLModule(cms::DDFilteredView
baseNumber_.setSize(fv.copyNos().size());

for (uint i = 0; i < fv.copyNos().size(); i++) {
std::string name((fv.geoHistory()[i])->GetName());
name.assign(name.erase(name.rfind('_')));
int copyN(fv.copyNos()[i]);
baseNumber_.addLevel(name, copyN);
std::string_view name((fv.geoHistory()[i])->GetName());
size_t ipos = name.rfind('_');
baseNumber_.addLevel((static_cast<std::string_view>((fv.geoHistory()[i])->GetName())).substr(0, ipos),
fv.copyNos()[i]);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("CmsMTDConstruction") << name << " " << copyN;
edm::LogVerbatim("CmsMTDConstruction") << name.substr(0, ipos) << " " << fv.copyNos()[i];
#endif
}

Expand Down