CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes | Friends

AlgoPos Class Reference

class for algorithmic positioning, represents an algorithm More...

#include <AlgoPos.h>

List of all members.

Public Member Functions

 AlgoPos (AlgoCheck *check=0)
 creates an algorithm named name
int copyno () const
 copy-number calculation
int end () const
bool go () const
 no further algorithm processing if go() returns false
int incr () const
void next ()
 update for next iteration of the algorithm, don't call it yourself!
size_t numRegistered ()
 return number of registered implementations
const parE_typeparE () const
const parS_typeparS () const
void registerAlgo (AlgoImpl *)
 registers an implementation of the algorithm
DDRotationMatrix rotation ()
 rotation calculations
void setParameters (int start, int end, int incr, const parS_type &, const parE_type &)
 sets mandatory and optional parameters
int start () const
void stream (std::ostream &os) const
 streams some information about common parameters and the name of the algorithm
DD3Vector translation ()
 translation calculations
 ~AlgoPos ()
 destructor clears registered AlgoImpl

Protected Member Functions

void checkTermination ()
 for algorithms with incr_==0 the algorithm must check whether to terminate
bool select ()
 selection of one of the registered AlgoImpl
void terminate ()
 terminates current algorithmic processing

Protected Attributes

AlgoCheckcheckAlgo_
 checking object which checks the user-supplied parameters whether they fulfill their spec.
int count_
 invocation count
int curr_
 current position in the range of the algorithm
int end_
std::string err_
 std::string to hold potential error messages found inside checkParameters()
int incr_
parE_type ParE_
 double valued parameters passed to the algorithm
parS_type ParS_
 std::string valued parameters passed to the algorithm
std::vector< AlgoImpl * > regAlgos_
 registry of algorithm implementation objects
AlgoImplselAlgo_
 selected algorithm implementation
int start_
 range of the algorithm
bool terminate_
 flag to signal whether the algorithm has finished (true)

Friends

class AlgoImpl

Detailed Description

class for algorithmic positioning, represents an algorithm

Implementations of the algorithm (AlgoImpl objects) have to register with AlgoPos. At least one implementation must register, so that AlgoPos is a valid representation of an algorithm. In case of multiple registration of AlgoImpl-implementations, it must be assured by the implementations that given a set of user-supplied parameters only one or none of these implementations will execute the algorithm (see AlgoImpl::checkParamters()).

Definition at line 27 of file AlgoPos.h.


Constructor & Destructor Documentation

AlgoPos::AlgoPos ( AlgoCheck check = 0)

creates an algorithm named name

Definition at line 9 of file AlgoPos.cc.

 : start_(0), end_(0), incr_(0), curr_(0), count_(0),
   terminate_(false), selAlgo_(0), checkAlgo_(check)
{ }
AlgoPos::~AlgoPos ( )

destructor clears registered AlgoImpl

Definition at line 15 of file AlgoPos.cc.

References checkAlgo_, and regAlgos_.

{ 
  //FIXME: delete all registered AlgoImpls!!!
  std::vector<AlgoImpl*>::iterator it = regAlgos_.begin();
  for (; it != regAlgos_.end(); ++it) {
    delete *it;
  }  
  delete checkAlgo_; 
}

Member Function Documentation

void AlgoPos::checkTermination ( void  ) [protected]

for algorithms with incr_==0 the algorithm must check whether to terminate

Overload this function in case the algorithm is a 'incr_==0' type. In this case provide some code which checks using perhaps the value of count_ and/or supplied algorithm parameters to check whether terminate() has to be called or not.

Will only work, if one registered algorithm AlgoImpl has been selected by checkParameters()

The default implementation will immidiately terminate the algorithm in case incr_==0.

In case of incr_!=0: checkTermination() is not called then, the algorithm will terminate automatically when the specified range [start_, end_, incr_] has been covered.

Definition at line 128 of file AlgoPos.cc.

References AlgoImpl::checkTermination(), and selAlgo_.

Referenced by next().

int AlgoPos::copyno ( void  ) const

copy-number calculation

Definition at line 83 of file AlgoPos.cc.

References AlgoImpl::copyno(), and selAlgo_.

{
  return selAlgo_->copyno();
}
int AlgoPos::end ( void  ) const [inline]

Definition at line 84 of file AlgoPos.h.

References end_.

Referenced by setParameters().

{ return end_; }
bool AlgoPos::go ( ) const

no further algorithm processing if go() returns false

Definition at line 140 of file AlgoPos.cc.

References terminate_.

{ 
  return !terminate_; 
}
int AlgoPos::incr ( ) const [inline]

Definition at line 85 of file AlgoPos.h.

References incr_.

Referenced by setParameters().

{ return incr_; }
void AlgoPos::next ( void  )

update for next iteration of the algorithm, don't call it yourself!

