CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
DDDefaultNumberingScheme Class Reference

Default numbering scheme. More...

#include <DDNumberingScheme.h>

Inheritance diagram for DDDefaultNumberingScheme:
DDNumberingScheme

Public Types

typedef DDNumberingScheme::nav_type nav_type
 
- Public Types inherited from DDNumberingScheme
typedef std::vector< int > nav_type
 

Public Member Functions

 DDDefaultNumberingScheme (const DDExpandedView &e)
 
 DDDefaultNumberingScheme (const DDFilteredView &f)
 
int id (const DDExpandedView &) const override
 calculate the id of a given node More...
 
int id (const DDNumberingScheme::nav_type &) const override
 calculate the id of a given node More...
 
int id (const DDFilteredView &) const override
 calculate the id of a given node More...
 
bool node (int id, DDExpandedView &view) const override
 calculate the node given an id More...
 
bool node (int id, DDFilteredView &view) const override
 calculate the node given an id More...
 
 ~DDDefaultNumberingScheme () override
 
- Public Member Functions inherited from DDNumberingScheme
virtual ~DDNumberingScheme ()
 

Protected Member Functions

DDNumberingScheme::nav_type idToNavType (int id) const
 

Protected Attributes

std::vector< std::map< nav_type, int >::iterator > id2path_
 
std::map< nav_type, int > path2id_
 

Detailed Description

Default numbering scheme.

implements a default - numbering scheme throws an DDException when it fails ...

Definition at line 54 of file DDNumberingScheme.h.

Member Typedef Documentation

Definition at line 57 of file DDNumberingScheme.h.

Constructor & Destructor Documentation

DDDefaultNumberingScheme::DDDefaultNumberingScheme ( const DDExpandedView e)

Definition at line 12 of file DDNumberingScheme.cc.

References KineDebug3::count(), MillePedeFileConverter_cfg::e, DDExpandedView::navPos(), DDExpandedView::next(), and DDExpandedView::reset().

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 }
bool next()
set current node to the next node in the expanded tree
std::map< nav_type, int > path2id_
Definition: Electron.h:6
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
void reset()
true, if a call to firstChild() would succeed (current node has at least one child) ...
std::vector< std::map< nav_type, int >::iterator > id2path_
Provides an exploded view of the detector (tree-view)
DDDefaultNumberingScheme::DDDefaultNumberingScheme ( const DDFilteredView f)

Definition at line 37 of file DDNumberingScheme.cc.

References KineDebug3::count(), f, DDFilteredView::navPos(), DDFilteredView::next(), and DDFilteredView::reset().

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 }
std::map< nav_type, int > path2id_
nav_type navPos() const
return the stack of sibling numbers
Definition: Electron.h:6
bool next()
set current node to the next node in the filtered tree
std::vector< std::map< nav_type, int >::iterator > id2path_
void reset()
clears the scope and sets the filtered view to its root-node
DDDefaultNumberingScheme::~DDDefaultNumberingScheme ( )
override

Definition at line 56 of file DDNumberingScheme.cc.

57 { }

Member Function Documentation

int DDDefaultNumberingScheme::id ( const DDExpandedView e) const
overridevirtual

calculate the id of a given node

Implements DDNumberingScheme.

Definition at line 60 of file DDNumberingScheme.cc.

References DDNumberingScheme::id(), and DDExpandedView::navPos().

61 {
62  return id(e.navPos());
63 }
nav_type navPos() const
return the stack of sibling numbers which indicates the current position in the DDExpandedView ...
int id(const DDExpandedView &) const override
calculate the id of a given node
int DDDefaultNumberingScheme::id ( const DDNumberingScheme::nav_type n) const
overridevirtual

calculate the id of a given node

Implements DDNumberingScheme.

Definition at line 72 of file DDNumberingScheme.cc.

References mps_fire::result.

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 }
std::map< nav_type, int > path2id_
int DDDefaultNumberingScheme::id ( const DDFilteredView f) const
overridevirtual

calculate the id of a given node

Implements DDNumberingScheme.

Definition at line 66 of file DDNumberingScheme.cc.

References DDNumberingScheme::id(), and DDFilteredView::navPos().

67 {
68  return id(f.navPos());
69 }
nav_type navPos() const
return the stack of sibling numbers
int id(const DDExpandedView &) const override
calculate the id of a given node
DDNumberingScheme::nav_type DDDefaultNumberingScheme::idToNavType ( int  id) const
protected

Definition at line 96 of file DDNumberingScheme.cc.

References DDNumberingScheme::id(), and mps_fire::result.

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 }
uint16_t size_type
DDNumberingScheme::nav_type nav_type
std::vector< std::map< nav_type, int >::iterator > id2path_
int id(const DDExpandedView &) const override
calculate the id of a given node
bool DDDefaultNumberingScheme::node ( int  id,
DDExpandedView view 
) const
overridevirtual

calculate the node given an id

returns true, if a node was found. view then corresponds to this node.

Implements DDNumberingScheme.

Definition at line 82 of file DDNumberingScheme.cc.

References DDExpandedView::goTo().

83 {
84  return view.goTo(idToNavType(id));
85 }
DDNumberingScheme::nav_type idToNavType(int id) const
bool goTo(const nav_type &)
transversed the DDExpandedView according to the given stack of sibling numbers
bool DDDefaultNumberingScheme::node ( int  id,
DDFilteredView view 
) const
overridevirtual

calculate the node given an id

returns true, if a node was found. view then corresponds to this node.

Implements DDNumberingScheme.

Definition at line 88 of file DDNumberingScheme.cc.

References DDFilteredView::goTo().

89 {
90  edm::LogError("DDNumberingScheme") << "DDDefaultNumberingScheme::node(int,DDFilteredView&) NOT IMPLEMENTED!"
91  << std::endl;
92  return view.goTo(idToNavType(id));
93 }
DDNumberingScheme::nav_type idToNavType(int id) const
bool goTo(const nav_type &)

Member Data Documentation

std::vector<std::map<nav_type,int>::iterator> DDDefaultNumberingScheme::id2path_
protected

Definition at line 88 of file DDNumberingScheme.h.

std::map<nav_type,int> DDDefaultNumberingScheme::path2id_
protected

Definition at line 87 of file DDNumberingScheme.h.