CMS 3D CMS Logo

AlgoCheck Class Reference

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

#include <DetectorDescription/ExprAlgo/interface/AlgoCheck.h>

Inheritance diagram for AlgoCheck:

global_angular_Check global_linear_Check global_simpleAngular_Check presh_detectorsChecker

List of all members.

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_
bool check (parS_type &ps, parE_type &pe, std::string &err)
 returns true if the check was successfull (parameters conform to XML specification)
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!

Protected Attributes

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

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...


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.

00014 { }

virtual AlgoCheck::~AlgoCheck (  )  [inline, virtual]

Definition at line 16 of file AlgoCheck.h.

00016 { }


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().

00006 {
00007   bool nok = false; // not ok - flag, negative logic inside the function!
00008   
00009   // first expression parameters
00010   constraintsE_type::iterator e_it = constraintsE_.begin();
00011   for (; e_it != constraintsE_.end(); ++e_it) {
00012     
00013     parE_type::iterator pit = pe.find(e_it->first);
00014     if (e_it->second.use_) { // required parameter
00015       
00016       if (pit != pe.end()) {
00017         nok |= checkBounds(pit,e_it,err);
00018       }
00019       else { // missing required parameter
00020         err += std::string("\tmissing required parameter: ") + e_it->first + std::string("\n");
00021         nok |= true;
00022       }
00023         
00024     }
00025     
00026     else { // optional parameter
00027            // an optional parameter MUST be here if a default-value is specified !
00028       
00029       DCOUT('e', "AlgoCheck::check(): optional param=" << e_it->first);
00030       
00031       
00032       if (pit != pe.end()) { // optional parameter present 
00033                              // (can be a possible default-val or a user-supplied-val)
00034         nok |= checkBounds(pit,e_it,err);
00035       } 
00036       else { // optional parameter absent although an default value is specified. 
00037              // provide the default value at least minOccurs-times
00038         if (e_it->second.default_) {
00039           for(int j=0; j<e_it->second.minOccurs_; ++j)
00040             pe[e_it->first].push_back(e_it->second.defaultVal_);
00041         }
00042       }
00043     }
00044   
00045   }
00046   
00047   // then std::string parameters
00048   // FIXME: implement AlgoCheck::check std::string-valued parameter checks! 
00049 
00050   constraintsS_type::iterator s_it = constraintsS_.begin();
00051   for (; s_it != constraintsS_.end(); ++s_it) {
00052     
00053     parS_type::iterator sit = ps.find(s_it->first);
00054     if (s_it->second.use_) { // required parameter
00055       
00056       if (sit != ps.end()) {
00057         nok |= checkStrings(sit, s_it, err);
00058       }
00059       else { // missing required parameter
00060         err += std::string("\tmissing required parameter: ") + s_it->first + std::string("\n");
00061         nok |= true;
00062       }
00063     }
00064     else { // optional parameter absent although a default value is specified. 
00065            // provide the default value at least minOccurs-times
00066 
00067       if (s_it->second.default_) {
00068         for (int j = 0; j < s_it->second.minOccurs_; ++j)
00069           ps[s_it->first].push_back(s_it->second.defaultVal_);
00070       }
00071     }
00072   }
00073   return !nok;
00074 }

bool AlgoCheck::checkBounds ( parE_type::iterator  pit,
constraintsE_type::iterator  cit,
std::string &  err 
) [protected]

Definition at line 78 of file AlgoCheck.cc.

References c, d2s(), DCOUT, i, int, and m.

Referenced by check().

