CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/DetectorDescription/Core/src/DDNumberingScheme.cc

Go to the documentation of this file.
00001 #include "DetectorDescription/Core/interface/DDNumberingScheme.h"
00002 #include "DetectorDescription/Core/interface/DDExpandedView.h"
00003 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00004 
00005 // Message logger.
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 
00008 DDNumberingScheme::~DDNumberingScheme() {}
00009 
00010 
00011 DDDefaultNumberingScheme::DDDefaultNumberingScheme(const DDExpandedView & ex)
00012 { 
00013   // extremely memory consuming & slow.
00014   
00015   /* - assign a node-number (from 0, ...) to every node in the view
00016      - save the node-number in a map, key is the stack of sibling-numbers of the node
00017        -> enables node to id calculation (slow O(log(max. node-number))).
00018      - save in a std::vector the stack of sibling-numbers; index in the std::vector is the
00019        assigned node number -> enables id to node calculation (fast)  
00020   */   
00021   typedef std::map<nav_type,int>::iterator m_it;
00022   
00023   DDExpandedView e = ex;
00024   e.reset();
00025   bool go = true;
00026   int count = 0;
00027   while (go) {
00028     std::pair<m_it,bool> res = path2id_.insert(std::make_pair(e.navPos(),count));
00029     id2path_.push_back(res.first);
00030     ++count;
00031     go = e.next();
00032   }
00033 }
00034 
00035 
00036 DDDefaultNumberingScheme::DDDefaultNumberingScheme(const DDFilteredView & fv)
00037 { 
00038   // very memory consuming & slow, depending on the amount of nodes
00039   // selected by the FilteredView; same algorithm then in ctor above
00040   typedef std::map<nav_type,int>::iterator m_it;
00041   
00042   DDFilteredView f = fv;
00043   f.reset();
00044   bool go = true;
00045   int count = 0;
00046   while (go) {
00047     std::pair<m_it,bool> res = path2id_.insert(std::make_pair(f.navPos(),count));
00048     id2path_.push_back(res.first);
00049     ++count;
00050     go = f.next();
00051   }
00052 }
00053 
00054 
00055 DDDefaultNumberingScheme::~DDDefaultNumberingScheme()
00056 { }
00057 
00058 
00059 int DDDefaultNumberingScheme::id(const DDExpandedView & e) const
00060 {
00061   return id(e.navPos());
00062 }
00063   
00064 
00065 int DDDefaultNumberingScheme::id(const DDFilteredView & f) const
00066 {
00067  return id(f.navPos());
00068 }
00069   
00070 
00071 int DDDefaultNumberingScheme::id(const DDDefaultNumberingScheme::nav_type & n) const
00072 {
00073   std::map<nav_type,int>::const_iterator it = path2id_.find(n);
00074   int result = -1;
00075   if (it != path2id_.end())
00076     result = it->second;
00077   return result;  
00078 }
00079 
00080 
00081 bool DDDefaultNumberingScheme::node(int id, DDExpandedView & view) const
00082 {
00083  return view.goTo(idToNavType(id));
00084 }
00085 
00086 
00087 bool DDDefaultNumberingScheme::node(int id, DDFilteredView & view) const
00088 {
00089  edm::LogError("DDNumberingScheme") << "DDDefaultNumberingScheme::node(int,DDFilteredView&) NOT IMPLEMENTED!" 
00090            << std::endl;
00091  return view.goTo(idToNavType(id));
00092 }
00093 
00094 
00095 DDNumberingScheme::nav_type DDDefaultNumberingScheme::idToNavType(int id) const
00096 { 
00097   std::vector<int>::size_type pos = id;
00098   nav_type result;
00099   if ( (id>=(int)id2path_.size()) || ( id < 0) ) 
00100     ;
00101      
00102   else {
00103     std::map<nav_type,int>::iterator it = id2path_[pos];
00104     result = it->first;
00105   }
00106   return result;
00107 }
00108