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)
 
virtual int id (const DDExpandedView &) const
 calculate the id of a given node More...
 
virtual int id (const DDNumberingScheme::nav_type &) const
 calculate the id of a given node More...
 
virtual int id (const DDFilteredView &) const
 calculate the id of a given node More...
 
virtual bool node (int id, DDExpandedView &view) const
 calculate the node given an id More...
 
virtual bool node (int id, DDFilteredView &view) const
 calculate the node given an id More...
 
virtual ~DDDefaultNumberingScheme ()
 
- 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 14 of file DDNumberingScheme.cc.

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

15 {
16  // extremely memory consuming & slow.
17 
18  /* - assign a node-number (from 0, ...) to every node in the view
19  - save the node-number in a map, key is the stack of sibling-numbers of the node
20  -> enables node to id calculation (slow O(log(max. node-number))).
21  - save in a std::vector the stack of sibling-numbers; index in the std::vector is the
22  assigned node number -> enables id to node calculation (fast)
23  */
24  typedef std::map<nav_type,int>::iterator m_it;
25 
26  DDExpandedView e = ex;
27  e.reset();
28  bool go = true;
29  int count = 0;
30  while (go) {
31  std::pair<m_it,bool> res = path2id_.insert(std::make_pair(e.navPos(),count));
32  id2path_.push_back(res.first);
33  ++count;
34  go = e.next();
35  }
36 }
bool next()
set current node to the next node in the expanded tree
std::map< nav_type, int > path2id_
Definition: Electron.h:4
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 39 of file DDNumberingScheme.cc.

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

40 {
41  // very memory consuming & slow, depending on the amount of nodes
42  // selected by the FilteredView; same algorithm then in ctor above
43  typedef std::map<nav_type,int>::iterator m_it;
44 
45  DDFilteredView f = fv;
46  f.reset();
47  bool go = true;
48  int count = 0;
49  while (go) {
50  std::pair<m_it,bool> res = path2id_.insert(std::make_pair(f.navPos(),count));
51  id2path_.push_back(res.first);
52  ++count;
53  go = f.next();
54  }
55 }
std::map< nav_type, int > path2id_
nav_type navPos() const
return the stack of sibling numbers
Definition: Electron.h:4
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 ( )
virtual

Definition at line 58 of file DDNumberingScheme.cc.

59 { }

Member Function Documentation

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

calculate the id of a given node

Implements DDNumberingScheme.

Definition at line 62 of file DDNumberingScheme.cc.

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

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

calculate the id of a given node

Implements DDNumberingScheme.

Definition at line 74 of file DDNumberingScheme.cc.

References mps_fire::result.

75 {
76  std::map<nav_type,int>::const_iterator it = path2id_.find(n);
77  int result = -1;
78  if (it != path2id_.end())
79  result = it->second;
80  return result;
81 }
std::map< nav_type, int > path2id_
int DDDefaultNumberingScheme::id ( const DDFilteredView f) const
virtual

calculate the id of a given node

Implements DDNumberingScheme.

Definition at line 68 of file DDNumberingScheme.cc.

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

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

Definition at line 98 of file DDNumberingScheme.cc.

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

99 {
102  if ( (id>=(int)id2path_.size()) || ( id < 0) )
103  ;
104 
105  else {
106  std::map<nav_type,int>::iterator it = id2path_[pos];
107  result = it->first;
108  }
109  return result;
110 }
uint16_t size_type
virtual int id(const DDExpandedView &) const
calculate the id of a given node
DDNumberingScheme::nav_type nav_type
std::vector< std::map< nav_type, int >::iterator > id2path_
bool DDDefaultNumberingScheme::node ( int  id,
DDExpandedView view 
) const
virtual

calculate the node given an id

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

Implements DDNumberingScheme.

Definition at line 84 of file DDNumberingScheme.cc.

References DDExpandedView::goTo().

85 {
86  return view.goTo(idToNavType(id));
87 }
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
virtual

calculate the node given an id

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

Implements DDNumberingScheme.

Definition at line 90 of file DDNumberingScheme.cc.

References DDFilteredView::goTo().

91 {
92  edm::LogError("DDNumberingScheme") << "DDDefaultNumberingScheme::node(int,DDFilteredView&) NOT IMPLEMENTED!"
93  << std::endl;
94  return view.goTo(idToNavType(id));
95 }
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.