CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CondFormats/SiPixelObjects/src/SiPixelFrameConverter.cc

Go to the documentation of this file.
00001 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
00002 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCabling.h"
00003 
00004 #include "CondFormats/SiPixelObjects/interface/PixelROC.h"
00005 #include "CondFormats/SiPixelObjects/interface/CablingPathToDetUnit.h"
00006 
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 #include <sstream>
00010 
00011 using namespace std;
00012 using namespace sipixelobjects;
00013 
00014 SiPixelFrameConverter::SiPixelFrameConverter(const SiPixelFedCabling* map, int fedId)
00015   : theFedId(fedId), theMap(map)
00016 { }
00017 
00018 
00019 bool SiPixelFrameConverter::hasDetUnit(uint32_t rawId) const
00020 {
00021   std::vector<CablingPathToDetUnit> paths = theMap->pathToDetUnit(rawId);
00022   typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
00023   for (IT it=paths.begin(); it!=paths.end();++it) {
00024     if(it->fed==static_cast<unsigned int>(theFedId)) return true;
00025   }
00026   return false;
00027 }
00028 
00029 
00030 int SiPixelFrameConverter::toDetector(const ElectronicIndex & cabling, DetectorIndex & detector) const
00031 {
00032   CablingPathToDetUnit path = {theFedId, cabling.link, cabling.roc }; 
00033   const PixelROC * roc = theMap->findItem(path);
00034   if (!roc){
00035     stringstream stm;
00036     stm << "Map shows no fed="<<theFedId
00037         <<", link="<<cabling.link
00038         <<", roc="<<cabling.roc;
00039     edm::LogWarning("SiPixelFrameConverter") << stm.str();
00040     return 2;
00041   }
00042   LocalPixel::DcolPxid local = { cabling.dcol, cabling.pxid };
00043   if (!local.valid()) return 3;
00044 
00045   GlobalPixel global = roc->toGlobal( LocalPixel(local) );
00046   detector.rawId = roc->rawId();
00047   detector.row   = global.row;
00048   detector.col   = global.col;
00049 
00050   return 0;
00051 
00052 
00053 }
00054 
00055 
00056 int SiPixelFrameConverter::toCabling(
00057     ElectronicIndex & cabling, const DetectorIndex & detector) const 
00058 {
00059   std::vector<CablingPathToDetUnit> path = theMap->pathToDetUnit(detector.rawId);
00060   typedef  std::vector<CablingPathToDetUnit>::const_iterator IT;
00061   for  (IT it = path.begin(); it != path.end(); ++it) {
00062     const PixelROC * roc = theMap->findItem(*it); 
00063     if (!roc) return 2;
00064     if (! roc->rawId() == detector.rawId) return 3;
00065 
00066     GlobalPixel global = {detector.row, detector.col};
00067     //LogTrace("")<<"GLOBAL PIXEL: row=" << global.row <<" col="<< global.col;
00068 
00069     LocalPixel local = roc->toLocal(global);
00070     // LogTrace("")<<"LOCAL PIXEL: dcol =" 
00071     //<<  local.dcol()<<" pxid="<<  local.pxid()<<" inside: " <<local.valid();
00072 
00073     if(!local.valid()) continue;
00074     ElectronicIndex cabIdx = {it->link, it->roc, local.dcol(), local.pxid()}; 
00075     cabling = cabIdx;
00076     return 0;
00077   }  
00078   return 1;
00079 }
00080