CMS 3D CMS Logo

DDSpecparRegistry.cc
Go to the documentation of this file.
3 #include "DD4hep/Detector.h"
4 #include <algorithm>
5 
6 using namespace std;
7 using namespace cms;
8 using namespace edm;
9 
10 string_view DDSpecPar::strValue(const string& key) const {
11  auto const& item = spars.find(key);
12  if (item == end(spars))
13  return string();
14  return *begin(item->second);
15 }
16 
17 bool DDSpecPar::hasValue(const string& key) const {
18  if (numpars.find(key) != end(numpars))
19  return true;
20  else
21  return false;
22 }
23 
24 template <>
25 std::vector<double> DDSpecPar::value<std::vector<double>>(const string& key) const {
26  std::vector<double> result;
27 
28  auto const& nitem = numpars.find(key);
29  if (nitem != end(numpars)) {
30  return std::vector<double>(begin(nitem->second), end(nitem->second));
31  }
32 
33  auto const& sitem = spars.find(key);
34  if (sitem != end(spars)) {
35  std::transform(begin(sitem->second), end(sitem->second), std::back_inserter(result), [](auto& i) -> double {
36  return dd4hep::_toDouble(i);
37  });
38  }
39 
40  return result;
41 }
42 
43 template <>
44 std::vector<std::string> DDSpecPar::value<std::vector<std::string>>(const string& key) const {
45  std::vector<std::string> result;
46 
47  auto const& nitem = numpars.find(key);
48  if (nitem != end(numpars)) {
49  std::transform(begin(nitem->second), end(nitem->second), std::back_inserter(result), [](auto& i) -> std::string {
50  return std::to_string(i);
51  });
52 
53  return result;
54  }
55 
56  auto const& sitem = spars.find(key);
57  if (sitem != end(spars)) {
58  return std::vector<std::string>(begin(sitem->second), end(sitem->second));
59  }
60 
61  return result;
62 }
63 
64 double DDSpecPar::dblValue(const string& key) const {
65  auto const& item = numpars.find(key);
66  if (item == end(numpars))
67  return 0;
68  return *begin(item->second);
69 }
70 
71 void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute, string_view value) const {
72  bool found(false);
73  for_each(begin(specpars), end(specpars), [&refs, &attribute, &value, &found](const auto& k) {
74  found = false;
75  for_each(begin(k.second.spars), end(k.second.spars), [&](const auto& l) {
76  if (l.first == attribute) {
77  for_each(begin(l.second), end(l.second), [&](const auto& m) {
78  if (m == value)
79  found = true;
80  });
81  }
82  });
83  if (found) {
84  refs.emplace_back(&k.second);
85  }
86  });
87 }
88 
89 void DDSpecParRegistry::filter(DDSpecParRefs& refs, string_view attribute) const {
90  bool found(false);
91  for_each(begin(specpars), end(specpars), [&refs, &attribute, &found](const auto& k) {
92  found = false;
93  for_each(begin(k.second.spars), end(k.second.spars), [&](const auto& l) {
94  if (l.first == attribute) {
95  found = true;
96  }
97  });
98  if (found) {
99  refs.emplace_back(&k.second);
100  }
101  });
102 }
103 
104 std::vector<std::string_view> DDSpecParRegistry::names() const {
105  std::vector<std::string_view> result;
106  for_each(begin(specpars), end(specpars), [&result](const auto& i) { result.emplace_back(i.first); });
107  return result;
108 }
109 
110 bool DDSpecParRegistry::hasSpecPar(std::string_view name) const {
111  auto const& result =
112  find_if(begin(specpars), end(specpars), [&name](const auto& i) { return (i.first.compare(name) == 0); });
113  if (result != end(specpars))
114  return true;
115  else
116  return false;
117 }
118 
119 const DDSpecPar* DDSpecParRegistry::specPar(std::string_view name) const {
120  auto const& result =
121  find_if(begin(specpars), end(specpars), [&name](const auto& i) { return (i.first.compare(name) == 0); });
122  if (result != end(specpars)) {
123  return &result->second;
124  } else {
125  return nullptr;
126  }
127 }
const std::string names[nVars_]
#define end
Definition: vmac.h:39
Definition: value.py:1
Namespace of DDCMS conversion namespace.
std::vector< const DDSpecPar * > DDSpecParRefs
#define begin
Definition: vmac.h:32
HLT enums.
unsigned transform(const HcalDetId &id, unsigned transformCode)