CMS 3D CMS Logo

DDVectorGetter.h
Go to the documentation of this file.
1 #ifndef CORE_DDVECTOR_GETTER_H
2 #define CORE_DDVECTOR_GETTER_H
3 
5 #include <string>
6 #include <vector>
7 
8 namespace DDVectorGetter {
9  bool check(const std::string&);
10  std::vector<double> get(const std::string&);
11  void beginWith(const std::string&, std::vector<std::string>&);
12 
13  inline bool check(const std::string& str) {
14  DDVector::iterator<DDVector> vit;
15  DDVector::iterator<DDVector> ved(DDVector::end());
16 
17  for (; vit != ved; ++vit) {
18  if (vit->isDefined().second) {
19  DDName vname(vit->name());
20  if (vname.name() == str)
21  return true;
22  }
23  }
24 
25  return false;
26  }
27 
28  inline std::vector<double> get(const std::string& str) {
29  DDVector::iterator<DDVector> vit;
30  DDVector::iterator<DDVector> ved(DDVector::end());
31  if (vit == ved)
32  throw cms::Exception("DDException") << "DDVectorGetter: vectors are empty, cannot get array " << str;
33 
34  for (; vit != ved; ++vit) {
35  if (vit->isDefined().second) {
36  DDName vname(vit->name());
37  if (vname.name() == str) {
38  const std::vector<double>& fvec = vit->values();
39  return fvec;
40  }
41  }
42  }
43 
44  throw cms::Exception("DDException") << "DDVectorGetter: cannot get array " << str;
45  }
46 
47  inline void beginWith(const std::string& str, std::vector<std::string>& vstring) {
48  DDVector::iterator<DDVector> vit;
49  DDVector::iterator<DDVector> ved(DDVector::end());
50 
51  for (; vit != ved; ++vit) {
52  if (vit->isDefined().second) {
53  DDName vname(vit->name());
54  if (vname.name().compare(0, str.size(), str) == 0)
55  vstring.emplace_back(vname.name());
56  }
57  }
58  }
59 }; // namespace DDVectorGetter
60 
61 #endif // CORE_DDVECTOR_GETTER_H
vector< string > vstring
Definition: ExoticaDQM.cc:8
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
bool check(const std::string &)
#define str(s)
void beginWith(const std::string &, std::vector< std::string > &)