Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:32

0001 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingMap.h"
0002 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
0003 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0004 
0005 #include <vector>
0006 #include <iostream>
0007 #include <algorithm>
0008 #include <iostream>
0009 
0010 using namespace sipixelobjects;
0011 
0012 void SiPixelFedCablingMap::initializeRocs() {
0013   // OLD Method
0014   //for (auto & v : theMap) v.second.initFrameConversion();
0015   // below is the new code, works for phase0 and phase1
0016 
0017   // Decide if it is phase0 or phase1 based on the first fed, 0-phase0, 1200-phase1
0018   unsigned int fedId = (theMap.begin())->first.fed;  // get the first fed
0019 
0020   // Specifically for CMSSW_9_0_X, we need to call a different version of the frame
0021   // conversion steered by the version name in the cabling map
0022   if (theVersion.find("CMSSW_9_0_X") != std::string::npos) {
0023     for (auto &v : theMap)
0024       v.second.initFrameConversionPhase1_CMSSW_9_0_X();  // works
0025     std::cout << "*** Found CMSSW_9_0_X specific cabling map\n";
0026     return;
0027   }
0028 
0029   if (fedId >= FEDNumbering::MINSiPixeluTCAFEDID) {  // phase1 >= 1200
0030     for (auto &v : theMap)
0031       v.second.initFrameConversionPhase1();  // works
0032   } else {                                   // phase0
0033     for (auto &v : theMap)
0034       v.second.initFrameConversion();  // works
0035   }
0036 
0037   // if(0) {  // for testing
0038   //   for (Map::iterator im = theMap.begin(); im != theMap.end(); im++) {
0039   //     unsigned int fedId = im->first.fed;
0040   //     unsigned int linkId = im->first.link;
0041   //     unsigned int rocId = im->first.roc;
0042   //     auto rawDetID = im->second.rawId();
0043   //     auto idInDetUnit = im->second.idInDetUnit();
0044   //     auto idInLink = im->second.idInLink();
0045   //     //auto v = *im;
0046   //     if(fedId>=1200) {
0047   //    //v.second.initFrameConversionPhase1(); //
0048   //    im->second.initFrameConversionPhase1(); //
0049   //     } else {
0050   //    im->second.initFrameConversion();
0051   //     }
0052   //   } //
0053   // } // end if(0)
0054 }
0055 
0056 bool SiPixelFedCablingMap::Key::operator<(const Key &other) const {
0057   if (fed < other.fed)
0058     return true;
0059   if (fed > other.fed)
0060     return false;
0061 
0062   if (link < other.link)
0063     return true;
0064   if (link > other.link)
0065     return false;
0066 
0067   if (roc < other.roc)
0068     return true;
0069   if (roc > other.roc)
0070     return false;
0071 
0072   return false;
0073 }
0074 
0075 SiPixelFedCablingMap::SiPixelFedCablingMap(const SiPixelFedCablingTree *cab) : theVersion(cab->version()) {
0076   // Never called
0077   std::vector<const PixelFEDCabling *> fedList = cab->fedList();
0078   for (std::vector<const PixelFEDCabling *>::const_iterator ifed = fedList.begin(); ifed != fedList.end(); ifed++) {
0079     unsigned int fed = (**ifed).id();
0080     unsigned int numLink = (**ifed).numberOfLinks();
0081     for (unsigned int link = 1; link <= numLink; link++) {
0082       const PixelFEDLink *pLink = (**ifed).link(link);
0083       if (pLink == nullptr)
0084         continue;
0085       //unsigned int linkId = pLink->id();
0086       //if (linkId != 0 && linkId!= link)
0087       //  std::cout << "PROBLEM WITH LINK NUMBER!!!!" << std::endl;
0088       unsigned int numberROC = pLink->numberOfROCs();
0089 
0090       for (unsigned int roc = 1; roc <= numberROC; roc++) {
0091         const PixelROC *pROC = pLink->roc(roc);
0092         if (pROC == nullptr)
0093           continue;
0094         //if (pROC->idInLink() != roc)
0095         //  std::cout << "PROBLEM WITH ROC NUMBER!!!!" << std::endl;
0096         Key key = {fed, link, roc};
0097         theMap[key] = (*pROC);
0098       }
0099     }
0100   }  // fed loop
0101 }
0102 
0103 std::unique_ptr<SiPixelFedCablingTree> SiPixelFedCablingMap::cablingTree() const {
0104   std::unique_ptr<SiPixelFedCablingTree> tree(new SiPixelFedCablingTree(theVersion));
0105   for (Map::const_iterator im = theMap.begin(); im != theMap.end(); im++) {
0106     const sipixelobjects::PixelROC &roc = im->second;
0107     unsigned int fedId = im->first.fed;
0108     unsigned int linkId = im->first.link;
0109     tree->addItem(fedId, linkId, roc);
0110   }
0111   return tree;
0112 }
0113 
0114 std::vector<unsigned int> SiPixelFedCablingMap::fedIds() const {
0115   std::vector<unsigned int> result;
0116   for (Map::const_iterator im = theMap.begin(); im != theMap.end(); im++) {
0117     unsigned int fedId = im->first.fed;
0118     if (find(result.begin(), result.end(), fedId) == result.end())
0119       result.push_back(fedId);
0120   }
0121   return result;
0122 }
0123 
0124 const sipixelobjects::PixelROC *SiPixelFedCablingMap::findItem(const sipixelobjects::CablingPathToDetUnit &path) const {
0125   const PixelROC *roc = nullptr;
0126   Key key = {path.fed, path.link, path.roc};
0127   Map::const_iterator inMap = theMap.find(key);
0128   if (inMap != theMap.end())
0129     roc = &(inMap->second);
0130   return roc;
0131 }
0132 
0133 std::unordered_map<uint32_t, unsigned int> SiPixelFedCablingMap::det2fedMap() const {
0134   std::unordered_map<uint32_t, unsigned int> result;
0135   for (auto im = theMap.begin(); im != theMap.end(); ++im) {
0136     result[im->second.rawId()] = im->first.fed;  // we know: a det is in only one fed!
0137   }
0138   return result;
0139 }
0140 
0141 std::map<uint32_t, std::vector<sipixelobjects::CablingPathToDetUnit> > SiPixelFedCablingMap::det2PathMap() const {
0142   std::map<uint32_t, std::vector<sipixelobjects::CablingPathToDetUnit> > result;
0143   for (auto im = theMap.begin(); im != theMap.end(); ++im) {
0144     CablingPathToDetUnit path = {im->first.fed, im->first.link, im->first.roc};
0145     result[im->second.rawId()].push_back(path);
0146   }
0147   return result;
0148 }
0149 
0150 std::vector<sipixelobjects::CablingPathToDetUnit> SiPixelFedCablingMap::pathToDetUnit(uint32_t rawDetId) const {
0151   std::vector<sipixelobjects::CablingPathToDetUnit> result;
0152   for (auto im = theMap.begin(); im != theMap.end(); ++im) {
0153     if (im->second.rawId() == rawDetId) {
0154       CablingPathToDetUnit path = {im->first.fed, im->first.link, im->first.roc};
0155       result.push_back(path);
0156     }
0157   }
0158   return result;
0159 }
0160 
0161 bool SiPixelFedCablingMap::pathToDetUnitHasDetUnit(uint32_t rawDetId, unsigned int fedId) const {
0162   auto end = theMap.end();
0163   for (auto im = theMap.lower_bound({fedId, 0, 0}); im != end and im->first.fed == fedId; ++im) {
0164     if (im->second.rawId() == rawDetId) {
0165       return true;
0166     }
0167   }
0168   return false;
0169 }