File indexing completed on 2024-04-06 12:02:35
0001 #include "CondFormats/SiPixelObjects/interface/SiPixelFedCablingTree.h"
0002 #include <algorithm>
0003 #include <sstream>
0004 #include <iostream>
0005
0006 using namespace std;
0007 using namespace sipixelobjects;
0008
0009 typedef std::unordered_map<int, SiPixelFedCablingTree::PixelFEDCabling>::const_iterator IMAP;
0010
0011 std::vector<sipixelobjects::CablingPathToDetUnit> SiPixelFedCablingTree::pathToDetUnit(uint32_t rawDetId) const {
0012 std::vector<sipixelobjects::CablingPathToDetUnit> result;
0013 for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
0014 const PixelFEDCabling& aFed = im->second;
0015 for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
0016 const PixelFEDLink* link = aFed.link(idxLink);
0017 if (!link)
0018 continue;
0019 unsigned int numberOfRocs = link->numberOfROCs();
0020 for (unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
0021 const PixelROC* roc = link->roc(idxRoc);
0022 if (rawDetId == roc->rawId()) {
0023 CablingPathToDetUnit path = {aFed.id(), link->id(), roc->idInLink()};
0024 result.push_back(path);
0025 }
0026 }
0027 }
0028 }
0029 return result;
0030 }
0031
0032 bool SiPixelFedCablingTree::pathToDetUnitHasDetUnit(uint32_t rawDetId, unsigned int fedId) const {
0033 for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
0034 const PixelFEDCabling& aFed = im->second;
0035 if (aFed.id() == fedId) {
0036 for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
0037 const PixelFEDLink* link = aFed.link(idxLink);
0038 if (!link)
0039 continue;
0040 unsigned int numberOfRocs = link->numberOfROCs();
0041 for (unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
0042 const PixelROC* roc = link->roc(idxRoc);
0043 if (rawDetId == roc->rawId()) {
0044 return true;
0045 }
0046 }
0047 }
0048 }
0049 }
0050 return false;
0051 }
0052
0053 std::unordered_map<uint32_t, unsigned int> SiPixelFedCablingTree::det2fedMap() const {
0054 std::unordered_map<uint32_t, unsigned int> result;
0055 for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
0056 auto const& aFed = im->second;
0057 for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
0058 auto link = aFed.link(idxLink);
0059 if (!link)
0060 continue;
0061 unsigned int numberOfRocs = link->numberOfROCs();
0062 for (unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
0063 auto roc = link->roc(idxRoc);
0064 result[roc->rawId()] = aFed.id();
0065 }
0066 }
0067 }
0068 return result;
0069 }
0070
0071 std::map<uint32_t, std::vector<sipixelobjects::CablingPathToDetUnit> > SiPixelFedCablingTree::det2PathMap() const {
0072 std::map<uint32_t, std::vector<sipixelobjects::CablingPathToDetUnit> > result;
0073 for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
0074 auto const& aFed = im->second;
0075 for (unsigned int idxLink = 1; idxLink <= aFed.numberOfLinks(); idxLink++) {
0076 auto link = aFed.link(idxLink);
0077 if (!link)
0078 continue;
0079 unsigned int numberOfRocs = link->numberOfROCs();
0080 for (unsigned int idxRoc = 1; idxRoc <= numberOfRocs; idxRoc++) {
0081 auto roc = link->roc(idxRoc);
0082 CablingPathToDetUnit path = {aFed.id(), link->id(), roc->idInLink()};
0083 result[roc->rawId()].push_back(path);
0084 }
0085 }
0086 }
0087 return result;
0088 }
0089
0090 void SiPixelFedCablingTree::addFed(const PixelFEDCabling& f) {
0091 int id = f.id();
0092 theFedCablings[id] = f;
0093 }
0094
0095 const PixelFEDCabling* SiPixelFedCablingTree::fed(unsigned int id) const {
0096 auto it = theFedCablings.find(id);
0097 return (it == theFedCablings.end()) ? nullptr : &(*it).second;
0098 }
0099
0100 string SiPixelFedCablingTree::print(int depth) const {
0101 ostringstream out;
0102 if (depth-- >= 0) {
0103 out << theVersion << endl;
0104 for (IMAP it = theFedCablings.begin(); it != theFedCablings.end(); it++) {
0105 out << (*it).second.print(depth);
0106 }
0107 }
0108 out << endl;
0109 return out.str();
0110 }
0111
0112 std::vector<const PixelFEDCabling*> SiPixelFedCablingTree::fedList() const {
0113 std::vector<const PixelFEDCabling*> result;
0114 for (IMAP im = theFedCablings.begin(); im != theFedCablings.end(); im++) {
0115 result.push_back(&(im->second));
0116 }
0117 std::sort(result.begin(), result.end(), [](const PixelFEDCabling* a, const PixelFEDCabling* b) {
0118 return a->id() < b->id();
0119 });
0120 return result;
0121 }
0122
0123 void SiPixelFedCablingTree::addItem(unsigned int fedId, unsigned int linkId, const PixelROC& roc) {
0124 PixelFEDCabling& cabling = theFedCablings[fedId];
0125 if (cabling.id() != fedId)
0126 cabling = PixelFEDCabling(fedId);
0127 cabling.addItem(linkId, roc);
0128 }
0129
0130 const sipixelobjects::PixelROC* SiPixelFedCablingTree::findItem(const CablingPathToDetUnit& path) const {
0131 const PixelROC* roc = nullptr;
0132 const PixelFEDCabling* aFed = fed(path.fed);
0133 if (aFed) {
0134 const PixelFEDLink* aLink = aFed->link(path.link);
0135 if (aLink)
0136 roc = aLink->roc(path.roc);
0137 }
0138 return roc;
0139 }
0140
0141 const sipixelobjects::PixelROC* SiPixelFedCablingTree::findItemInFed(const CablingPathToDetUnit& path,
0142 const PixelFEDCabling* aFed) const {
0143 const PixelROC* roc = nullptr;
0144 const PixelFEDLink* aLink = aFed->link(path.link);
0145 if (aLink)
0146 roc = aLink->roc(path.roc);
0147 return roc;
0148 }
0149
0150 int SiPixelFedCablingTree::checkNumbering() const {
0151 int status = 0;
0152 for (auto im = theFedCablings.begin(); im != theFedCablings.end(); ++im) {
0153 if (im->first != static_cast<int>(im->second.id())) {
0154 status = 1;
0155 std::cout << "PROBLEM WITH FED ID!!" << im->first << " vs: " << im->second.id() << std::endl;
0156 }
0157 im->second.checkLinkNumbering();
0158 }
0159 return status;
0160 }