#include <DetectorDescription/ExprAlgo/interface/AlgoPos.h>
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_type & | parE () const |
const parS_type & | parS () 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 | |
AlgoCheck * | checkAlgo_ |
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 | |
AlgoImpl * | selAlgo_ |
selected algorithm implementation | |
int | start_ |
range of the algorithm | |
bool | terminate_ |
flag to signal whether the algorithm has finished (true) | |
Friends | |
class | AlgoImpl |
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.
AlgoPos::AlgoPos | ( | AlgoCheck * | check = 0 |
) |
creates an algorithm named name
Definition at line 9 of file AlgoPos.cc.
00010 : start_(0), end_(0), incr_(0), curr_(0), count_(0), 00011 terminate_(false), selAlgo_(0), checkAlgo_(check) 00012 { }
AlgoPos::~AlgoPos | ( | ) |
destructor clears registered AlgoImpl
Definition at line 15 of file AlgoPos.cc.
References checkAlgo_, it, and regAlgos_.
00016 { 00017 //FIXME: delete all registered AlgoImpls!!! 00018 std::vector<AlgoImpl*>::iterator it = regAlgos_.begin(); 00019 for (; it != regAlgos_.end(); ++it) { 00020 delete *it; 00021 } 00022 delete checkAlgo_; 00023 }
void AlgoPos::checkTermination | ( | ) | [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().
00129 { 00130 selAlgo_->checkTermination(); 00131 }
int AlgoPos::copyno | ( | ) | const |
copy-number calculation
Definition at line 83 of file AlgoPos.cc.
References AlgoImpl::copyno(), and selAlgo_.
int AlgoPos::end | ( | ) | const [inline] |
bool AlgoPos::go | ( | ) | const |
no further algorithm processing if go() returns false
Definition at line 140 of file AlgoPos.cc.
References terminate_.
00141 { 00142 return !terminate_; 00143 }
int AlgoPos::incr | ( | ) | const [inline] |
void AlgoPos::next | ( | ) |
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().
00098 { 00099 // increase the invocation count of the algorithm 00100 ++count_; 00101 00102 00103 // iterate to the next position in the range [start_,end_,incr_] 00104 // only if incr_ != 0 00105 00106 if (incr_>0) { 00107 curr_ += incr_; 00108 if (curr_>end_) { 00109 terminate(); 00110 } 00111 } 00112 00113 if (incr_<0) { 00114 curr_ += incr_; 00115 if (curr_<start_) { 00116 terminate(); 00117 } 00118 } 00119 00120 // incr_==0: the algorithm has to self-check whether to terminate 00121 if (incr_==0) { 00122 checkTermination(); 00123 } 00124 }
size_t AlgoPos::numRegistered | ( | ) |
return number of registered implementations
Definition at line 78 of file AlgoPos.cc.
References regAlgos_.
00079 { 00080 return regAlgos_.size(); 00081 }
const parE_type& AlgoPos::parE | ( | ) | const [inline] |
const parS_type& AlgoPos::parS | ( | ) | const [inline] |
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().
00074 { 00075 regAlgos_.push_back(a); 00076 }
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_.
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_, it, ParE_, ParS_, regAlgos_, HLT_VtxMuL3::result, s, and selAlgo_.
Referenced by setParameters().
00159 { 00160 bool result = false; 00161 00162 // if constraints checking is enabled (object checkAlgo_ is there) , 00163 // check the contraints of the parameters as specified in the schema. 00164 if (checkAlgo_) { 00165 result = (checkAlgo_->check(ParS_,ParE_,err_)); 00166 } 00167 else { 00168 result = true; 00169 } 00170 00171 00172 if (result) { // select an algorithm-implementation only if the parameters are ok 00173 std::vector<AlgoImpl*>::iterator it = regAlgos_.begin(); 00174 for (; it != regAlgos_.end(); ++it) { 00175 std::string::size_type s = err_.size(); 00176 result = (*it)->checkParameters(); 00177 if (s!=err_.size()) { // uups, error-std::string was modified! tell it, where: 00178 err_ += std::string("\tin algo.implementation labeled \"") + (*it)->label_ + std::string("\"\n"); 00179 } 00180 if (result) { // select the algorithm 00181 selAlgo_ = *it; 00182 break; 00183 } 00184 } 00185 } 00186 // parameters are not ok, put something into the error message 00187 /* 00188 if (!result) { 00189 err_ += "\tin algorithm named " + std::string("[") 00190 + ns() + std::string(":") + name() + std::string("]\n"); 00191 } 00192 */ 00193 00194 return result; 00195 }
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 HcalDataFrameFilter_impl::check(), count_, curr_, AlgoImpl::d2s(), end_, err_, incr_, ParE_, ParS_, select(), start_, and terminate_.
00028 { 00029 // init the algorithm when parameters are set 00030 terminate_ = false; 00031 start_ = start; 00032 end_ = end; 00033 incr_ = incr; 00034 if (incr>0) curr_ = start; 00035 if (incr<0) curr_ = end; 00036 count_ = 1; 00037 00038 // now check mandatory parameters, then let the algorithm check all parametes itself. 00039 // collect all error messages in std::string err_ 00040 00041 bool check = true; 00042 if (incr) { 00043 if (start>=end) { 00044 check = false; 00045 } 00046 } 00047 if (!check) err_ = "\twrong range specification: (start<end && incr!=0)==false, [start,end,incr]=[" 00048 + AlgoImpl::d2s(start) + "," 00049 + AlgoImpl::d2s(end) + "," 00050 + AlgoImpl::d2s(incr) + "]\n" ; 00051 00052 if (incr==0) { 00053 if ( (start!=0) || (end!=0) ) { 00054 err_ += "\tincr==0 requires start==0 and end==0 in the range. range: [start,end,incr]=[" 00055 + AlgoImpl::d2s(start) + "," 00056 + AlgoImpl::d2s(end) + "," 00057 + AlgoImpl::d2s(incr) + "]\n" ; 00058 check = false; 00059 00060 } 00061 } 00062 00063 // select one of the registered algorithm implementations 00064 ParS_ = ps; 00065 ParE_ = pe; 00066 if (!select()) check = false; 00067 00068 if (!check) 00069 throw DDException(err_); 00070 }
int AlgoPos::start | ( | ) | const [inline] |
void AlgoPos::stream | ( | std::ostream & | os | ) | const |
streams some information about common parameters and the name of the algorithm
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().
00135 { 00136 terminate_=true; 00137 }
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().
00147 { 00148 return selAlgo_->translation(); 00149 }
AlgoCheck* AlgoPos::checkAlgo_ [protected] |
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] |
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] |
parE_type AlgoPos::ParE_ [protected] |
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(), and setParameters().
parS_type AlgoPos::ParS_ [protected] |
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(), and setParameters().
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().
AlgoImpl* AlgoPos::selAlgo_ [protected] |
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(), and start().
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().