00001 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h" 00002 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h" 00003 00004 #include "CondFormats/SiPixelObjects/interface/PixelFEDCabling.h" 00005 #include "CondFormats/SiPixelObjects/interface/PixelFEDLink.h" 00006 #include "CondFormats/SiPixelObjects/interface/PixelROC.h" 00007 00008 #include "FWCore/MessageLogger/interface/MessageLogger.h" 00009 00010 #include <sstream> 00011 00012 using namespace std; 00013 using namespace sipixelobjects; 00014 00015 SiPixelFrameConverter::SiPixelFrameConverter(const SiPixelFedCablingMap * map, int fedId) 00016 : theFed( *(*map).fed(fedId)) 00017 { } 00018 00019 00020 bool SiPixelFrameConverter::hasDetUnit(uint32_t rawId) const 00021 { 00022 for (int idxLink = 1; idxLink <= theFed.numberOfLinks(); idxLink++) { 00023 const PixelFEDLink * link = theFed.link(idxLink); 00024 if (!link) continue; 00025 int numberOfRocs = link->numberOfROCs(); 00026 for(int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) { 00027 const PixelROC * roc = link->roc(idxRoc); 00028 if (!roc) continue; 00029 if (rawId == roc->rawId() ) return true; 00030 } 00031 } 00032 return false; 00033 } 00034 00035 00036 int SiPixelFrameConverter::toDetector(const ElectronicIndex & cabling, DetectorIndex & detector) const 00037 { 00038 const PixelFEDLink * link = theFed.link( cabling.link); 00039 if (!link) { 00040 stringstream stm; 00041 stm << "FED shows no link of id= " << cabling.link; 00042 LogDebug("SiPixelFrameConverter") << stm.str(); 00043 return 1; 00044 } 00045 00046 const PixelROC * roc = link->roc(cabling.roc); 00047 if (!roc) { 00048 stringstream stm; 00049 stm << "Link=" << cabling.link << " shows no ROC with id=" << cabling.roc; 00050 LogDebug("SiPixelFrameConverter") << stm.str(); 00051 return 2; 00052 } 00053 00054 LocalPixel::DcolPxid local = { cabling.dcol, cabling.pxid }; 00055 if (!local.valid()) return 3; 00056 00057 GlobalPixel global = roc->toGlobal( LocalPixel(local) ); 00058 detector.rawId = roc->rawId(); 00059 detector.row = global.row; 00060 detector.col = global.col; 00061 00062 return 0; 00063 } 00064 00065 00066 int SiPixelFrameConverter::toCabling(ElectronicIndex & cabling, const DetectorIndex & detector) const 00067 { 00068 for (int idxLink = 1; idxLink <= theFed.numberOfLinks(); idxLink++) { 00069 const PixelFEDLink * link = theFed.link(idxLink); 00070 int linkid = link->id(); 00071 int numberOfRocs = link->numberOfROCs(); 00072 00073 for(int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) { 00074 const PixelROC * roc = link->roc(idxRoc); 00075 if (detector.rawId == roc->rawId() ) { 00076 GlobalPixel global = {detector.row, detector.col}; 00077 //LogTrace("")<<"GLOBAL PIXEL: row=" << global.row <<" col="<< global.col; 00078 LocalPixel local = roc->toLocal(global); 00079 // LogTrace("")<<"LOCAL PIXEL: dcol =" << local.dcol()<<" pxid="<< local.pxid()<<" inside: " <<local.valid(); 00080 if(!local.valid()) continue; 00081 ElectronicIndex cabIdx = {linkid, idxRoc, local.dcol(), local.pxid()}; 00082 cabling = cabIdx; 00083 return 0; 00084 } 00085 } 00086 } 00087 // proper unit not found, thrown exception 00088 return 1; 00089 } 00090