CMS 3D CMS Logo

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

List of all members.

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

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.

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

Definition at line 16 of file AlgoCheck.h.

{ }

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

{
  bool nok = false; // not ok - flag, negative logic inside the function!
  
  // first expression parameters
  constraintsE_type::iterator e_it = constraintsE_.begin();
  for (; e_it != constraintsE_.end(); ++e_it) {
    
    parE_type::iterator pit = pe.find(e_it->first);
    if (e_it->second.use_) { // required parameter
      
      if (pit != pe.end()) {
        nok |= checkBounds(pit,e_it,err);
      }
      else { // missing required parameter
        err += std::string("\tmissing required parameter: ") + e_it->first + std::string("\n");
        nok |= true;
      }
        
    }
    
    else { // optional parameter
           // an optional parameter MUST be here if a default-value is specified !
      
      DCOUT('e', "AlgoCheck::check(): optional param=" << e_it->first);
      
      
      if (pit != pe.end()) { // optional parameter present 
                             // (can be a possible default-val or a user-supplied-val)
        nok |= checkBounds(pit,e_it,err);
      } 
      else { // optional parameter absent although an default value is specified. 
             // provide the default value at least minOccurs-times
        if (e_it->second.default_) {
          for(int j=0; j<e_it->second.minOccurs_; ++j)
            pe[e_it->first].push_back(e_it->second.defaultVal_);
        }
      }
    }
  
  }
  
  // then std::string parameters
  // FIXME: implement AlgoCheck::check std::string-valued parameter checks! 

  constraintsS_type::iterator s_it = constraintsS_.begin();
  for (; s_it != constraintsS_.end(); ++s_it) {
    
    parS_type::iterator sit = ps.find(s_it->first);
    if (s_it->second.use_) { // required parameter
      
      if (sit != ps.end()) {
        nok |= checkStrings(sit, s_it, err);
      }
      else { // missing required parameter
        err += std::string("\tmissing required parameter: ") + s_it->first + std::string("\n");
        nok |= true;
      }
    }
    else { // optional parameter absent although a default value is specified. 
           // provide the default value at least minOccurs-times

      if (s_it->second.default_) {
        for (int j = 0; j < s_it->second.minOccurs_; ++j)
          ps[s_it->first].push_back(s_it->second.defaultVal_);
      }
    }
  }
  return !nok;
}
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().

{
   bool nok = false;
   
   DCOUT('e', "AlgoCheck::checkBounds(), par-name=" << pit->first );
   DCOUT('e', "                          minOccurs  = " << cit->second.minOccurs_ );
   DCOUT('e', "                          maxOccurs  = " << cit->second.maxOccurs_ );
   DCOUT('e', "                          par-occurs = " << pit->second.size() );
   // occurences
   if (cit->second.minOccurs_ > int(pit->second.size()) ) {
     err += "\tpar. " + cit->first 
         +  " occurs=" + d2s(pit->second.size()) + std::string(" < minOccurs; minOccurs=")
         +  d2s(cit->second.minOccurs_) + std::string(" maxOccurs=") 
         +  d2s(cit->second.maxOccurs_)
         +  "\n";
     nok |= true; 
     DCOUT('e', "                          VIOLATION of minOccurs");
   }
   //if (!nok) {
     if (cit->second.maxOccurs_ < int(pit->second.size()) ) {
     err += "\tpar. " + cit->first 
         +  " occurs=" + d2s(pit->second.size()) + std::string(" > maxOccurs; minOccurs=")
         +  d2s(cit->second.minOccurs_) + std::string(" maxOccurs=") 
         +  d2s(cit->second.maxOccurs_)
         +  "\n";
       nok |= true;   
       DCOUT('e', "                          VIOLATION of maxOccurs");
     }
   //} 
   
   // min, max
  // if (!nok) { // only check bounds if occurences were right!
     int c=0; // error count
     int i=0;
     int m=int(pit->second.size());
     for (;i<m;++i) {
       if (pit->second[i] < cit->second.min_) {
         err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("]=")
             +  d2s(pit->second[i]) + std::string(" < min; min=")
             +  d2s(cit->second.min_) + std::string(" max=") +  d2s(cit->second.max_)
             +  "\n";
         ++c; // error count
       }
       if (pit->second[i] > cit->second.max_) {
         err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("]=")
             +  d2s(pit->second[i]) + std::string(" > max; min=")
             +  d2s(cit->second.min_) + std::string(" max=") +  d2s(cit->second.max_)
             +  "\n";
         ++c; // error count       
       }
     }
     if (c)
      nok |= true;
   //}
   return nok;
}
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().

{
   // occurences
   bool nok = false;
   if (cit->second.minOccurs_ > int(sit->second.size()) ) {
     err += "\tpar. " + cit->first 
         +  " occurs=" + d2s(sit->second.size()) + std::string(" < minOccurs; minOccurs=")
         +  d2s(cit->second.minOccurs_) + std::string(" maxOccurs=") 
         +  d2s(cit->second.maxOccurs_)
         +  "\n";
     nok |= true; 
     DCOUT('e', "                          VIOLATION of minOccurs");
   }
   //if (!nok) {
     if (cit->second.maxOccurs_ < int(sit->second.size()) ) {
     err += "\tpar. " + cit->first 
         +  " occurs=" + d2s(sit->second.size()) + std::string(" > maxOccurs; minOccurs=")
         +  d2s(cit->second.minOccurs_) + std::string(" maxOccurs=") 
         +  d2s(cit->second.maxOccurs_)
         +  "\n";
       nok |= true;   
       DCOUT('e', "                          VIOLATION of maxOccurs");
     }
   //} 

  int i = 0;
  int m = int(sit->second.size());  
  for (; i<m;++i){

    std::string s = sit->second[i];
    int ss = int(s.size());

    int j = 0;
    for (; j < ss; ++j) {
      if (s[j] != ' '){
        break;
      }
      if (j == ss && s[j] == ' ') {
        err += "\tpar. " + cit->first + std::string("[") + d2s(i) + std::string("] is blank");
        nok |= true;
        DCOUT('e', "                         VIOLATION of requiring non-blank std::strings");
      }
    }
  }

  return nok;

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

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

Member Data Documentation