CMS 3D CMS Logo

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

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

#include <AlgoPos.h>

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

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 8 of file AlgoPos.cc.

9 : start_(0), end_(0), incr_(0), curr_(0), count_(0),
10 terminate_(false), selAlgo_(0), checkAlgo_(check)
11 { }
int end_
Definition: AlgoPos.h:138
AlgoImpl * selAlgo_
selected algorithm implementation
Definition: AlgoPos.h:181
int curr_
current position in the range of the algorithm
Definition: AlgoPos.h:146
int count_
invocation count
Definition: AlgoPos.h:153
int start_
range of the algorithm
Definition: AlgoPos.h:138
bool terminate_
flag to signal whether the algorithm has finished (true)
Definition: AlgoPos.h:172
int incr_
Definition: AlgoPos.h:138
AlgoCheck * checkAlgo_
checking object which checks the user-supplied parameters whether they fulfill their spec...
Definition: AlgoPos.h:184
AlgoPos::~AlgoPos ( )

destructor clears registered AlgoImpl

Definition at line 14 of file AlgoPos.cc.

References checkAlgo_, and regAlgos_.

15 {
16  //FIXME: delete all registered AlgoImpls!!!
17  std::vector<AlgoImpl*>::iterator it = regAlgos_.begin();
18  for (; it != regAlgos_.end(); ++it) {
19  delete *it;
20  }
21  delete checkAlgo_;
22 }
std::vector< AlgoImpl * > regAlgos_
registry of algorithm implementation objects
Definition: AlgoPos.h:178
AlgoCheck * checkAlgo_
checking object which checks the user-supplied parameters whether they fulfill their spec...
Definition: AlgoPos.h:184

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 127 of file AlgoPos.cc.

References AlgoImpl::checkTermination(), and selAlgo_.

Referenced by next().

128 {
130 }
AlgoImpl * selAlgo_
selected algorithm implementation
Definition: AlgoPos.h:181
virtual void checkTermination()
for algorithms with incr_==0 the algorithm must check whether to terminate
Definition: AlgoImpl.cc:34
int AlgoPos::copyno ( void  ) const

copy-number calculation

Definition at line 82 of file AlgoPos.cc.

References AlgoImpl::copyno(), and selAlgo_.

83 {
84  return selAlgo_->copyno();
85 }
AlgoImpl * selAlgo_
selected algorithm implementation
Definition: AlgoPos.h:181
virtual int copyno() const
copy-number calculation
Definition: AlgoImpl.cc:22
int AlgoPos::end ( void  ) const
inline

Definition at line 84 of file AlgoPos.h.

References end_.

Referenced by Types.LuminosityBlockRange::cppID(), Types.EventRange::cppID(), and setParameters().

84 { return end_; }
int end_
Definition: AlgoPos.h:138
bool AlgoPos::go ( ) const

no further algorithm processing if go() returns false

Definition at line 139 of file AlgoPos.cc.

References terminate_.

140 {
141  return !terminate_;
142 }
bool terminate_
flag to signal whether the algorithm has finished (true)
Definition: AlgoPos.h:172
int AlgoPos::incr ( ) const
inline

Definition at line 85 of file AlgoPos.h.

References incr_.

Referenced by setParameters().

85 { return incr_; }
int incr_
Definition: AlgoPos.h:138
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 96 of file AlgoPos.cc.

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

Referenced by BeautifulSoup.PageElement::_invert().

97 {
98  // increase the invocation count of the algorithm
99  ++count_;
100 
101 
102  // iterate to the next position in the range [start_,end_,incr_]
103  // only if incr_ != 0
104 
105  if (incr_>0) {
106  curr_ += incr_;
107  if (curr_>end_) {
108  terminate();
109  }
110  }
111 
112  if (incr_<0) {
113  curr_ += incr_;
114  if (curr_<start_) {
115  terminate();
116  }
117  }
118 
119  // incr_==0: the algorithm has to self-check whether to terminate
120  if (incr_==0) {
122  }
123 }
int end_
Definition: AlgoPos.h:138
int curr_
current position in the range of the algorithm
Definition: AlgoPos.h:146
void checkTermination()
for algorithms with incr_==0 the algorithm must check whether to terminate
Definition: AlgoPos.cc:127
void terminate()
terminates current algorithmic processing
Definition: AlgoPos.cc:133
int count_
invocation count
Definition: AlgoPos.h:153
int start_
range of the algorithm
Definition: AlgoPos.h:138
int incr_
Definition: AlgoPos.h:138
size_t AlgoPos::numRegistered ( )

return number of registered implementations

Definition at line 77 of file AlgoPos.cc.

References regAlgos_.

