CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDExpandedView.cc
Go to the documentation of this file.
3 
8  : walker_(0),
9  w2_(cpv.graph(),cpv.root()),
10  trans_( DDTranslation()),
11  rot_( DDRotationMatrix()),
12  depth_( 0 ),
13  worldpos_( cpv.worldPosition())
14 {
15  walker_ = &w2_;
16 
17  const DDPosData * pd((*walker_).current().second);
18  if (!pd)
19  pd = worldpos_;
20  DDExpandedNode expn((*walker_).current().first,
21  pd,
22  trans_,
23  rot_,
24  0);
25 
26  // starting point for position calculations, == root of expanded view
27  history_.push_back(expn);
28 }
29 
31 
33 {
34  return history_.back().logp_;
35 }
36 
37 
39 {
40  return history_.back().trans_;
41 }
42 
43 
45 {
46  return history_.back().rot_;
47 }
48 
49 
51 {
52  return history_;
53 }
54 
55 
57 {
58  return depth_;
59 }
60 
61 
63 {
64  return history_.back().copyno();
65 }
66 
73 {
74  bool result(false);
75  if (scope_.size() && history_.back() == scope_.back()) {
76  ; // no-next-sibling, if current node is the root of the scope!
77  }
78  else {
79  if ((*walker_).nextSibling()) {
80  DDExpandedNode & expn(history_.back()); // back of history_ is always current node
81  DDCompactView::walker_type::value_type curr = (*walker_).current();
82  DDPosData const * posdOld = expn.posd_;
83  expn.logp_=curr.first;
84  expn.posd_=curr.second;
85 
86  DDGeoHistory::size_type hsize = history_.size();
87 
88 
89  if (hsize>1) {
90  const DDExpandedNode & expnBefore(history_[hsize-2]);
91 
92  // T = T1 + INV[R1] * T2
93  expn.trans_ = expnBefore.trans_ + (expnBefore.rot_ * expn.posd_->trans_);
94 
95  // R = R1*INV[R2]
96  // VI in principle we can do this
97  if ( !(expn.posd_->rot()==posdOld->rot()) ) {
98  expn.rot_ = expnBefore.rot_ * expn.posd_->rot();//.inverse();
99  }
100  }
101  else {
102  expn.trans_ = expn.posd_->trans_;
103  expn.rot_ = expn.posd_->rot();//.inverse();
104  }
105  ++expn.siblingno_;
106  result = true;
107  }
108  }
109  return result;
110 }
111 
112 
118 {
119  bool result(false);
120  bool depthNotReached(true);
121 
122  // Check for the depth within the scope ...
123  if (depth_) {
124  if ( (history_.size()-scope_.size())==depth_ ) {
125  depthNotReached=false;
126  }
127  }
128  if (depthNotReached) {
129  if ((*walker_).firstChild()) {
130  DDExpandedNode & expnBefore(history_.back());
131  DDCompactView::walker_type::value_type curr = (*walker_).current();
132 
133  DDPosData * newPosd = curr.second;
134 
135  // T = ... (see nextSiblinig())
136  DDTranslation newTrans = expnBefore.trans_ + expnBefore.rot_ * newPosd->trans_;
137 
138  // R = ... (see nextSibling())
139  DDRotationMatrix newRot = expnBefore.rot_ * newPosd->rot();//.inverse();
140 
141  // create a new Expanded node and push it to the history ...
142  DDExpandedNode expn(curr.first, curr.second,
143  newTrans, newRot, 0);
144 
145  history_.push_back(expn);
146  result = true;
147  } // if firstChild
148  } // if depthNotReached
149  return result;
150 }
151 
152 
158 {
159  bool result(false);
160  bool scopeRoot(false);
161 
162  // check for a scope
163  if (scope_.size()) {
164  if (scope_.back() == history_.back()) {
165  // the current node is the root of the scope
166  scopeRoot = true;
167  }
168  }
169 
170  if (!scopeRoot) {
171  if ((*walker_).parent()) {
172  history_.pop_back();
173  result = true;
174  }
175  }
176 
177  return result;
178 }
179 
180 /*
181 bool DDExpandedView::hasChildren() const
182 {
183  bool result = false;
184 
185  return result;
186 }
187 */
188 
189 // same implementation as in GraphWalker !
205 {
206  bool res(false);
207  if(firstChild())
208  res=true;
209  else if(nextSibling())
210  res=true;
211  else {
212  while(parent()) {
213  //DCOUT('C', "pa=" << logicalPart() );
214  if(nextSibling()) {
215  //DCOUT('C', "ns=" << logicalPart() );
216  res=true;
217  break;
218  }
219  }
220  //DCOUT('C', current().first << " "<< current().second );
221  }
222  return res;
223 }
224 
225 
228 {
229  bool res(false);
230  return res;
231 }
232 
233 
234 void dump(const DDGeoHistory & h)
235 {
236  DDGeoHistory::const_iterator it = h.begin();
237  edm::LogInfo("DDExpandedView") << "--GeoHistory-Dump--[" << std::endl;
238  int i=0;
239  for (; it != h.end(); ++it) {
240  edm::LogInfo("DDExpandedView") << " " << i << it->logicalPart() << std::endl;
241  ++i;
242  }
243  edm::LogInfo("DDExpandedView") << "]---------" << std::endl;
244 }
245 
254 std::vector< const DDsvalues_type *> DDExpandedView::specifics() const
255 {
256  // backward compatible
257  std::vector<const DDsvalues_type * > result;
258  specificsV(result);
259  return result;
260 }
261 
262 void
263 DDExpandedView::specificsV(std::vector<const DDsvalues_type * > & result) const
264 {
265  unsigned int i(0);
266  const std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> > & specs = logicalPart().attachedSpecifics();
267  if( specs.size())
268  {
269  result.reserve(specs.size());
270  for (; i<specs.size(); ++i) {
271  const std::pair<const DDPartSelection*, const DDsvalues_type*>& sp = specs[i];
272  // a part selection
273  const DDPartSelection & psel = *(sp.first);
274  const DDGeoHistory & hist = geoHistory();
275 
276  if (DDCompareEqual(hist, psel)())
277  result.push_back( sp.second );
278  }
279  }
280 }
281 
283  DDsvalues_type merged;
284  mergedSpecificsV(merged);
285  return merged;
286 }
287 
289 {
290 
291  merged.clear();
292  const std::vector<std::pair<const DDPartSelection*, const DDsvalues_type*> > & specs = logicalPart().attachedSpecifics();
293  if (specs.empty()) return;
294  const DDGeoHistory & hist = geoHistory();
295  for (size_t i=0; i<specs.size(); ++i) {
296  const std::pair<const DDPartSelection*, const DDsvalues_type*>& sp = specs[i];
297  const DDPartSelection & psel = *(sp.first);
298  if (DDCompareEqual(hist, psel)())
299  merge(merged,*sp.second);
300  }
301 }
302 
310 {
311  return scope_;
312 }
313 
315 {
316  scope_.clear();
317  depth_=0;
318 }
319 
321 {
322  clearScope();
323  while(parent())
324  ;
325 }
326 
327 
339 {
340  bool result(false);
341 
342  DDGeoHistory buf = scope_; // save current scope
343  scope_.clear(); // sets scope to global (full) scope
344 
345  while (parent()) ; // move up to the root of the expanded-view
346 
347  if (descend(sc)) { // try to move down the given scope-history ...
348  scope_ = sc;
349  depth_ = depth;
350  result = true;
351  }
352  else {
353  scope_ = buf;
354  }
355 
356  return result;
357 }
358 
359 
367 {
368  bool result = true;
369  int tempD = depth_;
370  //DCOUT('G', " goto- target= " << pos );
371  DDGeoHistory tempScope = scope_;
372  reset();
373  DDGeoHistory::size_type s = pos.size();
374  for( DDGeoHistory::size_type j=1; j<s; ++j) {
375  if (! firstChild()) {
376  result = false;
377  //edm::LogError("DDExpandedView") << " ERROR! , wrong usage of DDExpandedView::goTo! " << std::endl;
378  //exit(1);
379  break;
380  }
381  int i=0;
382  for (; i<pos[j].siblingno(); ++i) {
383  if (! nextSibling()) {
384  //edm::LogError("DDExpandedView") << " ERROR! , wrong usage of DDExpandedView::goTo! " << std::endl;
385  result = false;
386  }
387  }
388  }
389 
390  if (!result) {
391  reset();
392  setScope(tempScope, tempD);
393  }
394  else {
395  scope_ = tempScope;
396  depth_ = tempD;
397  }
398 
399  //DCOUT('G', " goto-result = " << history_ );
400  return result;
401 }
402 
405 {
406  DDGeoHistory::size_type mxx = sc.size();
407  DDGeoHistory::size_type cur = 0;
408  bool result(false);
409 
410  /* algo: compare currerent node in expanded-view with current-node in sc
411  if matching:
412  (A)go to first child in expanded-view, go one level deeper in sc
413  iterate over all children in expanded-view until one of them
414  matches the current node in sc.
415  if no one matches, return false
416  else continue at (A)
417  else return false
418  */
419  const DDExpandedNode & curNode = history_.back();
420 
421  if (sc.size()) {
422  //DCOUT('x', "curN=" << curNode.logicalPart() << " scope[0]=" << sc[cur].logicalPart() );
423  if (curNode==sc[cur]) {
424  bool res(false);
425  while(cur+1 < mxx && firstChild()) {
426  ++cur;
427  //DCOUT('x', "fc-curN=" << history_.back().logicalPart() << " scope[x]=" << sc[cur].logicalPart() );
428  if (!(history_.back()==sc[cur])) {
429  while(nextSibling()) {
430  //DCOUT('x', "ns-curN=" << history_.back().logicalPart() << " scope[x]=" << sc[cur].logicalPart() );
431  if (history_.back()==sc[cur]) {
432  res=true;
433  break;
434  }
435  }
436  }
437  else {
438  res=true;
439  }
440  if (res==false)
441  break;
442  }
443  result = res;
444  }
445  }
446  return result;
447 }
448 
449 
450 bool DDExpandedView::goTo(const nav_type & newpos) {
451  return goTo(&newpos.front(),newpos.size());
452 
453 }
454 
456  return goTo(newpos.first,newpos.second);
457 }
458 
459 bool DDExpandedView::goTo(int const * newpos, size_t sz)
460 {
461  bool result(false);
462 
463  // save the current position
464  //nav_type savedPos = navPos();
465  DDGeoHistory savedPos = history_;
466 
467  // reset to root node
468  //FIXME: reset to root of scope!!
469  reset();
470 
471  // try to navigate down to the newpos
472  for (size_t i = 1; i < sz; ++i) {
473  result = firstChild();
474  if (result) {
475  int pos = newpos[i];
476  for(int k=0; k<pos; ++k) {
477  result = nextSibling();
478  }
479  }
480  else {
481  break;
482  }
483  }
484 
485  if (!result) {
486  goToHistory(savedPos);
487  }
488  return result;
489 }
490 
491 
493 {
496  nav_type pos(j);
497 
498  for (;i<j;++i)
499  pos[i] = history_[i].siblingno();
500 
501  return pos;
502 }
503 
505 {
507  DDGeoHistory::size_type sz = history_.size();
508  nav_type result(sz);
509 
510  for (; it < sz; ++it) {
511  result[it] = history_[it].copyno();
512  }
513  return result;
514 }
515 
516 std::ostream & printNavType(std::ostream & os, int const * n, size_t sz){
517  os << '(' ;
518  for (int const * it=n; it != n+sz; ++it) {
519  os << *it << ',';
520  }
521  os << ')';
522  return os;
523 }
bool next()
set current node to the next node in the expanded tree
int i
Definition: DBlmapReader.cc:9
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
bool parent()
set the current node to the parent node ...
Relative position of a child-volume inside a parent-volume.
Definition: DDPosData.h:16
DDsvalues_type mergedSpecifics() const
bool descend(const DDGeoHistory &sc)
nav_type copyNumbers() const
return the stack of copy numbers
compares a given geometrical-history whether it corresponds to the given part-selector ...
Definition: DDComparator.h:13
virtual ~DDExpandedView()
std::ostream & printNavType(std::ostream &, int const *n, size_t sz)
DDGeoHistory history_
std::vector of DDExpandedNode
std::vector< const DDsvalues_type * > specifics() const
User specific data attached to the current node.
represents one node in the DDExpandedView
unsigned int depth_
depth of the scope, 0==unrestricted depth
type of data representation of DDCompactView
Definition: DDCompactView.h:77
uint16_t size_type
std::pair< int const *, size_t > NavRange
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
DDRotationMatrix rot_
DDTranslation trans_
void specificsV(std::vector< const DDsvalues_type * > &vc) const
graph< DDLogicalPart, DDPosData * >::value_type value_type
Definition: graphwalker.h:38
const DDTranslation trans_
DDExpandedView(const DDCompactView &)
Constructs an expanded-view based on the compact-view.
int depth() const
depth of the scope. 0 means unrestricted depth.
tuple result
Definition: query.py:137
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
Definition: DDsvalues.h:19
const DDRotationMatrix & rot() const
Definition: DDPosData.h:41
DDCompactView::walker_type * walker_
the tricky walker
int j
Definition: DBlmapReader.cc:9
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:88
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
DDTranslation trans_
Definition: DDPosData.h:47
bool setScope(const DDGeoHistory &hist, int depth=0)
sets the scope of the expanded view
const DDTranslation & translation() const
The absolute translation of the current node.
void clearScope()
clears the scope; the full tree is available, depth=0
std::vector< DDExpandedNode > DDGeoHistory
Geometrical &#39;path&#39; of the current node up to the root-node.
bool nextB()
broad search order of next()
Definition: adjgraph.h:12
const DDGeoHistory & scope() const
The scope of the expanded-view.
DDCompactView::walker_type w2_
void reset()
true, if a call to firstChild() would succeed (current node has at least one child) ...
int copyno() const
Copy number associated with the current node.
bool firstChild()
set the current node to the first child ...
bool nextSibling()
set the current node to the next sibling ...
const DDRotationMatrix rot_
bool goToHistory(const DDGeoHistory &sc)
bool goTo(const nav_type &)
transversed the DDExpandedView according to the given stack of sibling numbers
const DDPosData * worldpos_
???
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
DDGeoHistory scope_
scope of the expanded view
const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > & attachedSpecifics(void) const
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
void mergedSpecificsV(DDsvalues_type &res) const
std::vector< int > nav_type
std::vector of sibling numbers
string root
initialization
Definition: dbtoconf.py:70