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.
1 
6 
7 using namespace std;
8 
10  : start_(0), end_(0), incr_(0), curr_(0), count_(0),
11  terminate_(false), selAlgo_(0), checkAlgo_(check)
12 { }
13 
14 
16 {
17  //FIXME: delete all registered AlgoImpls!!!
18  std::vector<AlgoImpl*>::iterator it = regAlgos_.begin();
19  for (; it != regAlgos_.end(); ++it) {
20  delete *it;
21  }
22  delete checkAlgo_;
23 }
24 
25 
26 void AlgoPos::setParameters(int start, int end, int incr,
27  const parS_type & ps, const parE_type & pe)
28 {
29  // init the algorithm when parameters are set
30  terminate_ = false;
31  start_ = start;
32  end_ = end;
33  incr_ = incr;
34  if (incr>0) curr_ = start;
35  if (incr<0) curr_ = end;
36  count_ = 1;
37 
38  // now check mandatory parameters, then let the algorithm check all parametes itself.
39  // collect all error messages in std::string err_
40 
41  bool check = true;
42  if (incr) {
43  if (start>=end) {
44  check = false;
45  }
46  }
47  if (!check) err_ = "\twrong range specification: (start<end && incr!=0)==false, [start,end,incr]=["
48  + AlgoImpl::d2s(start) + ","
49  + AlgoImpl::d2s(end) + ","
50  + AlgoImpl::d2s(incr) + "]\n" ;
51 
52  if (incr==0) {
53  if ( (start!=0) || (end!=0) ) {
54  err_ += "\tincr==0 requires start==0 and end==0 in the range. range: [start,end,incr]=["
55  + AlgoImpl::d2s(start) + ","
56  + AlgoImpl::d2s(end) + ","
57  + AlgoImpl::d2s(incr) + "]\n" ;
58  check = false;
59 
60  }
61  }
62 
63  // select one of the registered algorithm implementations
64  ParS_ = ps;
65  ParE_ = pe;
66  if (!select()) check = false;
67 
68  if (!check)
69  throw DDException(err_);
70 }
71 
72 
74 {
75  regAlgos_.push_back(a);
76 }
77 
79 {
80  return regAlgos_.size();
81 }
82 
83 int AlgoPos::copyno() const
84 {
85  return selAlgo_->copyno();
86 }
87 
88 
98 {
99  // increase the invocation count of the algorithm
100  ++count_;
101 
102 
103  // iterate to the next position in the range [start_,end_,incr_]
104  // only if incr_ != 0
105 
106  if (incr_>0) {
107  curr_ += incr_;
108  if (curr_>end_) {
109  terminate();
110  }
111  }
112 
113  if (incr_<0) {
114  curr_ += incr_;
115  if (curr_<start_) {
116  terminate();
117  }
118  }
119 
120  // incr_==0: the algorithm has to self-check whether to terminate
121  if (incr_==0) {
123  }
124 }
125 
126 
127 
129 {
131 }
132 
133 
135 {
136  terminate_=true;
137 }
138 
139 
140 bool AlgoPos::go() const
141 {
142  return !terminate_;
143 }
144 
145 
147 {
148  return selAlgo_->translation();
149 }
150 
151 
153 {
154  return selAlgo_->rotation();
155 }
156 
157 
159 {
160  bool result = false;
161 
162  // if constraints checking is enabled (object checkAlgo_ is there) ,
163  // check the contraints of the parameters as specified in the schema.
164  if (checkAlgo_) {
165  result = (checkAlgo_->check(ParS_,ParE_,err_));
166  }
167  else {
168  result = true;
169  }
170 
171 
172  if (result) { // select an algorithm-implementation only if the parameters are ok
173  std::vector<AlgoImpl*>::iterator it = regAlgos_.begin();
174  for (; it != regAlgos_.end(); ++it) {
175  std::string::size_type s = err_.size();
176  result = (*it)->checkParameters();
177  if (s!=err_.size()) { // uups, error-std::string was modified! tell it, where:
178  err_ += std::string("\tin algo.implementation labeled \"") + (*it)->label_ + std::string("\"\n");
179  }
180  if (result) { // select the algorithm
181  selAlgo_ = *it;
182  break;
183  }
184  }
185  }
186  // parameters are not ok, put something into the error message
187  /*
188  if (!result) {
189  err_ += "\tin algorithm named " + std::string("[")
190  + ns() + std::string(":") + name() + std::string("]\n");
191  }
192  */
193 
194  return result;
195 }
196 
197 // stream information about the alog-parameters
198 void AlgoPos::stream(ostream & os) const
199 {
200  os << "start=" << start_ << " end=" << end_ << " incr=" << incr_ << std::endl;
201  parE_type::const_iterator eit = ParE_.begin();
202  for (; eit != ParE_.end() ; ++eit) {
203  std::vector<double>::const_iterator sit = eit->second.begin();
204  os << "parE name=" << eit->first;
205  for (; sit != eit->second.end(); ++sit) {
206  os << " val=" << *sit << std::endl;
207  }
208  }
209  parS_type::const_iterator stit = ParS_.begin();
210  for (; stit != ParS_.end() ; ++stit) {
211  std::vector<std::string>::const_iterator sit = stit->second.begin();
212  os << "parS name=" << stit->first;
213  for (; sit != stit->second.end(); ++sit) {
214  os << " val=" << *sit << std::endl;
215  }
216  }
217 }
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:158
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:128
An exception for DDD errors.
Definition: DDException.h:23
virtual void checkTermination()
for algorithms with incr_==0 the algorithm must check whether to terminate
Definition: AlgoImpl.cc:33
void stream(std::ostream &os) const
streams some information about common parameters and the name of the algorithm
Definition: AlgoPos.cc:198
size_t numRegistered()
return number of registered implementations
Definition: AlgoPos.cc:78
int copyno() const
copy-number calculation
Definition: AlgoPos.cc:83
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:26
std::vector< AlgoImpl * > regAlgos_
registry of algorithm implementation objects
Definition: AlgoPos.h:178
void terminate()
terminates current algorithmic processing
Definition: AlgoPos.cc:134
AlgoPos(AlgoCheck *check=0)
creates an algorithm named name
Definition: AlgoPos.cc:9
void next()
update for next iteration of the algorithm, don&#39;t call it yourself!
Definition: AlgoPos.cc:97
virtual int copyno() const
copy-number calculation
Definition: AlgoImpl.cc:21
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:152
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:15
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:39
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:73
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:140
virtual DD3Vector translation()=0
subclass must calculate a translation std::vector
int end() const
Definition: AlgoPos.h:84
string s
Definition: asciidump.py:422
DD3Vector translation()
translation calculations
Definition: AlgoPos.cc:146
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