Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "DetectorDescription/DDCMS/interface/DDCompactView.h"
#include "FWCore/Utilities/interface/Exception.h"
#include <DD4hep/Filter.h>

#include <cmath>
#include <vector>

template <>
std::vector<int> cms::DDCompactView::getVector<int>(const std::string& key) const {
  std::vector<int> result;
  const auto& vmap = this->detector()->vectors();
  for (auto const& it : vmap) {
    if (dd4hep::dd::noNamespace(it.first) == key) {
      std::transform(
          it.second.begin(), it.second.end(), std::back_inserter(result), [](int n) -> int { return (int)n; });
      return result;
    }
  }
  return result;
}

template <>
std::vector<double> cms::DDCompactView::getVector<double>(const std::string& key) const {
  const auto& vmap = this->detector()->vectors();
  for (auto const& it : vmap) {
    if (dd4hep::dd::noNamespace(it.first) == key) {
      return it.second;
    }
  }
  return std::vector<double>();
}

template <>
std::vector<double> const& cms::DDCompactView::get<std::vector<double>>(const std::string& key) const {
  const auto& vmap = this->detector()->vectors();
  for (auto const& it : vmap) {
    if (dd4hep::dd::noNamespace(it.first) == key) {
      return it.second;
    }
  }
  throw cms::Exception("DDError") << "no vector<double> with name " << key;
}

template <>
std::vector<double> const& cms::DDCompactView::get<std::vector<double>>(const std::string& name,
                                                                        const std::string& key) const {
  const auto& spec = specpars().specPar(name);
  if (spec != nullptr) {
    auto const& nitem = spec->numpars.find(key);
    if (nitem != end(spec->numpars)) {
      return nitem->second;
    }
  }
  throw cms::Exception("DDError") << "no SpecPar with name " << name << " and vector<double> key " << key;
}