CMS 3D CMS Logo

TrackerDetToDTCELinkCablingMap.cc
Go to the documentation of this file.
3 
4 #include <utility>
5 #include <algorithm>
6 #include <iostream>
7 
9 
11 
12 std::unordered_map<DTCELinkId, uint32_t>::const_iterator TrackerDetToDTCELinkCablingMap::dtcELinkIdToDetId(
13  DTCELinkId const& key) const {
15  throw cms::Exception(
16  "TrackerDetToDTCELinkCablingMap has been asked to return a DetId associated to a DTCELinkId, but the latter is "
17  "unknown to the map. ")
18  << " (DTC, GBT, Elink) numbers = (" << key.dtc_id() << "," << key.gbtlink_id() << "," << key.elink_id() << ")"
19  << std::endl;
20  }
21 
22  return cablingMapDTCELinkIdToDetId_.find(key);
23 }
24 
25 std::pair<std::unordered_multimap<uint32_t, DTCELinkId>::const_iterator,
26  std::unordered_multimap<uint32_t, DTCELinkId>::const_iterator>
28  auto const DTCELinkId_itpair = cablingMapDetIdToDTCELinkId_.equal_range(key);
29 
30  if (DTCELinkId_itpair.first == cablingMapDetIdToDTCELinkId_.end()) {
31  throw cms::Exception(
32  "TrackerDetToDTCELinkCablingMap has been asked to return a DTCELinkId associated to a DetId, but the latter is "
33  "unknown to the map. ")
34  << " DetId = " << key << std::endl;
35  }
36 
37  return DTCELinkId_itpair;
38 }
39 
42 }
43 
46 }
47 
48 std::vector<DTCELinkId> TrackerDetToDTCELinkCablingMap::getKnownDTCELinkIds() const {
49  std::vector<DTCELinkId> knownDTCELinkIds(cablingMapDTCELinkIdToDetId_.size());
50 
51  // Unzip the map into a vector of DTCELinkId, discarding the DetIds
54  knownDTCELinkIds.begin(),
55  [=](auto pair) { return pair.first; });
56 
57  return knownDTCELinkIds;
58 }
59 
60 std::vector<uint32_t> TrackerDetToDTCELinkCablingMap::getKnownDetIds() const {
61  std::vector<uint32_t> knownDetId;
62 
63  // To get the list of unique DetIds we need to iterate over the various equal_ranges
64  // in the map associated to each unique key, and count them only once.
65 
66  for (auto allpairs_it = cablingMapDetIdToDTCELinkId_.begin(), allpairs_end = cablingMapDetIdToDTCELinkId_.end();
67  allpairs_it != allpairs_end;) {
68  // ***Store the first instance of the key***
69  knownDetId.push_back(uint32_t(allpairs_it->first));
70 
71  // *** Skip to the end of the equal range ***
72  // The following is just explicative, the bottom expression is equivalent
73  //auto const current_key = allpairs_it->first;
74  //auto const current_key_equal_range = cablingMapDetIdToDTCELinkId_.equal_range(current_key);
75  //auto const current_key_range_end = current_key_equal_range.second;
76  auto const current_key_range_end = cablingMapDetIdToDTCELinkId_.equal_range(allpairs_it->first).second;
77 
78  while (allpairs_it != current_key_range_end)
79  ++allpairs_it;
80  }
81 
82  return knownDetId;
83 }
84 
85 void TrackerDetToDTCELinkCablingMap::insert(DTCELinkId const& dtcELinkId, uint32_t const detId) {
86  cablingMapDTCELinkIdToDetId_.insert(std::make_pair(DTCELinkId(dtcELinkId), uint32_t(detId)));
87  cablingMapDetIdToDTCELinkId_.insert(std::make_pair(uint32_t(detId), DTCELinkId(dtcELinkId)));
88 }
89 
93 }
auto gbtlink_id() const noexcept
Definition: DTCELinkId.h:40
std::unordered_map< DTCELinkId, uint32_t >::const_iterator dtcELinkIdToDetId(DTCELinkId const &) const
Resolves the raw DetId of the detector connected to the eLink identified by a DTCELinkId.
std::vector< DTCELinkId > getKnownDTCELinkIds() const
Returns a vector containing all elink DTCELinkId nown to the map.
bool knowsDetId(uint32_t) const
Returns true if the cabling map has a record corresponding to an eLink identified by the given DTCELi...
void insert(DTCELinkId const &, uint32_t const)
Inserts in the cabling map a record corresponding to the connection of an eLink identified by the giv...
auto dtc_id() const noexcept
Definition: DTCELinkId.h:41
bool knowsDTCELinkId(DTCELinkId const &) const
Returns true if the cabling map has a record corresponding to a detector identified by the given raw ...
std::vector< uint32_t > getKnownDetIds() const
Returns a vector containing all detector DetId known to the map.
std::pair< std::unordered_multimap< uint32_t, DTCELinkId >::const_iterator, std::unordered_multimap< uint32_t, DTCELinkId >::const_iterator > detIdToDTCELinkId(uint32_t const) const
Resolves one or more DTCELinkId of eLinks which are connected to the detector identified by the given...
std::unordered_map< DTCELinkId, uint32_t > cablingMapDTCELinkIdToDetId_
auto elink_id() const noexcept
Definition: DTCELinkId.h:39
std::unordered_multimap< uint32_t, DTCELinkId > cablingMapDetIdToDTCELinkId_
unsigned transform(const HcalDetId &id, unsigned transformCode)