CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 {
10  bool check( const std::string & );
11  std::vector<double> get( const std::string & );
12  void beginWith( const std::string &, std::vector<std::string> & );
13 
14  inline bool
15  check( const std::string & str )
16  {
17  DDVector::iterator<DDVector> vit;
18  DDVector::iterator<DDVector> ved( DDVector::end());
19 
20  for(; vit != ved; ++vit )
21  {
22  if( vit->isDefined().second )
23  {
24  DDName vname( vit->name());
25  if( vname.name() == str )
26  return true;
27  }
28  }
29 
30  return false;
31  }
32 
33  inline std::vector<double>
34  get( const std::string & str )
35  {
36  DDVector::iterator<DDVector> vit;
37  DDVector::iterator<DDVector> ved( DDVector::end());
38  if( vit == ved )
39  throw cms::Exception( "DDException" ) << "DDVectorGetter: vectors are empty, cannot get array " << str;
40 
41  for (; vit != ved; ++vit )
42  {
43  if( vit->isDefined().second )
44  {
45  DDName vname( vit->name());
46  if( vname.name() == str )
47  {
48  const std::vector<double> & fvec = vit->values();
49  return fvec;
50  }
51  }
52  }
53 
54  throw cms::Exception( "DDException" ) << "DDVectorGetter: cannot get array " << str;
55  }
56 
57  inline void
58  beginWith( const std::string & str, std::vector<std::string>& vstring )
59  {
60  DDVector::iterator<DDVector> vit;
61  DDVector::iterator<DDVector> ved( DDVector::end());
62 
63  for(; vit != ved; ++vit )
64  {
65  if( vit->isDefined().second )
66  {
67  DDName vname( vit->name());
68  if( vname.name().compare( 0, str.size(), str ) == 0 )
69  vstring.push_back( vname.name());
70  }
71  }
72  }
73 };
74 
75 #endif // CORE_DDVECTOR_GETTER_H
vector< string > vstring
Definition: ExoticaDQM.cc:8
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:14
bool check(const std::string &)
void beginWith(const std::string &, std::vector< std::string > &)