CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/CondFormats/SiPixelObjects/src/SiPixelFrameReverter.cc

Go to the documentation of this file.
00001 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameReverter.h"
00002 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCabling.h"
00003 #include "CondFormats/SiPixelObjects/interface/CablingPathToDetUnit.h"
00004 #include "CondFormats/SiPixelObjects/interface/PixelFEDCabling.h"
00005 #include "CondFormats/SiPixelObjects/interface/PixelFEDLink.h"
00006 #include "CondFormats/SiPixelObjects/interface/PixelROC.h"
00007 // DataFormats
00008 #include "DataFormats/DetId/interface/DetId.h"
00009 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00010 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00011 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00012 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00013 // Geometry
00014 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00015 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00016 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00017 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00018 
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020 
00021 #include <sstream>
00022 
00023 using namespace std;
00024 using namespace sipixelobjects;
00025 
00026 SiPixelFrameReverter::SiPixelFrameReverter(const edm::EventSetup& iSetup, const SiPixelFedCabling* map) 
00027   : map_(map)
00028 { 
00029   // Build map
00030   buildStructure(iSetup);
00031 }
00032 
00033 
00034 void SiPixelFrameReverter::buildStructure(const edm::EventSetup& iSetup) 
00035 {
00036 
00037   // Create map connecting each detId to appropriate SiPixelFrameConverter
00038 
00039   edm::ESHandle<TrackerGeometry> pDD;
00040   iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00041 
00042   for(TrackerGeometry::DetContainer::const_iterator it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00043     
00044     if(dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00045 
00046       DetId detId = (*it)->geographicalId();
00047       uint32_t id = detId();
00048       std::vector<CablingPathToDetUnit> paths = map_->pathToDetUnit(id);
00049       DetToFedMap.insert(pair< uint32_t,std::vector<CablingPathToDetUnit> > (id,paths));
00050 
00051     }
00052   }  // for(TrackerGeometry::DetContainer::const_iterator
00053 }  // end buildStructure
00054 
00055 
00056 int SiPixelFrameReverter::toCabling(
00057     sipixelobjects::ElectronicIndex & cabling, const sipixelobjects::DetectorIndex & detector) const
00058 {
00059   if(!hasDetUnit(detector.rawId)) return -1;
00060   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detector.rawId)->second;
00061   typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
00062   for  (IT it = path.begin(); it != path.end(); ++it) {
00063     const PixelROC * roc = map_->findItem(*it);
00064     if (!roc) return -3;
00065     if (! roc->rawId() == detector.rawId) return -4;
00066 
00067     GlobalPixel global = {detector.row, detector.col};
00068     LocalPixel local = roc->toLocal(global);
00069     if(!local.valid()) continue;
00070     ElectronicIndex cabIdx = {it->link, it->roc, local.dcol(), local.pxid()};
00071     cabling = cabIdx;
00072 
00073     return it->fed;
00074   }
00075   return -2;
00076 }
00077 
00078 
00079 int SiPixelFrameReverter::findFedId(uint32_t detId)
00080 {
00081   if(!hasDetUnit(detId)) return -1;
00082   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
00083   int fedId = (int) path[0].fed;
00084   return fedId;
00085 }
00086 
00087 
00088 short SiPixelFrameReverter::findLinkInFed(uint32_t detId, GlobalPixel global)
00089 {
00090   if(!hasDetUnit(detId)) return -1;
00091   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
00092   typedef  std::vector<CablingPathToDetUnit>::const_iterator IT;
00093   for  (IT it = path.begin(); it != path.end(); ++it) {
00094     const PixelROC * roc = map_->findItem(*it);
00095     if (!roc) continue;
00096 
00097     LocalPixel local = roc->toLocal(global);
00098 
00099     if(!local.valid()) continue;
00100     short link = (short) it->link;
00101     return link;
00102   }
00103   return -1;
00104 }
00105 
00106 
00107 short SiPixelFrameReverter::findRocInLink(uint32_t detId, GlobalPixel global)
00108 {
00109   if(!hasDetUnit(detId)) return -1;
00110   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
00111   typedef  std::vector<CablingPathToDetUnit>::const_iterator IT;
00112   for  (IT it = path.begin(); it != path.end(); ++it) {
00113     const PixelROC * roc = map_->findItem(*it);
00114     if (!roc) continue;
00115 
00116     LocalPixel local = roc->toLocal(global);
00117 
00118     if(!local.valid()) continue;
00119     short rocInLink = (short) roc->idInLink();
00120     return rocInLink;
00121   }
00122   return -1;
00123 }
00124 
00125 
00126 short SiPixelFrameReverter::findRocInDet(uint32_t detId, GlobalPixel global)
00127 {
00128   if(!hasDetUnit(detId)) return -1;
00129   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
00130   typedef  std::vector<CablingPathToDetUnit>::const_iterator IT;
00131   for  (IT it = path.begin(); it != path.end(); ++it) {
00132     const PixelROC * roc = map_->findItem(*it);
00133     if (!roc) continue;
00134 
00135     LocalPixel local = roc->toLocal(global);
00136 
00137     if(!local.valid()) continue;
00138     short rocInDet = (short) roc->idInDetUnit();
00139     return rocInDet;
00140   }
00141   return -1;
00142 }
00143 
00144 
00145 LocalPixel SiPixelFrameReverter::findPixelInRoc(uint32_t detId, GlobalPixel global)
00146 {
00147   if(!hasDetUnit(detId)) {
00148     LocalPixel::RocRowCol pixel = {-1,-1};
00149     LocalPixel local(pixel);
00150     return local;
00151   }
00152   std::vector<CablingPathToDetUnit> path = DetToFedMap.find(detId)->second;
00153   typedef  std::vector<CablingPathToDetUnit>::const_iterator IT;
00154   for  (IT it = path.begin(); it != path.end(); ++it) {
00155     const PixelROC * roc = map_->findItem(*it);
00156     if (!roc) continue;
00157 
00158     LocalPixel local = roc->toLocal(global);
00159 
00160     if(!local.valid()) continue;
00161     return local;
00162   }
00163   LocalPixel::RocRowCol pixel = {-1,-1};
00164   LocalPixel local(pixel);
00165   return local;
00166 }