CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes
AlgoCheck Class Reference

base class for generated checking code for algorithm parameters. More...

#include <AlgoCheck.h>

Inheritance diagram for AlgoCheck:
global_angular_Check global_linear_Check global_simpleAngular_Check

Classes

struct  ConstraintE
 constraints as defined for algorithm-parameters in the XML schema Algorithm.xsd, expressions More...
 
struct  ConstraintS
 constraints as defined for algorithm-parameters in the XML schema Algorithm.xsd, strings More...
 

Public Types

typedef std::map< std::string,
ConstraintE
constraintsE_type
 
typedef std::map< std::string,
ConstraintS
constraintsS_type
 

Public Member Functions

 AlgoCheck ()
 the ctor of the derived class has to fill the members constraintsE_,S_ More...
 
bool check (parS_type &ps, parE_type &pe, std::string &err)
 returns true if the check was successfull (parameters conform to XML specification) More...
 
virtual ~AlgoCheck ()
 

Protected Member Functions

bool checkBounds (parE_type::iterator pit, constraintsE_type::iterator cit, std::string &err)
 
bool checkStrings (parS_type::iterator sit, constraintsS_type::iterator cit, std::string &err)
 

Static Protected Member Functions

static std::string d2s (double x)
 ahh, converts a double into a std::string ... yet another one of this kind! More...
 

Protected Attributes

constraintsE_type constraintsE_
 format: "ParameterName" -> ConstraintE More...
 
constraintsS_type constraintsS_
 format: "ParameterName" -> ConstraintS More...
 

Detailed Description

base class for generated checking code for algorithm parameters.

Definition at line 10 of file AlgoCheck.h.

Member Typedef Documentation

typedef std::map<std::string,ConstraintE> AlgoCheck::constraintsE_type

Definition at line 56 of file AlgoCheck.h.

typedef std::map<std::string,ConstraintS> AlgoCheck::constraintsS_type

Definition at line 57 of file AlgoCheck.h.

Constructor & Destructor Documentation

AlgoCheck::AlgoCheck ( )
inline

the ctor of the derived class has to fill the members constraintsE_,S_

Definition at line 14 of file AlgoCheck.h.

14 { }
virtual AlgoCheck::~AlgoCheck ( )
inlinevirtual

Definition at line 16 of file AlgoCheck.h.

16 { }

Member Function Documentation

bool AlgoCheck::check ( parS_type ps,
parE_type pe,
std::string &  err 
)

returns true if the check was successfull (parameters conform to XML specification)

Definition at line 5 of file AlgoCheck.cc.

References checkBounds(), checkStrings(), constraintsE_, constraintsS_, DCOUT, and j.

Referenced by AlgoPos::select().

6 {
7  bool nok = false; // not ok - flag, negative logic inside the function!
8 
9  // first expression parameters
10  constraintsE_type::iterator e_it = constraintsE_.begin();
11  for (; e_it != constraintsE_.end(); ++e_it) {
12 
13  parE_type::iterator pit = pe.find(e_it->first);
14  if (e_it->second.use_) { // required parameter
15 
16  if (pit != pe.end()) {
17  nok |= checkBounds(pit,e_it,err);
18  }
19  else { // missing required parameter
20  err += std::string("\tmissing required parameter: ") + e_it->first + std::string("\n");
21  nok |= true;
22  }
23 
24  }
25 
26  else { // optional parameter
27  // an optional parameter MUST be here if a default-value is specified !
28 
29  DCOUT('e', "AlgoCheck::check(): optional param=" << e_it->first);
30 
31 
32  if (pit != pe.end()) { // optional parameter present
33  // (can be a possible default-val or a user-supplied-val)
34  nok |= checkBounds(pit,e_it,err);
35  }
36  else { // optional parameter absent although an default value is specified.
37  // provide the default value at least minOccurs-times
38  if (e_it->second.default_) {
39  for(int j=0; j<e_it->second.minOccurs_; ++j)
40  pe[e_it->first].push_back(e_it->second.defaultVal_);
41  }
42  }
43  }
44 
45  }
46 
47  // then std::string parameters
48  // FIXME: implement AlgoCheck::check std::string-valued parameter checks!
49 
50  constraintsS_type::iterator s_it = constraintsS_.begin();
51  for (; s_it != constraintsS_.end(); ++s_it) {
52 
53  parS_type::iterator sit = ps.find(s_it->first);
54  if (s_it->second.use_) { // required parameter
55 
56  if (sit != ps.end()) {
57  nok |= checkStrings(sit, s_it, err);
58  }
59  else { // missing required parameter
60  err += std::string("\tmissing required parameter: ") + s_it->first + std::string("\n");
61  nok |= true;
62  }
63  }
64  else { // optional parameter absent although a default value is specified.
65  // provide the default value at least minOccurs-times
66 
67  if (s_it->second.default_) {
68  for (int j = 0; j < s_it->second.minOccurs_; ++j)
69  ps[s_it->first].push_back(s_it->second.defaultVal_);
70  }
71  }
72  }
73  return !nok;
74 }
bool checkBounds(parE_type::iterator pit, constraintsE_type::iterator cit, std::string &err)
Definition: AlgoCheck.cc:78
int j
Definition: DBlmapReader.cc:9
constraintsS_type constraintsS_
format: &quot;ParameterName&quot; -&gt; ConstraintS
Definition: AlgoCheck.h:76
constraintsE_type constraintsE_
format: &quot;ParameterName&quot; -&gt; ConstraintE
Definition: AlgoCheck.h:73
bool checkStrings(parS_type::iterator sit, constraintsS_type::iterator cit, std::string &err)
Definition: AlgoCheck.cc:149
#define DCOUT(M_v_Y, M_v_S)
Definition: DDdebug.h:53
bool AlgoCheck::checkBounds ( parE_type::iterator  pit,
constraintsE_type::iterator  cit,
std::string &  err 
)
protected