00082 {
00083    bool nok = false;
00084    
00085    DCOUT('e', "AlgoCheck::checkBounds(), par-name=" << pit->first );
00086    DCOUT('e', "                          minOccurs  = " << cit->second.minOccurs_ );
00087    DCOUT('e', "                          maxOccurs  = " << cit->second.maxOccurs_ );
00088    DCOUT('e', "                          par-occurs = " << pit->second.size() );
00089    // occurences
00090    if (cit->second.minOccurs_ > int(pit->second.size()) ) {
00091      err += "\tpar. " + cit->first 
00092          +  " occurs=" + d2s(pit->second.size()) + std::string(" < minOccurs; minOccurs=")
00093          +  d2s(cit->second.minOccurs_) + std::string(" maxOccurs=") 
00094          +  d2s(cit->second.maxOccurs_)
00095          +  "\n";
00096      nok |= true; 
00097      DCOUT('e', "                          VIOLATION of minOccurs");
00098    }
00099    //if (!nok) {
00100      if (cit->second.maxOccurs_ < int(pit->second.size()) ) {
00101      err += "\tpar. " + cit->first 
00102          +  " occurs=" + d2s(pit->second.size()) + std::string(" > maxOccurs; minOccurs=")
00103          +  d2s(cit->second.minOccurs_) + std::string(" maxOccurs=") 
00104          +  d2s(cit->second.maxOccurs_)
00105          +  "\n";
00106        nok |= true;   
00107        DCOUT('e', "                          VIOLATION of maxOccurs");
00108      }
00109    //} 
00110    
00111    // min, max
00112   // if (!nok) { // only check bounds if occurences were right!
00113      int c=0; // error count
00114      int i=0;
00115      int m=int(pit->second.size());
00116      for (;i<m;++i) {
00117        if (pit->second[i] < cit->second.min_) {
00118          err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("]=")
00119              +  d2s(pit->second[i]) + std::string(" < min; min=")
00120              +  d2s(cit->second.min_) + std::string(" max=") +  d2s(cit->second.max_)
00121              +  "\n";
00122          ++c; // error count
00123        }
00124        if (pit->second[i] > cit->second.max_) {
00125          err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("]=")
00126              +  d2s(pit->second[i]) + std::string(" > max; min=")
00127              +  d2s(cit->second.min_) + std::string(" max=") +  d2s(cit->second.max_)
00128              +  "\n";
00129          ++c; // error count       
00130        }
00131      }
00132      if (c)
00133       nok |= true;
00134    //}
00135    return nok;
00136 }

bool AlgoCheck::checkStrings ( parS_type::iterator  sit,
constraintsS_type::iterator  cit,
std::string &  err 
) [protected]

Definition at line 146 of file AlgoCheck.cc.

References d2s(), DCOUT, i, int, j, m, s, and ss.

Referenced by check().

00149 {
00150    // occurences
00151    bool nok = false;
00152    if (cit->second.minOccurs_ > int(sit->second.size()) ) {
00153      err += "\tpar. " + cit->first 
00154          +  " occurs=" + d2s(sit->second.size()) + std::string(" < minOccurs; minOccurs=")
00155          +  d2s(cit->second.minOccurs_) + std::string(" maxOccurs=") 
00156          +  d2s(cit->second.maxOccurs_)
00157          +  "\n";
00158      nok |= true; 
00159      DCOUT('e', "                          VIOLATION of minOccurs");
00160    }
00161    //if (!nok) {
00162      if (cit->second.maxOccurs_ < int(sit->second.size()) ) {
00163      err += "\tpar. " + cit->first 
00164          +  " occurs=" + d2s(sit->second.size()) + std::string(" > maxOccurs; minOccurs=")
00165          +  d2s(cit->second.minOccurs_) + std::string(" maxOccurs=") 
00166          +  d2s(cit->second.maxOccurs_)
00167          +  "\n";
00168        nok |= true;   
00169        DCOUT('e', "                          VIOLATION of maxOccurs");
00170      }
00171    //} 
00172 
00173   int i = 0;
00174   int m = int(sit->second.size());  
00175   for (; i<m;++i){
00176 
00177     std::string s = sit->second[i];
00178     int ss = int(s.size());
00179 
00180     int j = 0;
00181     for (; j < ss; ++j) {
00182       if (s[j] != ' '){
00183         break;
00184       }
00185       if (j == ss && s[j] == ' ') {
00186         err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("] is blank");
00187         nok |= true;
00188         DCOUT('e', "                         VIOLATION of requiring non-blank std::strings");
00189       }
00190     }
00191   }
00192 
00193   return nok;
00194 
00195 }

std::string AlgoCheck::d2s ( double  x  )  [static, protected]

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().

00140 {
00141   char buffer [25]; 
00142   /*int n =*/ sprintf(buffer,"%g",x);
00143   return std::string(buffer);
00144 }


Member Data Documentation

constraintsE_type AlgoCheck::constraintsE_ [protected]

format: "ParameterName" -> ConstraintE

Definition at line 73 of file AlgoCheck.h.

Referenced by check(), global_angular_Check::global_angular_Check(), global_linear_Check::global_linear_Check(), and global_simpleAngular_Check::global_simpleAngular_Check().

constraintsS_type AlgoCheck::constraintsS_ [protected]

format: "ParameterName" -> ConstraintS

Definition at line 76 of file AlgoCheck.h.

Referenced by check(), global_angular_Check::global_angular_Check(), and global_simpleAngular_Check::global_simpleAngular_Check().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:14:11 2009 for CMSSW by  doxygen 1.5.4