File indexing completed on 2024-04-06 12:05:29
0001 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <DD4hep/Filter.h>
0004
0005 #include <cmath>
0006 #include <vector>
0007
0008 template <>
0009 std::vector<int> cms::DDCompactView::getVector<int>(const std::string& key) const {
0010 std::vector<int> result;
0011 const auto& vmap = this->detector()->vectors();
0012 for (auto const& it : vmap) {
0013 if (dd4hep::dd::noNamespace(it.first) == key) {
0014 std::transform(
0015 it.second.begin(), it.second.end(), std::back_inserter(result), [](int n) -> int { return (int)n; });
0016 return result;
0017 }
0018 }
0019 return result;
0020 }
0021
0022 template <>
0023 std::vector<double> cms::DDCompactView::getVector<double>(const std::string& key) const {
0024 const auto& vmap = this->detector()->vectors();
0025 for (auto const& it : vmap) {
0026 if (dd4hep::dd::noNamespace(it.first) == key) {
0027 return it.second;
0028 }
0029 }
0030 return std::vector<double>();
0031 }
0032
0033 template <>
0034 std::vector<double> const& cms::DDCompactView::get<std::vector<double>>(const std::string& key) const {
0035 const auto& vmap = this->detector()->vectors();
0036 for (auto const& it : vmap) {
0037 if (dd4hep::dd::noNamespace(it.first) == key) {
0038 return it.second;
0039 }
0040 }
0041 throw cms::Exception("DDError") << "no vector<double> with name " << key;
0042 }
0043
0044 template <>
0045 std::vector<double> const& cms::DDCompactView::get<std::vector<double>>(const std::string& name,
0046 const std::string& key) const {
0047 const auto& spec = specpars().specPar(name);
0048 if (spec != nullptr) {
0049 auto const& nitem = spec->numpars.find(key);
0050 if (nitem != end(spec->numpars)) {
0051 return nitem->second;
0052 }
0053 }
0054 throw cms::Exception("DDError") << "no SpecPar with name " << name << " and vector<double> key " << key;
0055 }