File indexing completed on 2024-04-06 12:02:33
0001 #include "CondFormats/SiPhase2TrackerObjects/interface/TrackerDetToDTCELinkCablingMap.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003
0004 #include <utility>
0005 #include <algorithm>
0006 #include <iostream>
0007
0008 TrackerDetToDTCELinkCablingMap::TrackerDetToDTCELinkCablingMap() {}
0009
0010 TrackerDetToDTCELinkCablingMap::~TrackerDetToDTCELinkCablingMap() {}
0011
0012 std::unordered_map<DTCELinkId, uint32_t>::const_iterator TrackerDetToDTCELinkCablingMap::dtcELinkIdToDetId(
0013 DTCELinkId const& key) const {
0014 if (cablingMapDTCELinkIdToDetId_.find(key) == cablingMapDTCELinkIdToDetId_.end()) {
0015 throw cms::Exception(
0016 "TrackerDetToDTCELinkCablingMap has been asked to return a DetId associated to a DTCELinkId, but the latter is "
0017 "unknown to the map. ")
0018 << " (DTC, GBT, Elink) numbers = (" << key.dtc_id() << "," << key.gbtlink_id() << "," << key.elink_id() << ")"
0019 << std::endl;
0020 }
0021
0022 return cablingMapDTCELinkIdToDetId_.find(key);
0023 }
0024
0025 std::pair<std::unordered_multimap<uint32_t, DTCELinkId>::const_iterator,
0026 std::unordered_multimap<uint32_t, DTCELinkId>::const_iterator>
0027 TrackerDetToDTCELinkCablingMap::detIdToDTCELinkId(uint32_t const key) const {
0028 auto const DTCELinkId_itpair = cablingMapDetIdToDTCELinkId_.equal_range(key);
0029
0030 if (DTCELinkId_itpair.first == cablingMapDetIdToDTCELinkId_.end()) {
0031 throw cms::Exception(
0032 "TrackerDetToDTCELinkCablingMap has been asked to return a DTCELinkId associated to a DetId, but the latter is "
0033 "unknown to the map. ")
0034 << " DetId = " << key << std::endl;
0035 }
0036
0037 return DTCELinkId_itpair;
0038 }
0039
0040 bool TrackerDetToDTCELinkCablingMap::knowsDTCELinkId(DTCELinkId const& key) const {
0041 return cablingMapDTCELinkIdToDetId_.find(key) != cablingMapDTCELinkIdToDetId_.end();
0042 }
0043
0044 bool TrackerDetToDTCELinkCablingMap::knowsDetId(uint32_t key) const {
0045 return cablingMapDetIdToDTCELinkId_.find(key) != cablingMapDetIdToDTCELinkId_.end();
0046 }
0047
0048 std::vector<DTCELinkId> TrackerDetToDTCELinkCablingMap::getKnownDTCELinkIds() const {
0049 std::vector<DTCELinkId> knownDTCELinkIds(cablingMapDTCELinkIdToDetId_.size());
0050
0051
0052 std::transform(cablingMapDTCELinkIdToDetId_.begin(),
0053 cablingMapDTCELinkIdToDetId_.end(),
0054 knownDTCELinkIds.begin(),
0055 [=](auto pair) { return pair.first; });
0056
0057 return knownDTCELinkIds;
0058 }
0059
0060 std::vector<uint32_t> TrackerDetToDTCELinkCablingMap::getKnownDetIds() const {
0061 std::vector<uint32_t> knownDetId;
0062
0063
0064
0065
0066 for (auto allpairs_it = cablingMapDetIdToDTCELinkId_.begin(), allpairs_end = cablingMapDetIdToDTCELinkId_.end();
0067 allpairs_it != allpairs_end;) {
0068
0069 knownDetId.push_back(uint32_t(allpairs_it->first));
0070
0071
0072
0073
0074
0075
0076 auto const current_key_range_end = cablingMapDetIdToDTCELinkId_.equal_range(allpairs_it->first).second;
0077
0078 while (allpairs_it != current_key_range_end)
0079 ++allpairs_it;
0080 }
0081
0082 return knownDetId;
0083 }
0084
0085 void TrackerDetToDTCELinkCablingMap::insert(DTCELinkId const& dtcELinkId, uint32_t const detId) {
0086 cablingMapDTCELinkIdToDetId_.insert(std::make_pair(DTCELinkId(dtcELinkId), uint32_t(detId)));
0087 cablingMapDetIdToDTCELinkId_.insert(std::make_pair(uint32_t(detId), DTCELinkId(dtcELinkId)));
0088 }
0089
0090 void TrackerDetToDTCELinkCablingMap::clear() {
0091 cablingMapDTCELinkIdToDetId_.clear();
0092 cablingMapDetIdToDTCELinkId_.clear();
0093 }