CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/Geometry/TrackerNumberingBuilder/src/TrackerMapDDDtoID.cc

Go to the documentation of this file.
00001 #include "Geometry/TrackerNumberingBuilder/interface/TrackerMapDDDtoID.h"
00002 #include "DetectorDescription/Core/interface/DDExpandedView.h"
00003 #include "DetectorDescription/Core/interface/DDFilteredView.h"
00004 #include "DataFormats/DetId/interface/DetId.h"
00005 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include<algorithm>
00008 
00009 TrackerMapDDDtoID::TrackerMapDDDtoID(const GeometricDet* iDet) 
00010 {
00011    buildAll(iDet);
00012   //
00013   // loop over all the volumes which hahe a SpecPar called specpar with value value, 
00014   // and save in the map the association nav_type<->id
00015   //
00016 }
00017 
00018 void TrackerMapDDDtoID::buildAll(const GeometricDet* iDet){
00019   edm::LogInfo("TrackerMapDDDtoID")<<" Building the TrackerMapDDDtoID map.";
00020   TrackerMapDDDtoID* me = const_cast<TrackerMapDDDtoID*>(this);
00021   me->buildAllStep2(iDet);
00022 }
00023 
00024 void TrackerMapDDDtoID::buildAllStep2(const GeometricDet* theTracker){
00025   
00026   std::vector<const GeometricDet*> allDetectors;
00027   theTracker->deepComponents(allDetectors);
00028   
00029   //
00030   // Also build a map! (for slower access)
00031   //
00032 
00033   for (unsigned int j=0; j<allDetectors.size(); j++){
00034     
00035     path2id_.insert(std::pair<nav_type,uint32_t>(allDetectors[j]->navType(),(allDetectors[j]->geographicalID())()));
00036     revpath2id_.insert(std::pair<uint32_t,nav_type>((allDetectors[j]->geographicalID())(),allDetectors[j]->navType()));
00037     navVec.push_back(allDetectors[j]->navType());
00038   }
00039   edm::LogInfo("TrackerMapDDDtoID")<<"Created TrackerMapDDDtoID; results in "<<allDetectors.size()<<" detectors numbered.";
00040 }
00041 
00042 /*
00043 unsigned int TrackerMapDDDtoID::id(const DDExpandedView & e) const
00044 {
00045   return id(e.navPos());
00046 }
00047 
00048 
00049 unsigned int TrackerMapDDDtoID::id(const DDFilteredView & f) const
00050 {
00051   return id(f.navPos());
00052 }
00053 */
00054 
00055 unsigned int TrackerMapDDDtoID::id(const nav_type & n) const
00056 {
00057   std::map<nav_type,uint32_t>::const_iterator it = path2id_.find(n);
00058   unsigned int result = 0;
00059   if (it != path2id_.end())
00060     result = it->second;
00061   return result;  
00062 }
00063 
00064 
00065 std::vector<TrackerMapDDDtoID::nav_type> const & TrackerMapDDDtoID::allNavTypes() const{
00066   return navVec;
00067 }
00068 
00069 namespace {
00070   const TrackerMapDDDtoID::nav_type nullresult;
00071 }
00072 
00073 TrackerMapDDDtoID::nav_type const & TrackerMapDDDtoID::navType(uint32_t num) const
00074 { 
00075   std::map<uint32_t,nav_type>::const_iterator it = revpath2id_.find(num);
00076   if (it != revpath2id_.end())
00077     return it->second;
00078   return nullresult;  
00079 }
00080 
00081 void TrackerMapDDDtoID::clear(){
00082   path2id_.clear();
00083   edm::LogInfo("TrackerMapDDDtoID")<<" TrackerMapDDDtoID maps deleted from memory.";
00084 }