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),w2_(cpv.graph(),cpv.root()), trans_(DDTranslation()), rot_(DDRotationMatrix()),
9  depth_(0), worldpos_(0)
10 {
11  // std::cout << "Building a DDExpandedView" << std::endl;
12  // MEC:2010-02-08 - consider the ROOT as where you want to start LOOKING at
13  // the DDD, and worldpos_ as the "real" root node of the graph. MOVE all this
14  // logic to DDCompactView. This should really be just the traverser...
15  DDRotation::StoreT::instance().setReadOnly(false);
17  DDRotation::StoreT::instance().setReadOnly(true);
18 
19  walker_ = &w2_;
20 
21  // std::cout << "Walker: current.first=" << (*walker_).current().first << std::endl;
22  // std::cout << "Walker: current.second=" << (*walker_).current().second << std::endl;
23 
24  DDPosData * pd((*walker_).current().second);
25  if (!pd)
26  pd = worldpos_;
27  DDExpandedNode expn((*walker_).current().first,
28  pd,
29  trans_,
30  rot_,
31  0);
32 
33  // starting point for position calculations, == root of expanded view
34  history_.push_back(expn);
35 }
36 
37 
39 
40 
42 {
43  return history_.back().logp_;
44 }
45 
46 
48 {
49  return history_.back().trans_;
50 }
51 
52 
54 {
55  return history_.back().rot_;
56 }
57 
58 
60 {
61  return history_;
62 }
63 
64 
66 {
67  return depth_;
68 }
69 
70 
72 {
73  return history_.back().copyno();
74 }
75 
76 
77 namespace {
78 
79  struct Counter {
80  int same;
81  int diff;
82  ~Counter() {
83  }
84 
85  };
86 
87  inline Counter & counter() {
88  static Counter local;
89  return local;
90  }
91 
92 
93 }
94 
95 
102 {
103  bool result(false);
104  if (scope_.size() && history_.back() == scope_.back()) {
105  ; // no-next-sibling, if current node is the root of the scope!
106  }
107  else {
108  if ((*walker_).nextSibling()) {
109  DDExpandedNode & expn(history_.back()); // back of history_ is always current node
110  DDCompactView::walker_type::value_type curr = (*walker_).current();
111  DDPosData const * posdOld = expn.posd_;
112  expn.logp_=curr.first;
113  expn.posd_=curr.second;
114 
115  DDGeoHistory::size_type hsize = history_.size();
116 
117 
118  if (hsize>1) {
119  const DDExpandedNode & expnBefore(history_[hsize-2]);
120 
121  // T = T1 + INV[R1] * T2
122  expn.trans_ = expnBefore.trans_ + (expnBefore.rot_ * expn.posd_->trans_);
123 
124  // R = R1*INV[R2]
125  // VI in principle we can do this
126  if ( !(expn.posd_->rot()==posdOld->rot()) ) {
127  expn.rot_ = expnBefore.rot_ * expn.posd_->rot();//.inverse();
128  ++counter().diff;
129  }else ++counter().same;
130 
131  }
132  else {
133  expn.trans_ = expn.posd_->trans_;
134  expn.rot_ = expn.posd_->rot();//.inverse();
135  }
136  ++expn.siblingno_;
137  result = true;
138  }
139  }
140  return result;
141 }
142 
143 
149 {
150  bool result(false);
151  bool depthNotReached(true);
152 
153  // Check for the depth within the scope ...
154  if (depth_) {
155  if ( (history_.size()-scope_.size())==depth_ ) {
156  depthNotReached=false;
157  }
158  }
159  if (depthNotReached) {
160  if ((*walker_).firstChild()) {
161  DDExpandedNode & expnBefore(history_.back());
162  DDCompactView::walker_type::value_type curr = (*walker_).current();
163 
164  DDPosData * newPosd = curr.second;
165 
166  // T = ... (see nextSiblinig())
167  DDTranslation newTrans = expnBefore.trans_ + expnBefore.rot_ * newPosd->trans_;
168 
169  // R = ... (see nextSibling())
170  DDRotationMatrix newRot = expnBefore.rot_ * newPosd->rot();//.inverse();
171 
172  // create a new Expanded node and push it to the history ...
173  DDExpandedNode expn(curr.first, curr.second,
174  newTrans, newRot, 0);
175 
176  history_.push_back(expn);
177 
178  /* debug output
179  edm::LogInfo("DDExpandedView") << "FIRSTCHILD: name=" << expn.logicalPart().ddname()
180  << " rot=";
181 
182  if (expn.absRotation().isIdentity())
183  edm::LogInfo("DDExpandedView") << "[none]" << std::endl;
184  else
185  edm::LogInfo("DDExpandedView") << expn.absRotation() << std::endl;
186  */
187 
188  result = true;
189  } // if firstChild
190  } // if depthNotReached
191  return result;
192 }
193 
194 
200 {
201  bool result(false);
202  bool scopeRoot(false);
203 
204  // check for a scope
205  if (scope_.size()) {
206  if (scope_.back() == history_.back()) {
207  // the current node is the root of the scope
208  scopeRoot = true;
209  }
210  }
211 
212  if (!scopeRoot) {
213  if ((*walker_).parent()) {
214  history_.pop_back();
215  result = true;
216  }
217  }
218 
219  return result;
220 }
221 
222 /*
223 bool DDExpandedView::hasChildren() const
224 {
225  bool result = false;
226 
227  return result;
228 }
229 */
230 
231 // same implementation as in GraphWalker !
247 {
248  bool res(false);
249  if(firstChild())
250  res=true;
251  else if(nextSibling())
252  res=true;
253  else {
254  while(parent()) {
255  //DCOUT('C', "pa=" << logicalPart() );
256  if(nextSibling()) {
257  //DCOUT('C', "ns=" << logicalPart() );
258  res=true;
259  break;
260  }
261  }
262  //DCOUT('C', current().first << " "<< current().second );
263  }
264  return res;
265 }
266 
267 
270 {
271  bool res(false);
272  return res;
273 }
274 
275 
276 void dump(const DDGeoHistory & h)
277 {
278  DDGeoHistory::const_iterator it = h.begin();
279  edm::LogInfo("DDExpandedView") << "--GeoHistory-Dump--[" << std::endl;
280  int i=0;
281  for (; it != h.end(); ++it) {
282  edm::LogInfo("DDExpandedView") << " " << i << it->logicalPart() << std::endl;
283  /*
284  << " " << it->logicalPart().material() << std::endl
285  << " " << it->logicalPart().solid() << std::endl;
286  */
287  ++i;
288  }
289  edm::LogInfo("DDExpandedView") << "]---------" << std::endl;
290 }
291 
300 std::vector< const DDsvalues_type *> DDExpandedView::specifics() const
301 {
302  // backward compatible
303  std::vector<const DDsvalues_type * > result;
304  specificsV(result);
305  return result;
306 }
307 
308 void DDExpandedView::specificsV(std::vector<const DDsvalues_type * > & result) const
309 {
310  unsigned int i(0);
311  //edm::LogInfo("DDExpandedView") << " in ::specifics " << std::endl;
312  const std::vector<std::pair<DDPartSelection*, DDsvalues_type*> > & specs = logicalPart().attachedSpecifics();
313  if (specs.size()) { // do only if SpecPar has data defined
314  //edm::LogInfo("DDExpandedView") << " found: specifics size=" << specs.size() << std::endl;
315  result.reserve(specs.size());
316  for (; i<specs.size(); ++i) {
317  const std::pair<DDPartSelection*,DDsvalues_type*>& sp = specs[i];
318  // a part selection
319  const DDPartSelection & psel = *(sp.first);
320  //edm::LogInfo("DDExpandedView") << " partsel.size = " << psel.size() << std::endl;
321  //edm::LogInfo("DDExpandedView") << " geohistory = " << geoHistory() << std::endl;
322  const DDGeoHistory & hist = geoHistory();
323 
324  //dump(hist);
325  //dump(psel);
326 
327  if (DDCompareEqual(hist, psel)()) //edm::LogInfo("DDExpandedView") << "MATCH!!!!" << std::endl;
328  result.push_back( sp.second );
329  }
330  }
331 }
332 
333 
335  DDsvalues_type merged;
336  mergedSpecificsV(merged);
337  return merged;
338 }
339 
340 
342 {
343 
344  merged.clear();
345  const std::vector<std::pair<DDPartSelection*, DDsvalues_type*> > & specs = logicalPart().attachedSpecifics();
346  if (specs.empty()) return;
347  const DDGeoHistory & hist = geoHistory();
348  for (size_t i=0; i<specs.size(); ++i) {
349  const std::pair<DDPartSelection*,DDsvalues_type*>& sp = specs[i];
350  const DDPartSelection & psel = *(sp.first);
351  if (DDCompareEqual(hist, psel)())
352  merge(merged,*sp.second);
353  }
354  // std::sort(merged.begin(),merged.end());
355 }
356 
357 
365 {
366  return scope_;
367 }
368 
370 {
371  scope_.clear();
372  depth_=0;
373 }
374 
375 
377 {
378  clearScope();
379  while(parent())
380  ;
381 }
382 
383 
394 bool DDExpandedView::setScope(const DDGeoHistory & sc, int depth)
395 {
396  bool result(false);
397 
398  DDGeoHistory buf = scope_; // save current scope
399  scope_.clear(); // sets scope to global (full) scope
400 
401  while (parent()) ; // move up to the root of the expanded-view
402 
403  if (descend(sc)) { // try to move down the given scope-history ...
404  scope_ = sc;
405  depth_ = depth;
406  result = true;
407  }
408  else {
409  scope_ = buf;
410  }
411 
412  return result;
413 }
414 
415 
423 {
424  bool result = true;
425  int tempD = depth_;
426  //DCOUT('G', " goto- target= " << pos );
427  DDGeoHistory tempScope = scope_;
428  reset();
429  DDGeoHistory::size_type s = pos.size();
430  for( DDGeoHistory::size_type j=1; j<s; ++j) {
431  if (! firstChild()) {
432  result = false;
433  //edm::LogError("DDExpandedView") << " ERROR! , wrong usage of DDExpandedView::goTo! " << std::endl;
434  //exit(1);
435  break;
436  }
437  int i=0;
438  for (; i<pos[j].siblingno(); ++i) {
439  if (! nextSibling()) {
440  //edm::LogError("DDExpandedView") << " ERROR! , wrong usage of DDExpandedView::goTo! " << std::endl;
441  result = false;
442  }
443  }
444  }
445 
446  if (!result) {
447  reset();
448  setScope(tempScope, tempD);
449  }
450  else {
451  scope_ = tempScope;
452  depth_ = tempD;
453  }
454 
455  //DCOUT('G', " goto-result = " << history_ );
456  return result;
457 }
458 
461 {
462  DDGeoHistory::size_type mxx = sc.size();
463  DDGeoHistory::size_type cur = 0;
464  bool result(false);
465 
466  /* algo: compare currerent node in expanded-view with current-node in sc
467  if matching:
468  (A)go to first child in expanded-view, go one level deeper in sc
469  iterate over all children in expanded-view until one of them
470  matches the current node in sc.
471  if no one matches, return false
472  else continue at (A)
473  else return false
474  */
475  const DDExpandedNode & curNode = history_.back();
476 
477  if (sc.size()) {
478  //DCOUT('x', "curN=" << curNode.logicalPart() << " scope[0]=" << sc[cur].logicalPart() );
479  if (curNode==sc[cur]) {
480  bool res(false);
481  while(cur+1 < mxx && firstChild()) {
482  ++cur;
483  //DCOUT('x', "fc-curN=" << history_.back().logicalPart() << " scope[x]=" << sc[cur].logicalPart() );
484  if (!(history_.back()==sc[cur])) {
485  while(nextSibling()) {
486  //DCOUT('x', "ns-curN=" << history_.back().logicalPart() << " scope[x]=" << sc[cur].logicalPart() );
487  if (history_.back()==sc[cur]) {
488  res=true;
489  break;
490  }
491  }
492  }
493  else {
494  res=true;
495  }
496  if (res==false)
497  break;
498  }
499  result = res;
500  }
501  }
502  return result;
503 }
504 
505 
506 bool DDExpandedView::goTo(const nav_type & newpos) {
507  return goTo(&newpos.front(),newpos.size());
508 
509 }
510 
512  return goTo(newpos.first,newpos.second);
513 }
514 
515 bool DDExpandedView::goTo(int const * newpos, size_t sz)
516 {
517  bool result(false);
518 
519  // save the current position
520  //nav_type savedPos = navPos();
521  DDGeoHistory savedPos = history_;
522 
523  // reset to root node
524  //FIXME: reset to root of scope!!
525  reset();
526 
527  // try to navigate down to the newpos
528  for (size_t i = 1; i < sz; ++i) {
529  result = firstChild();
530  if (result) {
531  int pos = newpos[i];
532  for(int k=0; k<pos; ++k) {
533  result = nextSibling();
534  }
535  }
536  else {
537  break;
538  }
539  }
540 
541  if (!result) {
542  goToHistory(savedPos);
543  }
544  return result;
545 }
546 
547 
549 {
552  nav_type pos(j);
553 
554  for (;i<j;++i)
555  pos[i] = history_[i].siblingno();
556 
557  return pos;
558 }
559 
561 {
563  DDGeoHistory::size_type sz = history_.size();
564  nav_type result(sz);
565 
566  for (; it < sz; ++it) {
567  result[it] = history_[it].copyno();
568  }
569  return result;
570 }
571 
572 std::ostream & printNavType(std::ostream & os, int const * n, size_t sz){
573  os << '(' ;
574  for (int const * it=n; it != n+sz; ++it) {
575  os << *it << ',';
576  }
577  os << ')';
578  return os;
579 }
580 
581 
582 
583 //THIS IS WRONG, THIS IS WRONG, THIS IS WRONG (not functional wrong but in any other case!)
584 //THIS IS WRONG, THIS IS STUPID, i bin a depp ...
585 /*
586 void doit(DDGeoHistory& h) {
587  DDRotationMatrix m1, m2, m3;
588  DDGeoHistory::size_type s(h.size());
589  std::vector<DDRotationMatrix> rotVec(s);
590  std::vector<DDTranslation> transVec(s);
591 
592  DDGeoHistory::size_type c(s);
593  for (int i=0; i<s; ++i) {
594  rotVec[i] = h[i].posd_->rot_;
595  transVec[i] = h[i].posd_->trans_;
596  }
597 
598  if (s>1) {
599  for (int i=1; i<s; ++i) {
600  rotVec[i] = rotVec[i-1]*rotVec[i];
601  //h[i].rot_ = h[i-1].posd_->rot_ * h[i].posd_->rot_;
602  }
603 
604  for (int i=1; i<s; ++i)
605  transVec[i] = transVec[i-1] + rotVec[i-1]*transVec[i];
606  //h[i].trans_ = h[i-1].trans_ + h[i-1].rot_ * h[i]
607  }
608  h[s-1].trans_ = transVec[s-1];
609  h[s-1].rot_ = rotVec[s-1];
610 
611 }
612 */
613 
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.
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
DDRotationMatrix rot_
const std::vector< std::pair< DDPartSelection *, DDsvalues_type * > > & attachedSpecifics(void) const
static value_type & instance()
DDTranslation trans_
void specificsV(std::vector< const DDsvalues_type * > &vc) const
graph< DDLogicalPart, DDPosData * >::value_type value_type
Definition: graphwalker.h:38
DDPosData * worldpos_
???
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.
unsigned int(* Counter)(align::ID, const TrackerTopology *)
Definition: Counters.h:27
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
int k[5][pyjets_maxn]
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 ...
static std::atomic< unsigned int > counter
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 DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
DDGeoHistory scope_
scope of the expanded view
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