CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDExpandedView.cc
Go to the documentation of this file.
2 
3 #include <memory>
4 #include <ostream>
5 
12 #include "Math/GenVector/Cartesian3D.h"
13 #include "Math/GenVector/DisplacementVector3D.h"
14 #include "Math/GenVector/Rotation3D.h"
15 
16 class DDPartSelection;
17 
22  : walker_(nullptr),
23  w2_(cpv.graph(), cpv.root()),
24  trans_(DDTranslation()),
25  rot_(DDRotationMatrix()),
26  depth_(0),
27  worldpos_(cpv.worldPosition()),
28  cpv_(&cpv) {
29  walker_ = &w2_;
30 
31  const DDPosData* pd((*walker_).current().second);
32  if (!pd)
33  pd = worldpos_;
34  DDExpandedNode expn((*walker_).current().first, pd, trans_, rot_, 0);
35 
36  // starting point for position calculations, == root of expanded view
37  history_.emplace_back(expn);
38 }
39 
41 
42 const DDLogicalPart& DDExpandedView::logicalPart() const { return history_.back().logp_; }
43 
44 const std::string& DDExpandedView::name() const { return history_.back().logp_.ddname().name(); }
45 
46 const DDTranslation& DDExpandedView::translation() const { return history_.back().trans_; }
47 
48 const DDRotationMatrix& DDExpandedView::rotation() const { return history_.back().rot_; }
49 
51 
52 int DDExpandedView::depth() const { return depth_; }
53 
54 int DDExpandedView::copyno() const { return history_.back().copyno(); }
55 
62  bool result(false);
63  if (!scope_.empty() && history_.back() == scope_.back()) {
64  ; // no-next-sibling, if current node is the root of the scope!
65  } else {
66  if ((*walker_).nextSibling()) {
67  DDExpandedNode& expn(history_.back()); // back of history_ is always current node
68  WalkerType::value_type curr = (*walker_).current();
69  DDPosData const* posdOld = expn.posd_;
70  expn.logp_ = curr.first;
71  expn.posd_ = curr.second;
72 
73  DDGeoHistory::size_type hsize = history_.size();
74 
75  if (hsize > 1) {
76  const DDExpandedNode& expnBefore(history_[hsize - 2]);
77 
78  // T = T1 + INV[R1] * T2
79  expn.trans_ = expnBefore.trans_ + (expnBefore.rot_ * expn.posd_->trans());
80 
81  // R = R1*INV[R2]
82  // VI in principle we can do this
83  if (!(expn.posd_->rot() == posdOld->rot())) {
84  expn.rot_ = expnBefore.rot_ * expn.posd_->rot(); //.inverse();
85  }
86  } else {
87  expn.trans_ = expn.posd_->trans();
88  expn.rot_ = expn.posd_->rot(); //.inverse();
89  }
90  ++expn.siblingno_;
91  result = true;
92  }
93  }
94  return result;
95 }
96 
102  bool result(false);
103  bool depthNotReached(true);
104 
105  // Check for the depth within the scope ...
106  if (depth_) {
107  if ((history_.size() - scope_.size()) == depth_) {
108  depthNotReached = false;
109  }
110  }
111  if (depthNotReached) {
112  if ((*walker_).firstChild()) {
113  DDExpandedNode& expnBefore(history_.back());
114  WalkerType::value_type curr = (*walker_).current();
115 
116  DDPosData* newPosd = curr.second;
117 
118  // T = ... (see nextSiblinig())
119  DDTranslation newTrans = expnBefore.trans_ + expnBefore.rot_ * newPosd->trans();
120 
121  // R = ... (see nextSibling())
122  DDRotationMatrix newRot = expnBefore.rot_ * newPosd->rot(); //.inverse();
123 
124  // create a new Expanded node and push it to the history ...
125  DDExpandedNode expn(curr.first, curr.second, newTrans, newRot, 0);
126 
127  history_.emplace_back(expn);
128  result = true;
129  } // if firstChild
130  } // if depthNotReached
131  return result;
132 }
133 
139  bool result(false);
140  bool scopeRoot(false);
141 
142  // check for a scope
143  if (!scope_.empty()) {
144  if (scope_.back() == history_.back()) {
145  // the current node is the root of the scope
146  scopeRoot = true;
147  }
148  }
149 
150  if (!scopeRoot) {
151  if ((*walker_).parent()) {
152  history_.pop_back();
153  result = true;
154  }
155  }
156 
157  return result;
158 }
159 
160 // same implementation as in GraphWalker !
176  bool res(false);
177  if (firstChild())
178  res = true;
179  else if (nextSibling())
180  res = true;
181  else {
182  while (parent()) {
183  if (nextSibling()) {
184  res = true;
185  break;
186  }
187  }
188  }
189  return res;
190 }
191 
194  bool res(false);
195  return res;
196 }
197 
198 void dump(const DDGeoHistory& history) {
199  edm::LogInfo("DDExpandedView") << "--GeoHistory-Dump--[" << std::endl;
200  int i = 0;
201  for (const auto& it : history) {
202  edm::LogInfo("DDExpandedView") << " " << i << it.logicalPart() << std::endl;
203  ++i;
204  }
205  edm::LogInfo("DDExpandedView") << "]---------" << std::endl;
206 }
207 
215 std::vector<const DDsvalues_type*> DDExpandedView::specifics() const {
216  // backward compatible
217  std::vector<const DDsvalues_type*> result;
218  specificsV(result);
219  return result;
220 }
221 
222 void DDExpandedView::specificsV(std::vector<const DDsvalues_type*>& result) const {
223  const auto& specs = logicalPart().attachedSpecifics();
224  if (!specs.empty()) {
225  result.reserve(specs.size());
226  for (const auto& it : specs) {
227  // a part selection
228  const DDPartSelection& psel = *(it.first);
229  const DDGeoHistory& hist = geoHistory();
230 
231  if (DDCompareEqual(hist, psel)())
232  result.emplace_back(it.second);
233  }
234  }
235 }
236 
239  mergedSpecificsV(merged);
240  return merged;
241 }
242 
244  merged.clear();
245  const auto& specs = logicalPart().attachedSpecifics();
246  if (specs.empty())
247  return;
248  const DDGeoHistory& hist = geoHistory();
249  for (const auto& it : specs) {
250  if (DDCompareEqual(hist, *it.first)())
251  merge(merged, *it.second);
252  }
253 }
254 
261 const DDGeoHistory& DDExpandedView::scope() const { return scope_; }
262 
264  scope_.clear();
265  depth_ = 0;
266 }
267 
269  clearScope();
270  while (parent())
271  ;
272 }
273 
285  bool result(false);
286 
287  DDGeoHistory buf = scope_; // save current scope
288  scope_.clear(); // sets scope to global (full) scope
289 
290  while (parent())
291  ; // move up to the root of the expanded-view
292 
293  if (descend(sc)) { // try to move down the given scope-history ...
294  scope_ = sc;
295  depth_ = depth;
296  result = true;
297  } else {
298  scope_ = buf;
299  }
300 
301  return result;
302 }
303 
311  bool result = true;
312  int tempD = depth_;
313  DDGeoHistory tempScope = scope_;
314  reset();
315  DDGeoHistory::size_type s = pos.size();
316  for (DDGeoHistory::size_type j = 1; j < s; ++j) {
317  if (!firstChild()) {
318  result = false;
319  break;
320  }
321  int i = 0;
322  for (; i < pos[j].siblingno(); ++i) {
323  if (!nextSibling()) {
324  result = false;
325  }
326  }
327  }
328 
329  if (!result) {
330  reset();
331  setScope(tempScope, tempD);
332  } else {
333  scope_ = tempScope;
334  depth_ = tempD;
335  }
336 
337  return result;
338 }
339 
342  DDGeoHistory::size_type mxx = sc.size();
343  DDGeoHistory::size_type cur = 0;
344  bool result(false);
345 
346  /* algo: compare currerent node in expanded-view with current-node in sc
347  if matching:
348  (A)go to first child in expanded-view, go one level deeper in sc
349  iterate over all children in expanded-view until one of them
350  matches the current node in sc.
351  if no one matches, return false
352  else continue at (A)
353  else return false
354  */
355  const DDExpandedNode& curNode = history_.back();
356 
357  if (!sc.empty()) {
358  if (curNode == sc[cur]) {
359  bool res(false);
360  while (cur + 1 < mxx && firstChild()) {
361  ++cur;
362  if (!(history_.back() == sc[cur])) {
363  while (nextSibling()) {
364  if (history_.back() == sc[cur]) {
365  res = true;
366  break;
367  }
368  }
369  } else {
370  res = true;
371  }
372  if (res == false)
373  break;
374  }
375  result = res;
376  }
377  }
378  return result;
379 }
380 
381 bool DDExpandedView::goTo(const nav_type& newpos) { return goTo(&newpos.front(), newpos.size()); }
382 
383 bool DDExpandedView::goTo(NavRange newpos) { return goTo(newpos.first, newpos.second); }
384 
385 bool DDExpandedView::goTo(int const* newpos, size_t sz) {
386  bool result(false);
387 
388  // save the current position
389  DDGeoHistory savedPos = history_;
390 
391  // reset to root node
392  //FIXME: reset to root of scope!!
393  reset();
394 
395  // try to navigate down to the newpos
396  for (size_t i = 1; i < sz; ++i) {
397  result = firstChild();
398  if (result) {
399  int pos = newpos[i];
400  for (int k = 0; k < pos; ++k) {
401  result = nextSibling();
402  }
403  } else {
404  break;
405  }
406  }
407 
408  if (!result) {
409  goToHistory(savedPos);
410  }
411  return result;
412 }
413 
417  nav_type pos(j);
418 
419  for (; i < j; ++i)
420  pos[i] = history_[i].siblingno();
421 
422  return pos;
423 }
424 
427  DDGeoHistory::size_type sz = history_.size();
428  nav_type result(sz);
429 
430  for (; it < sz; ++it) {
431  result[it] = history_[it].copyno();
432  }
433  return result;
434 }
435 
436 std::string printNavType(int const* n, size_t sz) {
437  std::ostringstream oss;
438  oss << '(';
439  for (int const* it = n; it != n + sz; ++it) {
440  oss << *it << ',';
441  }
442  oss << ')';
443  return oss.str();
444 }
bool next()
set current node to the next node in the expanded tree
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:13
DDsvalues_type mergedSpecifics() const
bool descend(const DDGeoHistory &sc)
nav_type copyNumbers() const
return the stack of copy numbers
const std::string & name() const
The name of the logical-part of the current node in the expanded-view.
compares a given geometrical-history whether it corresponds to the given part-selector ...
Definition: DDComparator.h:15
virtual ~DDExpandedView()
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
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
uint16_t size_type
std::pair< int const *, size_t > NavRange
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
tuple result
Definition: mps_fire.py:311
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
DDRotationMatrix rot_
WalkerType w2_
WalkerType * walker_
the tricky walker
DDTranslation trans_
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
void specificsV(std::vector< const DDsvalues_type * > &vc) const
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
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.
std::string printNavType(int const *n, size_t sz)
const DDRotationMatrix & rot() const
Definition: DDPosData.h:31
typename math::Graph< DDLogicalPart, DDPosData * >::value_type value_type
Definition: GraphWalker.h:28
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
const DDTranslation & trans() const
Definition: DDPosData.h:28
DDTranslation trans_
Definition: DDPosData.h:39
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.
__shared__ Hist hist
bool nextB()
broad search order of next()
Log< level::Info, false > LogInfo
const DDGeoHistory & scope() const
The scope of the expanded-view.
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::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
tuple dump
OutputFilePath = cms.string(&#39;/tmp/zhokin/&#39;), OutputFileExt = cms.string(&#39;&#39;),.
void mergedSpecificsV(DDsvalues_type &res) const
std::vector< int > nav_type
std::vector of sibling numbers