Definition at line 78 of file AlgoCheck.cc.

References trackerHits::c, d2s(), DCOUT, i, and m.

Referenced by check().

82 {
83  bool nok = false;
84 
85  DCOUT('e', "AlgoCheck::checkBounds(), par-name=" << pit->first );
86  DCOUT('e', " minOccurs = " << cit->second.minOccurs_ );
87  DCOUT('e', " maxOccurs = " << cit->second.maxOccurs_ );
88  DCOUT('e', " par-occurs = " << pit->second.size() );
89  // occurences
90  if (cit->second.minOccurs_ > int(pit->second.size()) ) {
91  err += "\tpar. " + cit->first
92  + " occurs=" + d2s(pit->second.size()) + std::string(" < minOccurs; minOccurs=")
93  + d2s(cit->second.minOccurs_) + std::string(" maxOccurs=")
94  + d2s(cit->second.maxOccurs_)
95  + "\n";
96  nok |= true;
97  DCOUT('e', " VIOLATION of minOccurs");
98  }
99  //if (!nok) {
100  if (cit->second.maxOccurs_ < int(pit->second.size()) ) {
101  err += "\tpar. " + cit->first
102  + " occurs=" + d2s(pit->second.size()) + std::string(" > maxOccurs; minOccurs=")
103  + d2s(cit->second.minOccurs_) + std::string(" maxOccurs=")
104  + d2s(cit->second.maxOccurs_)
105  + "\n";
106  nok |= true;
107  DCOUT('e', " VIOLATION of maxOccurs");
108  }
109  //}
110 
111  // min, max
112  // if (!nok) { // only check bounds if occurences were right!
113  int c=0; // error count
114  int i=0;
115  int m=int(pit->second.size());
116  for (;i<m;++i) {
117  if (pit->second[i] < cit->second.min_) {
118  err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("]=")
119  + d2s(pit->second[i]) + std::string(" < min; min=")
120  + d2s(cit->second.min_) + std::string(" max=") + d2s(cit->second.max_)
121  + "\n";
122  ++c; // error count
123  }
124  if (pit->second[i] > cit->second.max_) {
125  err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("]=")
126  + d2s(pit->second[i]) + std::string(" > max; min=")
127  + d2s(cit->second.min_) + std::string(" max=") + d2s(cit->second.max_)
128  + "\n";
129  ++c; // error count
130  }
131  }
132  if (c)
133  nok |= true;
134  //}
135  return nok;
136 }
int i
Definition: DBlmapReader.cc:9
static std::string d2s(double x)
ahh, converts a double into a std::string ... yet another one of this kind!
Definition: AlgoCheck.cc:139
#define DCOUT(M_v_Y, M_v_S)
Definition: DDdebug.h:53
bool AlgoCheck::checkStrings ( parS_type::iterator  sit,
constraintsS_type::iterator  cit,
std::string &  err 
)
protected

Definition at line 149 of file AlgoCheck.cc.

References d2s(), DCOUT, i, j, m, and asciidump::s.

Referenced by check().

152 {
153  // occurences
154  bool nok = false;
155  if (cit->second.minOccurs_ > int(sit->second.size()) ) {
156  err += "\tpar. " + cit->first
157  + " occurs=" + d2s(sit->second.size()) + std::string(" < minOccurs; minOccurs=")
158  + d2s(cit->second.minOccurs_) + std::string(" maxOccurs=")
159  + d2s(cit->second.maxOccurs_)
160  + "\n";
161  nok |= true;
162  DCOUT('e', " VIOLATION of minOccurs");
163  }
164  //if (!nok) {
165  if (cit->second.maxOccurs_ < int(sit->second.size()) ) {
166  err += "\tpar. " + cit->first
167  + " occurs=" + d2s(sit->second.size()) + std::string(" > maxOccurs; minOccurs=")
168  + d2s(cit->second.minOccurs_) + std::string(" maxOccurs=")
169  + d2s(cit->second.maxOccurs_)
170  + "\n";
171  nok |= true;
172  DCOUT('e', " VIOLATION of maxOccurs");
173  }
174  //}
175 
176  int i = 0;
177  int m = int(sit->second.size());
178  for (; i<m;++i){
179 
180  std::string s = sit->second[i];
181  int ss = int(s.size());
182 
183  int j = 0;
184  for (; j < ss; ++j) {
185  if (s[j] != ' '){
186  break;
187  }
188  if (j == ss && s[j] == ' ') {
189  err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("] is blank");
190  nok |= true;
191  DCOUT('e', " VIOLATION of requiring non-blank std::strings");
192  }
193  }
194  }
195 
196  return nok;
197 
198 }
int i
Definition: DBlmapReader.cc:9
static std::string d2s(double x)
ahh, converts a double into a std::string ... yet another one of this kind!
Definition: AlgoCheck.cc:139
int j
Definition: DBlmapReader.cc:9
string s
Definition: asciidump.py:422
#define DCOUT(M_v_Y, M_v_S)
Definition: DDdebug.h:53
std::string AlgoCheck::d2s ( double  x)
staticprotected

ahh, converts a double into a std::string ... yet another one of this kind!

Definition at line 139 of file AlgoCheck.cc.

Referenced by checkBounds(), and checkStrings().

140 {
141  char buffer [25];
142  int len = snprintf( buffer, 25, "%g", x );
143  if( len >= 25 )
144  edm::LogError( "DoubleToString" ) << "Length truncated (from " << len << ")";
145  return std::string( buffer );
146 }

Member Data Documentation

constraintsE_type AlgoCheck::constraintsE_
protected
constraintsS_type AlgoCheck::constraintsS_
protected