CMS 3D CMS Logo

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;
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 
238  DDsvalues_type merged;
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 }
DDExpandedView::depth_
unsigned int depth_
depth of the scope, 0==unrestricted depth
Definition: DDExpandedView.h:143
DDExpandedView::nextB
bool nextB()
broad search order of next()
Definition: DDExpandedView.cc:193
DDExpandedView::copyNumbers
nav_type copyNumbers() const
return the stack of copy numbers
Definition: DDExpandedView.cc:425
printNavType
std::string printNavType(int const *n, size_t sz)
Definition: DDExpandedView.cc:436
DDPosData::trans_
DDTranslation trans_
Definition: DDPosData.h:39
mps_fire.i
i
Definition: mps_fire.py:428
DDGeoHistory
std::vector< DDExpandedNode > DDGeoHistory
Geometrical 'path' of the current node up to the root-node.
Definition: DDExpandedNode.h:82
DDExpandedView::scope
const DDGeoHistory & scope() const
The scope of the expanded-view.
Definition: DDExpandedView.cc:261
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
DDExpandedView::rotation
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
Definition: DDExpandedView.cc:48
DDExpandedView::firstChild
bool firstChild()
set the current node to the first child ...
Definition: DDExpandedView.cc:101
DDExpandedView::specifics
std::vector< const DDsvalues_type * > specifics() const
User specific data attached to the current node.
Definition: DDExpandedView.cc:215
DDPosData::trans
const DDTranslation & trans() const
Definition: DDPosData.h:28
DDExpandedView::mergedSpecifics
DDsvalues_type mergedSpecifics() const
Definition: DDExpandedView.cc:237
DDExpandedView::mergedSpecificsV
void mergedSpecificsV(DDsvalues_type &res) const
Definition: DDExpandedView.cc:243
DDExpandedView::nav_type
std::vector< int > nav_type
std::vector of sibling numbers
Definition: DDExpandedView.h:48
DDExpandedView::rot_
const DDRotationMatrix rot_
Definition: DDExpandedView.h:140
DDExpandedNode::rot_
DDRotationMatrix rot_
Definition: DDExpandedNode.h:48
pos
Definition: PixelAliasList.h:18
HistogramManager_cfi.specs
specs
Definition: HistogramManager_cfi.py:83
DDExpandedView.h
DDExpandedView::next
bool next()
set current node to the next node in the expanded tree
Definition: DDExpandedView.cc:175
DDPartSelection
Definition: DDPartSelection.h:37
DDExpandedView::scope_
DDGeoHistory scope_
scope of the expanded view
Definition: DDExpandedView.h:142
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
DDExpandedView::DDExpandedView
DDExpandedView(const DDCompactView &)
Constructs an expanded-view based on the compact-view.
Definition: DDExpandedView.cc:21
DDExpandedView::setScope
bool setScope(const DDGeoHistory &hist, int depth=0)
sets the scope of the expanded view
Definition: DDExpandedView.cc:284
DDExpandedView::goToHistory
bool goToHistory(const DDGeoHistory &sc)
Definition: DDExpandedView.cc:310
DDExpandedView::NavRange
std::pair< int const *, size_t > NavRange
Definition: DDExpandedView.h:49
DDExpandedView::copyno
int copyno() const
Copy number associated with the current node.
Definition: DDExpandedView.cc:54
DDExpandedNode::trans_
DDTranslation trans_
Definition: DDExpandedNode.h:47
alignCSCRings.s
s
Definition: alignCSCRings.py:92
DDExpandedView::nextSibling
bool nextSibling()
set the current node to the next sibling ...
Definition: DDExpandedView.cc:61
trigger::size_type
uint16_t size_type
Definition: TriggerTypeDefs.h:18
DDExpandedView::specificsV
void specificsV(std::vector< const DDsvalues_type * > &vc) const
Definition: DDExpandedView.cc:222
DDTranslation
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
DDCompactView
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
DDExpandedView::name
const std::string & name() const
The name of the logical-part of the current node in the expanded-view.
Definition: DDExpandedView.cc:44
math::GraphWalker< DDLogicalPart, DDPosData * >::value_type
typename math::Graph< DDLogicalPart, DDPosData * >::value_type value_type
Definition: GraphWalker.h:28
DDExpandedView::w2_
WalkerType w2_
Definition: DDExpandedView.h:138
dqmdumpme.k
k
Definition: dqmdumpme.py:60
DDPosData.h
LEDCalibrationChannels.depth
depth
Definition: LEDCalibrationChannels.py:65
DDPosData
Relative position of a child-volume inside a parent-volume.
Definition: DDPosData.h:13
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
DDExpandedView::goTo
bool goTo(const nav_type &)
transversed the DDExpandedView according to the given stack of sibling numbers
Definition: DDExpandedView.cc:381
DDExpandedView::clearScope
void clearScope()
clears the scope; the full tree is available, depth=0
Definition: DDExpandedView.cc:263
DDComparator.h
GraphWalker.h
DDExpandedView::worldpos_
const DDPosData * worldpos_
???
Definition: DDExpandedView.h:144
dump
void dump(const DDGeoHistory &history)
Definition: DDExpandedView.cc:198
gpuVertexFinder::hist
__shared__ Hist hist
Definition: gpuClusterTracksDBSCAN.h:48
DDLogicalPart
A DDLogicalPart aggregates information concerning material, solid and sensitveness ....
Definition: DDLogicalPart.h:93
DDExpandedView::~DDExpandedView
virtual ~DDExpandedView()
Definition: DDExpandedView.cc:40
root
Definition: RooFitFunction.h:10
DDCompareEqual
compares a given geometrical-history whether it corresponds to the given part-selector
Definition: DDComparator.h:15
DDExpandedView::reset
void reset()
true, if a call to firstChild() would succeed (current node has at least one child)
Definition: DDExpandedView.cc:268
DDLogicalPart.h
res
Definition: Electron.h:6
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
DDExpandedView::geoHistory
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
Definition: DDExpandedView.cc:50
DDPosData::rot
const DDRotationMatrix & rot() const
Definition: DDPosData.h:31
Graph.h
DDRotationMatrix
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
Definition: DDRotationMatrix.h:8
DDExpandedView::walker_
WalkerType * walker_
the tricky walker
Definition: DDExpandedView.h:137
DDExpandedNode
represents one node in the DDExpandedView
Definition: DDExpandedNode.h:16
DDExpandedView::history_
DDGeoHistory history_
std::vector of DDExpandedNode
Definition: DDExpandedView.h:141
DDLogicalPart::attachedSpecifics
const std::vector< std::pair< const DDPartSelection *, const DDsvalues_type * > > & attachedSpecifics(void) const
Definition: DDLogicalPart.cc:340
DDExpandedView::navPos
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView
Definition: DDExpandedView.cc:414
DDExpandedView::logicalPart
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the expanded-view.
Definition: DDExpandedView.cc:42
mps_fire.result
result
Definition: mps_fire.py:311
DDExpandedView::descend
bool descend(const DDGeoHistory &sc)
Definition: DDExpandedView.cc:341
DDExpandedView::translation
const DDTranslation & translation() const
The absolute translation of the current node.
Definition: DDExpandedView.cc:46
DDExpandedView::depth
int depth() const
depth of the scope. 0 means unrestricted depth.
Definition: DDExpandedView.cc:52
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
MatrixUtil.merge
def merge(dictlist, TELL=False)
Definition: MatrixUtil.py:201
DDExpandedView::parent
bool parent()
set the current node to the parent node ...
Definition: DDExpandedView.cc:138
DDsvalues_type
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
DDExpandedView::trans_
const DDTranslation trans_
Definition: DDExpandedView.h:139