78 {
79  return regAlgos_.size();
80 }
std::vector< AlgoImpl * > regAlgos_
registry of algorithm implementation objects
Definition: AlgoPos.h:178
const parE_type& AlgoPos::parE ( ) const
inline

Definition at line 87 of file AlgoPos.h.

References ParE_.

87 { return ParE_; }
parE_type ParE_
double valued parameters passed to the algorithm
Definition: AlgoPos.h:169
const parS_type& AlgoPos::parS ( ) const
inline

Definition at line 86 of file AlgoPos.h.

References ParS_.

86 { return ParS_; }
parS_type ParS_
std::string valued parameters passed to the algorithm
Definition: AlgoPos.h:161
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 72 of file AlgoPos.cc.

References regAlgos_.

Referenced by AlgoImpl::AlgoImpl().

73 {
74  regAlgos_.push_back(a);
75 }
std::vector< AlgoImpl * > regAlgos_
registry of algorithm implementation objects
Definition: AlgoPos.h:178
DDRotationMatrix AlgoPos::rotation ( void  )

rotation calculations

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

Definition at line 151 of file AlgoPos.cc.

References AlgoImpl::rotation(), and selAlgo_.

152 {
153  return selAlgo_->rotation();
154 }
AlgoImpl * selAlgo_
selected algorithm implementation
Definition: AlgoPos.h:181
virtual DDRotationMatrix rotation()=0
subclass must calculate a rotation matrix
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 157 of file AlgoPos.cc.

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

Referenced by Vispa.Views.LineDecayView.LineDecayContainer::createObject(), Vispa.Plugins.Browser.BrowserTabController.BrowserTabController::find(), Vispa.Views.LineDecayView.LineDecayContainer::mousePressEvent(), Vispa.Gui.PortConnection.PointToPointConnection::mousePressEvent(), Vispa.Gui.VispaWidget.VispaWidget::mousePressEvent(), Vispa.Views.AbstractView.AbstractView::restoreSelection(), and setParameters().

158 {
159  bool result = false;
160 
161  // if constraints checking is enabled (object checkAlgo_ is there) ,
162  // check the contraints of the parameters as specified in the schema.
163  if (checkAlgo_) {
164  result = (checkAlgo_->check(ParS_,ParE_,err_));
165  }
166  else {
167  result = true;
168  }
169 
170 
171  if (result) { // select an algorithm-implementation only if the parameters are ok
172  std::vector<AlgoImpl*>::iterator it = regAlgos_.begin();
173  for (; it != regAlgos_.end(); ++it) {
174  std::string::size_type s = err_.size();
175  result = (*it)->checkParameters();
176  if (s!=err_.size()) { // uups, error-std::string was modified! tell it, where:
177  err_ += std::string("\tin algo.implementation labeled \"") + (*it)->label_ + std::string("\"\n");
178  }
179  if (result) { // select the algorithm
180  selAlgo_ = *it;
181  break;
182  }
183  }
184  }
185  // parameters are not ok, put something into the error message
186  /*
187  if (!result) {
188  err_ += "\tin algorithm named " + std::string("[")
189  + ns() + std::string(":") + name() + std::string("]\n");
190  }
191  */
192 
193  return result;
194 }
AlgoImpl * selAlgo_
selected algorithm implementation
Definition: AlgoPos.h:181
bool check(parS_type &ps, parE_type &pe, std::string &err)
returns true if the check was successfull (parameters conform to XML specification) ...
Definition: AlgoCheck.cc:5
uint16_t size_type
std::vector< AlgoImpl * > regAlgos_
registry of algorithm implementation objects
Definition: AlgoPos.h:178
tuple result
Definition: query.py:137
parS_type ParS_
std::string valued parameters passed to the algorithm
Definition: AlgoPos.h:161
parE_type ParE_
double valued parameters passed to the algorithm
Definition: AlgoPos.h:169
AlgoCheck * checkAlgo_
checking object which checks the user-supplied parameters whether they fulfill their spec...
Definition: AlgoPos.h:184
std::string err_
std::string to hold potential error messages found inside checkParameters()
Definition: AlgoPos.h:175
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 25 of file AlgoPos.cc.

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