In the case of incr_!=0 this function will set curr_ to the next point in the range [start_,end_,incr_] or terminate the algorithm if the next point is going to be out of the range bounds.

In the case of incr_=0 this function calls checkTermination() in which the algorithm itself must check whether to terminate or not

Definition at line 97 of file AlgoPos.cc.

References checkTermination(), count_, curr_, end_, incr_, start_, and terminate().

{
  // increase the invocation count of the algorithm
  ++count_;
  
  
  // iterate to the next position in the range [start_,end_,incr_]
  // only if incr_ != 0
  
  if (incr_>0) {
    curr_ += incr_;
    if (curr_>end_) {
      terminate();
    }  
  }
  
  if (incr_<0) {
    curr_ += incr_;
    if (curr_<start_) {
      terminate();
    }  
  }
  
  // incr_==0: the algorithm has to self-check whether to terminate
  if (incr_==0) {
    checkTermination();
  }
}
size_t AlgoPos::numRegistered ( )

return number of registered implementations

Definition at line 78 of file AlgoPos.cc.

References regAlgos_.

{
  return regAlgos_.size();
}
const parE_type& AlgoPos::parE ( ) const [inline]

Definition at line 87 of file AlgoPos.h.

References ParE_.

{ return ParE_; }
const parS_type& AlgoPos::parS ( ) const [inline]

Definition at line 86 of file AlgoPos.h.

References ParS_.

{ return ParS_; }
void AlgoPos::registerAlgo ( AlgoImpl a)

registers an implementation of the algorithm

At least 1 implementation must be registered.

In case multiple implementations are registered, only one checkParamters() member function of these is allowed to return true given a set of user-supplied parameters. The particular registered algorithm is then selected. If all checkParamters() of the registered AlgoImpls return false, an exception is raised.

Definition at line 73 of file AlgoPos.cc.

References regAlgos_.

Referenced by AlgoImpl::AlgoImpl().

{
  regAlgos_.push_back(a);
}
DDRotationMatrix AlgoPos::rotation ( void  )

rotation calculations

Will only work, if one registered algorithm AlgoImpl has been selected by checkParameters()

Definition at line 152 of file AlgoPos.cc.

References AlgoImpl::rotation(), and selAlgo_.

{
  return selAlgo_->rotation();
}
bool AlgoPos::select ( ) [protected]

selection of one of the registered AlgoImpl

checkParamters() of the registered AlgoImpl objects will be called sequentially until either an error is detected in the parameters or true is returned. In the latter case this AlgoImpl is choosen.

select() returns true as soon as a checkParamters() of a registered AlgoImpl returns true. Otherwise it returns false.

Definition at line 158 of file AlgoPos.cc.

References AlgoCheck::check(), checkAlgo_, err_, ParE_, ParS_, regAlgos_, query::result, alignCSCRings::s, and selAlgo_.

Referenced by setParameters().

{
  bool result = false;
  
  // if constraints checking is enabled (object checkAlgo_ is there) ,
  // check the contraints of the parameters as specified in the schema.
  if (checkAlgo_) {
    result = (checkAlgo_->check(ParS_,ParE_,err_));
  }
  else {
    result = true;
  }  
  
  
  if (result) { // select an algorithm-implementation only if the parameters are ok
    std::vector<AlgoImpl*>::iterator it = regAlgos_.begin();
    for (; it != regAlgos_.end(); ++it) {
      std::string::size_type s = err_.size();
      result = (*it)->checkParameters();
      if (s!=err_.size()) { // uups, error-std::string was modified! tell it, where:
        err_ += std::string("\tin algo.implementation labeled \"") + (*it)->label_ + std::string("\"\n");
      }
      if (result) { // select the algorithm
        selAlgo_ = *it;
        break;
      }  
    }
  }  
  // parameters are not ok, put something into the error message
  /*
  if (!result) { 
   err_ += "\tin algorithm named " + std::string("[") 
        +  ns() + std::string(":") + name() + std::string("]\n");
  }     
  */   
  
  return result;
}
void AlgoPos::setParameters ( int  start,
int  end,
int  incr,
const parS_type ps,
const parE_type pe 
)

sets mandatory and optional parameters

Definition at line 26 of file AlgoPos.cc.

References CastorDataFrameFilter_impl::check(), count_, curr_, AlgoImpl::d2s(), end(), end_, err_, incr(), incr_, ParE_, ParS_, select(), start(), start_, and terminate_.

