Skip to content

Commit

Permalink
Merge pull request #28384 from ianna/dd4hep-replace-char-pointer-with…
Browse files Browse the repository at this point in the history
…-string-reference

DD4hep: Replace "const char*" with "const std::string&"
  • Loading branch information
cmsbuild committed Nov 13, 2019
2 parents e20d32e + f16c857 commit be878f4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
3 changes: 0 additions & 3 deletions DetectorDescription/DDCMS/data/cms-geometry-2021.xml
Expand Up @@ -14,9 +14,6 @@
<debug_visattr/-->
</debug>

<!--DisabledAlgo name="track:DDCutTubsFromPoints"/>
<DisabledAlgo name="track:DDTOBRadCableAlgo"/-->

<open_geometry/>
<close_geometry/>

Expand Down
4 changes: 2 additions & 2 deletions DetectorDescription/DDCMS/interface/DDFilteredView.h
Expand Up @@ -147,11 +147,11 @@ namespace cms {

//! extract attribute value
template <typename T>
T get(const char*) const;
T get(const std::string&) const;

//! extract attribute value in SpecPar
template <typename T>
T get(const char*, const char*) const;
T get(const std::string&, const std::string&) const;

std::string_view getString(const std::string&) const;

Expand Down
8 changes: 4 additions & 4 deletions DetectorDescription/DDCMS/interface/DDSpecParRegistry.h
Expand Up @@ -12,12 +12,12 @@ namespace cms {
using DDVectorsMap = tbb::concurrent_unordered_map<std::string, tbb::concurrent_vector<double>>;

struct DDSpecPar {
std::string_view strValue(const char*) const;
bool hasValue(const char* key) const;
double dblValue(const char*) const;
std::string_view strValue(const std::string&) const;
bool hasValue(const std::string& key) const;
double dblValue(const std::string&) const;

template <typename T>
T value(const char*) const;
T value(const std::string&) const;

DDPaths paths;
DDPartSelectionMap spars;
Expand Down
10 changes: 5 additions & 5 deletions DetectorDescription/DDCMS/src/DDFilteredView.cc
Expand Up @@ -304,7 +304,7 @@ LegacySolidShape DDFilteredView::legacyShape(const cms::DDSolidShape shape) cons
}

template <>
std::string_view DDFilteredView::get<string_view>(const char* key) const {
std::string_view DDFilteredView::get<string_view>(const string& key) const {
std::string_view result;
DDSpecParRefs refs;
registry_->filter(refs, key);
Expand Down Expand Up @@ -333,7 +333,7 @@ std::string_view DDFilteredView::get<string_view>(const char* key) const {
}

template <>
double DDFilteredView::get<double>(const char* key) const {
double DDFilteredView::get<double>(const string& key) const {
double result(0.0);
std::string_view tmpStrV = get<std::string_view>(key);
if (!tmpStrV.empty())
Expand All @@ -342,15 +342,15 @@ double DDFilteredView::get<double>(const char* key) const {
}

template <>
std::vector<double> DDFilteredView::get<std::vector<double>>(const char* name, const char* key) const {
std::vector<double> DDFilteredView::get<std::vector<double>>(const string& name, const string& key) const {
if (registry_->hasSpecPar(name))
return registry_->specPar(name)->value<std::vector<double>>(key);
else
return std::vector<double>();
}

template <>
std::vector<std::string> DDFilteredView::get<std::vector<std::string>>(const char* name, const char* key) const {
std::vector<std::string> DDFilteredView::get<std::vector<std::string>>(const string& name, const string& key) const {
if (registry_->hasSpecPar(name))
return registry_->specPar(name)->value<std::vector<std::string>>(key);
else
Expand All @@ -360,7 +360,7 @@ std::vector<std::string> DDFilteredView::get<std::vector<std::string>>(const cha
std::string_view DDFilteredView::getString(const std::string& key) const {
assert(currentFilter_);
assert(currentFilter_->spec);
return currentFilter_->spec->strValue(key.c_str());
return currentFilter_->spec->strValue(key);
}

DDFilteredView::nav_type DDFilteredView::navPos() const {
Expand Down
10 changes: 5 additions & 5 deletions DetectorDescription/DDCMS/src/DDSpecparRegistry.cc
Expand Up @@ -7,22 +7,22 @@ using namespace std;
using namespace cms;
using namespace edm;

string_view DDSpecPar::strValue(const char* key) const {
string_view DDSpecPar::strValue(const string& key) const {
auto const& item = spars.find(key);
if (item == end(spars))
return string();
return *begin(item->second);
}

bool DDSpecPar::hasValue(const char* key) const {
bool DDSpecPar::hasValue(const string& key) const {
if (numpars.find(key) != end(numpars))
return true;
else
return false;
}

template <>
std::vector<double> DDSpecPar::value<std::vector<double>>(const char* key) const {
std::vector<double> DDSpecPar::value<std::vector<double>>(const string& key) const {
std::vector<double> result;

auto const& nitem = numpars.find(key);
Expand All @@ -41,7 +41,7 @@ std::vector<double> DDSpecPar::value<std::vector<double>>(const char* key) const
}

template <>
std::vector<std::string> DDSpecPar::value<std::vector<std::string>>(const char* key) const {
std::vector<std::string> DDSpecPar::value<std::vector<std::string>>(const string& key) const {
std::vector<std::string> result;

auto const& nitem = numpars.find(key);
Expand All @@ -61,7 +61,7 @@ std::vector<std::string> DDSpecPar::value<std::vector<std::string>>(const char*
return result;
}

double DDSpecPar::dblValue(const char* key) const {
double DDSpecPar::dblValue(const string& key) const {
auto const& item = numpars.find(key);
if (item == end(numpars))
return 0;
Expand Down

0 comments on commit be878f4

Please sign in to comment.