27 {
28  // init the algorithm when parameters are set
29  terminate_ = false;
30  start_ = start;
31  end_ = end;
32  incr_ = incr;
33  if (incr>0) curr_ = start;
34  if (incr<0) curr_ = end;
35  count_ = 1;
36 
37  // now check mandatory parameters, then let the algorithm check all parametes itself.
38  // collect all error messages in std::string err_
39 
40  bool check = true;
41  if (incr) {
42  if (start>=end) {
43  check = false;
44  }
45  }
46  if (!check) err_ = "\twrong range specification: (start<end && incr!=0)==false, [start,end,incr]=["
47  + AlgoImpl::d2s(start) + ","
48  + AlgoImpl::d2s(end) + ","
49  + AlgoImpl::d2s(incr) + "]\n" ;
50 
51  if (incr==0) {
52  if ( (start!=0) || (end!=0) ) {
53  err_ += "\tincr==0 requires start==0 and end==0 in the range. range: [start,end,incr]=["
54  + AlgoImpl::d2s(start) + ","
55  + AlgoImpl::d2s(end) + ","
56  + AlgoImpl::d2s(incr) + "]\n" ;
57  check = false;
58 
59  }
60  }
61 
62  // select one of the registered algorithm implementations
63  ParS_ = ps;
64  ParE_ = pe;
65  if (!select()) check = false;
66 
67  if (!check)
68  throw cms::Exception("DDException") << err_;
69 }
int end_
Definition: AlgoPos.h:138
bool select()
selection of one of the registered AlgoImpl
Definition: AlgoPos.cc:157
int curr_
current position in the range of the algorithm
Definition: AlgoPos.h:146
int incr() const
Definition: AlgoPos.h:85
int count_
invocation count
Definition: AlgoPos.h:153
bool check(const std::string &)
int start() const
Definition: AlgoPos.h:83
int start_
range of the algorithm
Definition: AlgoPos.h:138
parS_type ParS_
std::string valued parameters passed to the algorithm
Definition: AlgoPos.h:161
bool terminate_
flag to signal whether the algorithm has finished (true)
Definition: AlgoPos.h:172
static std::string d2s(double x)
ahh, converts a double into a std::string ... yet another one of this kind!
Definition: AlgoImpl.cc:40
parE_type ParE_
double valued parameters passed to the algorithm
Definition: AlgoPos.h:169
int incr_
Definition: AlgoPos.h:138
int end() const
Definition: AlgoPos.h:84
std::string err_
std::string to hold potential error messages found inside checkParameters()
Definition: AlgoPos.h:175
int AlgoPos::start ( ) const
inline

Definition at line 83 of file AlgoPos.h.

References start_.

Referenced by progressbar.ProgressBar::__next__(), Types.LuminosityBlockRange::cppID(), Types.EventRange::cppID(), and setParameters().

83 { return start_; }
int start_
range of the algorithm
Definition: AlgoPos.h:138
void AlgoPos::stream ( std::ostream &  os) const

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

Definition at line 197 of file AlgoPos.cc.

References end_, incr_, ParE_, ParS_, and start_.

198 {
199  os << "start=" << start_ << " end=" << end_ << " incr=" << incr_ << std::endl;
200  parE_type::const_iterator eit = ParE_.begin();
201  for (; eit != ParE_.end() ; ++eit) {
202  std::vector<double>::const_iterator sit = eit->second.begin();
203  os << "parE name=" << eit->first;
204  for (; sit != eit->second.end(); ++sit) {
205  os << " val=" << *sit << std::endl;
206  }
207  }
208  parS_type::const_iterator stit = ParS_.begin();
209  for (; stit != ParS_.end() ; ++stit) {
210  std::vector<std::string>::const_iterator sit = stit->second.begin();
211  os << "parS name=" << stit->first;
212  for (; sit != stit->second.end(); ++sit) {
213  os << " val=" << *sit << std::endl;
214  }
215  }
216 }
int end_
Definition: AlgoPos.h:138
int start_
range of the algorithm
Definition: AlgoPos.h:138
parS_type ParS_
std::string valued parameters passed to the algorithm
Definition: AlgoPos.h:161
parE_type ParE_
double valued parameters passed to the algorithm
Definition: AlgoPos.h:169
int incr_
Definition: AlgoPos.h:138
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 133 of file AlgoPos.cc.

References terminate_.

Referenced by next().

134 {
135  terminate_=true;
136 }
bool terminate_
flag to signal whether the algorithm has finished (true)
Definition: AlgoPos.h:172
DD3Vector AlgoPos::translation ( void  )

translation calculations

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

Definition at line 145 of file AlgoPos.cc.

References selAlgo_, and AlgoImpl::translation().

146 {
147  return selAlgo_->translation();
148 }
AlgoImpl * selAlgo_
selected algorithm implementation
Definition: AlgoPos.h:181
virtual DD3Vector translation()=0
subclass must calculate a translation std::vector

Friends And Related Function Documentation

friend class AlgoImpl
friend

Definition at line 29 of file AlgoPos.h.

Member Data Documentation

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

Definition at line 138 of file AlgoPos.h.

Referenced by end(), next(), setParameters(), and 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 stream().

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(), setParameters(), and stream().

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(), setParameters(), and 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().

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(), start(), and 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().