{
  // init the algorithm when parameters are set
  terminate_ = false;
  start_     = start;
  end_       = end;
  incr_      = incr;
  if (incr>0) curr_ = start;
  if (incr<0) curr_ = end;  
  count_ = 1;

  // now check mandatory parameters, then let the algorithm check all parametes itself.
  // collect all error messages in std::string err_
  
  bool check = true;
  if (incr) {
    if (start>=end) {
      check = false;
    }  
  }
  if (!check) err_ = "\twrong range specification: (start<end && incr!=0)==false, [start,end,incr]=["
                   + AlgoImpl::d2s(start) + "," 
                   + AlgoImpl::d2s(end) + "," 
                   + AlgoImpl::d2s(incr) + "]\n" ;

  if (incr==0) {
    if ( (start!=0) || (end!=0) ) {
      err_ += "\tincr==0 requires start==0 and end==0 in the range. range: [start,end,incr]=["
                   + AlgoImpl::d2s(start) + "," 
                   + AlgoImpl::d2s(end) + "," 
                   + AlgoImpl::d2s(incr) + "]\n" ;
      check = false;               

    }
  }     
                           
  // select one of the registered algorithm implementations
  ParS_ = ps;
  ParE_ = pe;
  if (!select()) check = false;
  
  if (!check) 
    throw DDException(err_);
}
int AlgoPos::start ( ) const [inline]

Definition at line 83 of file AlgoPos.h.

References start_.

Referenced by setParameters().

{ return start_; }
void AlgoPos::stream ( std::ostream &  os) const

streams some information about common parameters and the name of the algorithm

void AlgoPos::terminate ( void  ) [protected]

terminates current algorithmic processing

current algorithm iteration will not result in a positioning, if terminate() was called from within translation() or rotation()

Definition at line 134 of file AlgoPos.cc.

References terminate_.

Referenced by next().

{ 
  terminate_=true; 
}
DD3Vector AlgoPos::translation ( void  )

translation calculations

Will only work, if one registered algorithm AlgoImpl has been selected by checkParameters()

Definition at line 146 of file AlgoPos.cc.

References selAlgo_, and AlgoImpl::translation().

{
  return selAlgo_->translation();
}

Friends And Related Function Documentation

friend class AlgoImpl [friend]

Definition at line 29 of file AlgoPos.h.


Member Data Documentation

checking object which checks the user-supplied parameters whether they fulfill their spec.

Definition at line 184 of file AlgoPos.h.

Referenced by select(), and ~AlgoPos().

int AlgoPos::count_ [protected]

invocation count

count_ will be set to 1 at the first invocation of the algorithm and will be increased by 1 at every subsequent invocation.

Definition at line 153 of file AlgoPos.h.

Referenced by next(), and setParameters().

int AlgoPos::curr_ [protected]

current position in the range of the algorithm

see doc of start_, end_, incr_ as well.

In case of incr_==0, the value of curr_ is undefined.

Definition at line 146 of file AlgoPos.h.

Referenced by next(), and setParameters().

int AlgoPos::end_ [protected]

Definition at line 138 of file AlgoPos.h.

Referenced by end(), next(), setParameters(), and DDXMLElement::stream().

std::string AlgoPos::err_ [protected]

std::string to hold potential error messages found inside checkParameters()

Definition at line 175 of file AlgoPos.h.

Referenced by select(), and setParameters().

int AlgoPos::incr_ [protected]

Definition at line 138 of file AlgoPos.h.

Referenced by incr(), next(), setParameters(), and DDXMLElement::stream().

double valued parameters passed to the algorithm

Before the first invocation of the algorithm ParS_ will be filled with the std::string-valued parameters passed to the algorithm implementation object AlgoImpl.

Definition at line 169 of file AlgoPos.h.

Referenced by parE(), select(), setParameters(), and DDXMLElement::stream().

std::string valued parameters passed to the algorithm

Before the first invocation of the algorithm ParS_ will be filled with the std::string-valued parameters passed to the algorithm implementation object AlgoImpl.

Definition at line 161 of file AlgoPos.h.

Referenced by parS(), select(), setParameters(), and DDXMLElement::stream().

std::vector<AlgoImpl*> AlgoPos::regAlgos_ [protected]

registry of algorithm implementation objects

Definition at line 178 of file AlgoPos.h.

Referenced by numRegistered(), registerAlgo(), select(), and ~AlgoPos().

selected algorithm implementation

Definition at line 181 of file AlgoPos.h.

Referenced by checkTermination(), copyno(), rotation(), select(), and translation().

int AlgoPos::start_ [protected]

range of the algorithm

The algorithm will be invoked like /c for(curr_=start_; curr_<=end_; curr_ += incr_) { algo code } // incr > 0 /c for(curr_=end_; curr_>=start_; curr_ += incr_) { algo code } // incr < 0

If incr_==0 the algorithm code will be invoked until term() is called from within the algorithm code. The iteration in wich term() is called will not result in a positioning.

Definition at line 138 of file AlgoPos.h.

Referenced by next(), setParameters(), start(), and DDXMLElement::stream().

bool AlgoPos::terminate_ [protected]

flag to signal whether the algorithm has finished (true)

Definition at line 172 of file AlgoPos.h.

Referenced by go(), setParameters(), and terminate().