Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-16 03:19:41

0001 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
0002 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCabling.h"
0003 
0004 #include "CondFormats/SiPixelObjects/interface/PixelROC.h"
0005 #include "CondFormats/SiPixelObjects/interface/CablingPathToDetUnit.h"
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 #include <sstream>
0010 
0011 using namespace std;
0012 using namespace sipixelobjects;
0013 
0014 SiPixelFrameConverter::SiPixelFrameConverter(const SiPixelFedCabling* map, int fedId)
0015     : theFedId(fedId),
0016       theMap(map),
0017       theTree(dynamic_cast<SiPixelFedCablingTree const*>(map)),
0018       theFed(theTree ? theTree->fed(fedId) : nullptr) {}
0019 
0020 bool SiPixelFrameConverter::hasDetUnit(uint32_t rawId) const {
0021   return theMap->pathToDetUnitHasDetUnit(rawId, static_cast<unsigned int>(theFedId));
0022 }
0023 
0024 PixelROC const* SiPixelFrameConverter::toRoc(int link, int roc) const {
0025   CablingPathToDetUnit path = {
0026       static_cast<unsigned int>(theFedId), static_cast<unsigned int>(link), static_cast<unsigned int>(roc)};
0027   const PixelROC* rocp = (theFed) ? theTree->findItemInFed(path, theFed) : theMap->findItem(path);
0028   if UNLIKELY (!rocp) {
0029     stringstream stm;
0030     stm << "Map shows no fed=" << theFedId << ", link=" << link << ", roc=" << roc;
0031     edm::LogWarning("SiPixelFrameConverter") << stm.str();
0032   }
0033   return rocp;
0034 }
0035 
0036 int SiPixelFrameConverter::toCabling(ElectronicIndex& cabling, const DetectorIndex& detector) const {
0037   std::vector<CablingPathToDetUnit> path = theMap->pathToDetUnit(detector.rawId);
0038   typedef std::vector<CablingPathToDetUnit>::const_iterator IT;
0039   for (IT it = path.begin(); it != path.end(); ++it) {
0040     const PixelROC* roc = theMap->findItem(*it);
0041     if (!roc)
0042       return 2;
0043     if (roc->rawId() != detector.rawId)
0044       return 3;
0045 
0046     GlobalPixel global = {detector.row, detector.col};
0047     //LogTrace("")<<"GLOBAL PIXEL: row=" << global.row <<" col="<< global.col;
0048 
0049     LocalPixel local = roc->toLocal(global);
0050     // LogTrace("")<<"LOCAL PIXEL: dcol ="
0051     //<<  local.dcol()<<" pxid="<<  local.pxid()<<" inside: " <<local.valid();
0052 
0053     if (!local.valid())
0054       continue;
0055     ElectronicIndex cabIdx = {static_cast<int>(it->link), static_cast<int>(it->roc), local.dcol(), local.pxid()};
0056     cabling = cabIdx;
0057     return 0;
0058   }
0059   return 1;
0060 }