File indexing completed on 2024-04-06 12:02:35
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
0014
0015
0016
0017
0018 unsigned int fedId = (theMap.begin())->first.fed;
0019
0020
0021
0022 if (theVersion.find("CMSSW_9_0_X") != std::string::npos) {
0023 for (auto &v : theMap)
0024 v.second.initFrameConversionPhase1_CMSSW_9_0_X();
0025 std::cout << "*** Found CMSSW_9_0_X specific cabling map\n";
0026 return;
0027 }
0028
0029 if (fedId >= FEDNumbering::MINSiPixeluTCAFEDID) {
0030 for (auto &v : theMap)
0031 v.second.initFrameConversionPhase1();
0032 } else {
0033 for (auto &v : theMap)
0034 v.second.initFrameConversion();
0035 }
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
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
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
0086
0087
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
0095
0096 Key key = {fed, link, roc};
0097 theMap[key] = (*pROC);
0098 }
0099 }
0100 }
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;
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 }