File indexing completed on 2023-03-17 10:47:41
0001 #include "CondFormats/SiStripObjects/interface/Phase2TrackerCabling.h"
0002 #include "CondFormats/SiStripObjects/interface/Phase2TrackerModule.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include <sstream>
0006
0007
0008
0009
0010 bool Phase2TrackerCabling::chOrdering(Phase2TrackerCabling::key a, Phase2TrackerCabling::key b) {
0011 if (a->getCh().first == b->getCh().first)
0012 return a->getCh().second < b->getCh().second;
0013 else
0014 return a->getCh().first < b->getCh().first;
0015 }
0016 bool Phase2TrackerCabling::chComp(Phase2TrackerCabling::key a, std::pair<unsigned int, unsigned int> b) {
0017 if (a->getCh().first == b.first)
0018 return a->getCh().second < b.second;
0019 else
0020 return a->getCh().first < b.first;
0021 }
0022 bool Phase2TrackerCabling::fedeq(key a, key b) { return (a->getCh().first == b->getCh().first); }
0023
0024
0025 bool Phase2TrackerCabling::detidOrdering(Phase2TrackerCabling::key a, Phase2TrackerCabling::key b) {
0026 return a->getDetid() < b->getDetid();
0027 }
0028 bool Phase2TrackerCabling::detidComp(Phase2TrackerCabling::key a, uint32_t b) { return a->getDetid() < b; }
0029
0030
0031 bool Phase2TrackerCabling::gbtidOrdering(Phase2TrackerCabling::key a, Phase2TrackerCabling::key b) {
0032 return a->getGbtid() < b->getGbtid();
0033 }
0034 bool Phase2TrackerCabling::gbtidComp(Phase2TrackerCabling::key a, uint32_t b) { return a->getGbtid() < b; }
0035
0036
0037 bool Phase2TrackerCabling::coolingOrdering(const Phase2TrackerModule& a, const Phase2TrackerModule& b) {
0038 return a.getCoolingLoop() < b.getCoolingLoop();
0039 }
0040 bool Phase2TrackerCabling::coolingComp(const Phase2TrackerModule& a, uint32_t b) { return a.getCoolingLoop() < b; }
0041 bool Phase2TrackerCabling::cooleq(const Phase2TrackerModule& a, const Phase2TrackerModule& b) {
0042 return (a.getCoolingLoop() == b.getCoolingLoop());
0043 }
0044
0045
0046 bool Phase2TrackerCabling::powerOrdering(const Phase2TrackerModule& a, const Phase2TrackerModule& b) {
0047 return a.getPowerGroup() < b.getPowerGroup();
0048 }
0049 bool Phase2TrackerCabling::powerComp(const Phase2TrackerModule& a, uint32_t b) { return a.getPowerGroup() < b; }
0050 bool Phase2TrackerCabling::poweq(const Phase2TrackerModule& a, const Phase2TrackerModule& b) {
0051 return (a.getPowerGroup() == b.getPowerGroup());
0052 }
0053
0054
0055
0056 Phase2TrackerCabling::Phase2TrackerCabling(const std::vector<Phase2TrackerModule>& cons) : connections_(cons) {
0057
0058 initializeCabling();
0059 }
0060
0061 Phase2TrackerCabling::Phase2TrackerCabling(const Phase2TrackerCabling& src) {
0062 connections_ = src.connections_;
0063 fedCabling_ = src.fedCabling_;
0064 detCabling_ = src.detCabling_;
0065 gbtCabling_ = src.gbtCabling_;
0066 }
0067
0068 void Phase2TrackerCabling::initializeCabling() {
0069
0070 fedCabling_.reserve(connections_.size());
0071 detCabling_.reserve(connections_.size());
0072 gbtCabling_.reserve(connections_.size());
0073 for (key module = connections_.begin(); module < connections_.end(); ++module) {
0074 fedCabling_.push_back(module);
0075 detCabling_.push_back(module);
0076 gbtCabling_.push_back(module);
0077 }
0078
0079 std::sort(fedCabling_.begin(), fedCabling_.end(), chOrdering);
0080 std::sort(detCabling_.begin(), detCabling_.end(), detidOrdering);
0081 std::sort(gbtCabling_.begin(), gbtCabling_.end(), gbtidOrdering);
0082 }
0083
0084 const Phase2TrackerModule& Phase2TrackerCabling::findFedCh(std::pair<unsigned int, unsigned int> fedch) const {
0085
0086 cabling::const_iterator itid = std::lower_bound(fedCabling_.begin(), fedCabling_.end(), fedch, chComp);
0087 if (itid != fedCabling_.end() && (*itid)->getCh() == fedch)
0088 return **itid;
0089 else
0090 throw cms::Exception("IndexNotFound")
0091 << "No connection corresponding to FED id/ch = " << fedch.first << "/" << fedch.second;
0092 }
0093
0094 const Phase2TrackerModule& Phase2TrackerCabling::findDetid(uint32_t detid) const {
0095
0096 cabling::const_iterator itch = std::lower_bound(detCabling_.begin(), detCabling_.end(), detid, detidComp);
0097 if (itch != detCabling_.end() && (*itch)->getDetid() == detid)
0098 return **itch;
0099 else
0100 throw cms::Exception("IndexNotFound")
0101 << "No connection corresponding to detid = 0x" << std::hex << detid << std::dec;
0102 }
0103
0104 const Phase2TrackerModule& Phase2TrackerCabling::findGbtid(uint32_t gbtid) const {
0105
0106 cabling::const_iterator itch = std::lower_bound(gbtCabling_.begin(), gbtCabling_.end(), gbtid, gbtidComp);
0107 if (itch != gbtCabling_.end() && (*itch)->getGbtid() == gbtid)
0108 return **itch;
0109 else
0110 throw cms::Exception("IndexNotFound")
0111 << "No connection corresponding to gbtid = 0x" << std::hex << gbtid << std::dec;
0112 }
0113
0114 Phase2TrackerCabling Phase2TrackerCabling::filterByCoolingLine(uint32_t coolingLine) const {
0115
0116
0117
0118
0119 store resultStore = connections_;
0120
0121 std::sort(resultStore.begin(), resultStore.end(), coolingOrdering);
0122
0123 std::pair<key, key> range = std::equal_range(resultStore.begin(),
0124 resultStore.end(),
0125 Phase2TrackerModule(Phase2TrackerModule::SS, 0, 0, 0, 0, 0, coolingLine),
0126 coolingOrdering);
0127
0128 Phase2TrackerCabling result(store(range.first, range.second));
0129
0130 return result;
0131 }
0132
0133 Phase2TrackerCabling Phase2TrackerCabling::filterByPowerGroup(uint32_t powerGroup) const {
0134
0135
0136
0137
0138 store resultStore = connections_;
0139
0140 std::sort(resultStore.begin(), resultStore.end(), powerOrdering);
0141
0142 std::pair<key, key> range = std::equal_range(resultStore.begin(),
0143 resultStore.end(),
0144 Phase2TrackerModule(Phase2TrackerModule::SS, 0, 0, 0, 0, powerGroup, 0),
0145 powerOrdering);
0146
0147 Phase2TrackerCabling result(store(range.first, range.second));
0148
0149 return result;
0150 }
0151
0152 std::string Phase2TrackerCabling::summaryDescription() const {
0153 std::string mystring("Summary of the cabling\n======================\n");
0154 std::stringstream ss;
0155
0156 ss << "Number of modules: " << connections_.size() << std::endl;
0157 store orig(connections_);
0158 ss << "Number of FEDs: ";
0159 cabling tmpc(fedCabling_);
0160 ss << std::distance(tmpc.begin(), std::unique(tmpc.begin(), tmpc.end(), fedeq)) << std::endl;
0161 ss << "Number of cooling loops: ";
0162 std::sort(orig.begin(), orig.end(), coolingOrdering);
0163 store tmp(orig);
0164 ss << std::distance(tmp.begin(), std::unique(tmp.begin(), tmp.end(), cooleq)) << std::endl;
0165 ss << "Number of power groups: ";
0166 std::sort(orig.begin(), orig.end(), powerOrdering);
0167 tmp = orig;
0168 ss << std::distance(tmp.begin(), std::unique(tmp.begin(), tmp.end(), poweq)) << std::endl;
0169 mystring += ss.str();
0170 return mystring;
0171 }
0172
0173 std::string Phase2TrackerCabling::description(bool compact) const {
0174 std::string mystring("Cabling:\n========\n");
0175 for (std::vector<Phase2TrackerModule>::const_iterator it = connections_.begin(); it < connections_.end(); ++it) {
0176 mystring += it->description(compact);
0177 }
0178 return mystring;
0179 }