CMS 3D CMS Logo

DDNumberingScheme.cc
Go to the documentation of this file.
2 
3 #include <ostream>
4 #include <utility>
5 
9 
11 
13 {
14  // extremely memory consuming & slow.
15 
16  /* - assign a node-number (from 0, ...) to every node in the view
17  - save the node-number in a map, key is the stack of sibling-numbers of the node
18  -> enables node to id calculation (slow O(log(max. node-number))).
19  - save in a std::vector the stack of sibling-numbers; index in the std::vector is the
20  assigned node number -> enables id to node calculation (fast)
21  */
22  typedef std::map<nav_type,int>::iterator m_it;
23 
24  DDExpandedView e = ex;
25  e.reset();
26  bool go = true;
27  int count = 0;
28  while (go) {
29  std::pair<m_it,bool> res = path2id_.insert(std::make_pair(e.navPos(),count));
30  id2path_.emplace_back(res.first);
31  ++count;
32  go = e.next();
33  }
34 }
35 
36 
38 {
39  // very memory consuming & slow, depending on the amount of nodes
40  // selected by the FilteredView; same algorithm then in ctor above
41  typedef std::map<nav_type,int>::iterator m_it;
42 
43  DDFilteredView f = fv;
44  f.reset();
45  bool go = true;
46  int count = 0;
47  while (go) {
48  std::pair<m_it,bool> res = path2id_.insert(std::make_pair(f.navPos(),count));
49  id2path_.emplace_back(res.first);
50  ++count;
51  go = f.next();
52  }
53 }
54 
55 
57 { }
58 
59 
61 {
62  return id(e.navPos());
63 }
64 
65 
67 {
68  return id(f.navPos());
69 }
70 
71 
73 {
74  std::map<nav_type,int>::const_iterator it = path2id_.find(n);
75  int result = -1;
76  if (it != path2id_.end())
77  result = it->second;
78  return result;
79 }
80 
81 
83 {
84  return view.goTo(idToNavType(id));
85 }
86 
87 
89 {
90  edm::LogError("DDNumberingScheme") << "DDDefaultNumberingScheme::node(int,DDFilteredView&) NOT IMPLEMENTED!"
91  << std::endl;
92  return view.goTo(idToNavType(id));
93 }
94 
95 
97 {
100  if ( (id>=(int)id2path_.size()) || ( id < 0) )
101  ;
102 
103  else {
104  std::map<nav_type,int>::iterator it = id2path_[pos];
105  result = it->first;
106  }
107  return result;
108 }
109 
bool node(int id, DDExpandedView &view) const override
calculate the node given an id
bool next()
set current node to the next node in the expanded tree
DDNumberingScheme::nav_type idToNavType(int id) const
virtual int id(const DDExpandedView &) const =0
calculate the id of a given node
virtual ~DDNumberingScheme()
nav_type navPos() const
return the stack of sibling numbers
uint16_t size_type
Definition: Electron.h:6
std::vector< int > nav_type
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
bool goTo(const nav_type &)
bool next()
set current node to the next node in the filtered tree
double f[11][100]
DDNumberingScheme::nav_type nav_type
void reset()
true, if a call to firstChild() would succeed (current node has at least one child) ...
bool goTo(const nav_type &)
transversed the DDExpandedView according to the given stack of sibling numbers
int id(const DDExpandedView &) const override
calculate the id of a given node
void reset()
clears the scope and sets the filtered view to its root-node
Provides an exploded view of the detector (tree-view)
DDDefaultNumberingScheme(const DDExpandedView &e)