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_view();
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 bool DDSpecPar::hasPath(const string& path) const {
26  if (result != end(paths))
27  return true;
28  else
29  return false;
30 }
31 
32 template <>
33 std::vector<double> DDSpecPar::value<std::vector<double>>(const string& key) const {
34  std::vector<double> result;
35 
36  auto const& nitem = numpars.find(key);
37  if (nitem != end(numpars)) {
38  return std::vector<double>(begin(nitem->second), end(nitem->second));
39  }
40 
41  auto const& sitem = spars.find(key);
42  if (sitem != end(spars)) {
43  std::transform(begin(sitem->second), end(sitem->second), std::back_inserter(result), [](auto& i) -> double {
44  return dd4hep::_toDouble(i);
45  });
46  }
47 
48  return result;
49 }
50 
51 template <>
52 std::vector<int> DDSpecPar::value<std::vector<int>>(const string& key) const {
53  std::vector<int> result;
54 
55  auto const& nitem = numpars.find(key);
56  if (nitem != end(numpars)) {
57  return std::vector<int>(begin(nitem->second), end(nitem->second));
58  }
59 
60  auto const& sitem = spars.find(key);
61  if (sitem != end(spars)) {
62  std::transform(begin(sitem->second), end(sitem->second), std::back_inserter(result), [](auto& i) -> int {
63  return dd4hep::_toInt(i);
64  });
65  }
66 
67  return result;
68 }
69 
70 template <>
71 std::vector<std::string> DDSpecPar::value<std::vector<std::string>>(const string& key) const {
72  std::vector<std::string> result;
73 
74  auto const& nitem = numpars.find(key);
75  if (nitem != end(numpars)) {
76  std::transform(begin(nitem->second), end(nitem->second), std::back_inserter(result), [](auto& i) -> std::string {
77  return std::to_string(i);
78  });
79 
80  return result;
81  }
82 
83  auto const& sitem = spars.find(key);
84  if (sitem != end(spars)) {
85  return std::vector<std::string>(begin(sitem->second), end(sitem->second));
86  }
87 
88  return result;
89 }
90 
91 double DDSpecPar::dblValue(const string& key) const {
92  auto const& item = numpars.find(key);
93  if (item == end(numpars))
94  return 0;
95  return *begin(item->second);
96 }
97 
98 void DDSpecParRegistry::filter(DDSpecParRefs& refs, const std::string& attribute, const std::string& value) const {
99  bool found(false);
100  for_each(begin(specpars), end(specpars), [&refs, &attribute, &value, &found](auto& k) {
101  found = false;
102  for_each(begin(k.second.spars), end(k.second.spars), [&](const auto& l) {
103  if (l.first == attribute) {
104  if (value.empty()) {
105  found = true;
106  } else {
107  for_each(begin(l.second), end(l.second), [&](const auto& m) {
108  if (m == value)
109  found = true;
110  });
111  }
112  }
113  });
114  if (found) {
115  k.second.name = k.first;
116  refs.emplace_back(&k.second);
117  }
118  });
119 }
120 
121 std::vector<std::string_view> DDSpecParRegistry::names(const std::string& path) const {
122  std::vector<std::string_view> result;
123  for_each(begin(specpars), end(specpars), [&](const auto& i) {
124  if (i.second.hasPath(path))
125  result.emplace_back(i.first);
126  });
127  return result;
128 }
129 
130 std::vector<std::string_view> DDSpecParRegistry::names() const {
131  std::vector<std::string_view> result;
132  for_each(begin(specpars), end(specpars), [&result](const auto& i) { result.emplace_back(i.first); });
133  return result;
134 }
135 
136 bool DDSpecParRegistry::hasSpecPar(std::string_view name) const {
137  auto const& result =
138  find_if(begin(specpars), end(specpars), [&name](const auto& i) { return (i.first.compare(name) == 0); });
139  if (result != end(specpars))
140  return true;
141  else
142  return false;
143 }
144 
145 const DDSpecPar* DDSpecParRegistry::specPar(std::string_view name) const {
146  auto const& result =
147  find_if(begin(specpars), end(specpars), [&name](const auto& i) { return (i.first.compare(name) == 0); });
148  if (result != end(specpars)) {
149  return &result->second;
150  } else {
151  return nullptr;
152  }
153 }
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
edm
HLT enums.
Definition: AlignableModifier.h:19
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
end
#define end
Definition: vmac.h:39
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:122
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
dqmdumpme.k
k
Definition: dqmdumpme.py:60
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
cms::DDSpecParRefs
std::vector< const DDSpecPar * > DDSpecParRefs
Definition: DDSpecParRegistry.h:30
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDSpecParRegistry.h
value
Definition: value.py:1
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:193
cms::DDSpecPar
Definition: DDSpecParRegistry.h:14
std
Definition: JetResolutionObject.h:76
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Skims_PA_cff.paths
paths
Definition: Skims_PA_cff.py:18
mps_fire.result
result
Definition: mps_fire.py:303
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
crabWrapper.key
key
Definition: crabWrapper.py:19
begin
#define begin
Definition: vmac.h:32
cms
Namespace of DDCMS conversion namespace.
Definition: ProducerAnalyzer.cc:21