CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlgoPos.cc
Go to the documentation of this file.
5 
6 using namespace std;
7 
9 : start_(0), end_(0), incr_(0), curr_(0), count_(0),
10 terminate_(false), selAlgo_(0), checkAlgo_(check)
11 { }
12 
13 
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 }
23 
24 
25 void AlgoPos::setParameters(int start, int end, int incr,
26  const parS_type & ps, const parE_type & pe)
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 }
70 
71 
73 {
74  regAlgos_.push_back(a);
75 }
76 
78 {
79  return regAlgos_.size();
80 }
81 
82 int AlgoPos::copyno() const
83 {
84  return selAlgo_->copyno();
85 }
86 
87 
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 }
124 
125 
126 
128 {
130 }
131 
132 
134 {
135  terminate_=true;
136 }
137 
138 
139 bool AlgoPos::go() const
140 {
141  return !terminate_;
142 }
143 
144 
146 {
147  return selAlgo_->translation();
148 }
149 
150 
152 {
153  return selAlgo_->rotation();
154 }
155 
156 
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 }
195 
196 // stream information about the alog-parameters
197 void AlgoPos::stream(ostream & os) const
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
base class for generated checking code for algorithm parameters.
Definition: AlgoCheck.h:10
AlgoImpl * selAlgo_
selected algorithm implementation
Definition: AlgoPos.h:181
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
void checkTermination()
for algorithms with incr_==0 the algorithm must check whether to terminate
Definition: AlgoPos.cc:127
virtual void checkTermination()
for algorithms with incr_==0 the algorithm must check whether to terminate
Definition: AlgoImpl.cc:34
void stream(std::ostream &os) const
streams some information about common parameters and the name of the algorithm
Definition: AlgoPos.cc:197
size_t numRegistered()
return number of registered implementations
Definition: AlgoPos.cc:77
int copyno() const
copy-number calculation
Definition: AlgoPos.cc:82
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
int incr() const
Definition: AlgoPos.h:85
void setParameters(int start, int end, int incr, const parS_type &, const parE_type &)
sets mandatory and optional parameters
Definition: AlgoPos.cc:25
std::vector< AlgoImpl * > regAlgos_
registry of algorithm implementation objects
Definition: AlgoPos.h:178
void terminate()
terminates current algorithmic processing
Definition: AlgoPos.cc:133
AlgoPos(AlgoCheck *check=0)
creates an algorithm named name
Definition: AlgoPos.cc:8
void next()
update for next iteration of the algorithm, don&#39;t call it yourself!
Definition: AlgoPos.cc:96
virtual int copyno() const
copy-number calculation
Definition: AlgoImpl.cc:22
int count_
invocation count
Definition: AlgoPos.h:153
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
virtual DDRotationMatrix rotation()=0
subclass must calculate a rotation matrix
DDRotationMatrix rotation()
rotation calculations
Definition: AlgoPos.cc:151
int start() const
Definition: AlgoPos.h:83
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
std::map< std::string, std::vector< std::string > > parS_type
Definition: DDAlgoPar.h:9
tuple result
Definition: query.py:137
implementation of an algorithm, non generated checking code.
Definition: AlgoImpl.h:19
#define end
Definition: vmac.h:38
~AlgoPos()
destructor clears registered AlgoImpl
Definition: AlgoPos.cc:14
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
void registerAlgo(AlgoImpl *)
registers an implementation of the algorithm
Definition: AlgoPos.cc:72
double a
Definition: hdecay.h:121
int incr_
Definition: AlgoPos.h:138
bool go() const
no further algorithm processing if go() returns false
Definition: AlgoPos.cc:139
virtual DD3Vector translation()=0
subclass must calculate a translation std::vector
int end() const
Definition: AlgoPos.h:84
DD3Vector translation()
translation calculations
Definition: AlgoPos.cc:145
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
std::map< std::string, std::vector< double > > parE_type
Definition: DDAlgoPar.h:12
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