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 {
10 
11 }
12 
14 {
15 
16 }
17 
18 
19 std::unordered_map<DTCELinkId, uint32_t>::const_iterator TrackerDetToDTCELinkCablingMap::dtcELinkIdToDetId(DTCELinkId const& key) const
20 {
22  {
23  throw cms::Exception("TrackerDetToDTCELinkCablingMap has been asked to return a DetId associated to a DTCELinkId, but the latter is unknown to the map. ")<<" (DTC, GBT, Elink) numbers = (" << key.dtc_id() << "," << key.gbtlink_id() << "," << key.elink_id() << ")" << std::endl;
24  }
25 
26  return cablingMapDTCELinkIdToDetId_.find(key);
27 }
28 
29 
30 std::pair<std::unordered_multimap<uint32_t, DTCELinkId>::const_iterator, std::unordered_multimap<uint32_t, DTCELinkId>::const_iterator> TrackerDetToDTCELinkCablingMap::detIdToDTCELinkId(uint32_t const key) const
31 {
32  auto const DTCELinkId_itpair = cablingMapDetIdToDTCELinkId_.equal_range(key);
33 
34  if (DTCELinkId_itpair.first == cablingMapDetIdToDTCELinkId_.end())
35  {
36  throw cms::Exception("TrackerDetToDTCELinkCablingMap has been asked to return a DTCELinkId associated to a DetId, but the latter is unknown to the map. ")<<" DetId = " << key << std::endl;
37  }
38 
39  return DTCELinkId_itpair;
40 }
41 
42 
44 {
46 }
47 
49 {
51 }
52 
53 
55 {
56  std::vector<DTCELinkId> knownDTCELinkIds(cablingMapDTCELinkIdToDetId_.size());
57 
58  // Unzip the map into a vector of DTCELinkId, discarding the DetIds
59  std::transform(cablingMapDTCELinkIdToDetId_.begin(), cablingMapDTCELinkIdToDetId_.end(), knownDTCELinkIds.begin(), [=](auto pair){return pair.first;});
60 
61  return knownDTCELinkIds;
62 }
63 
64 
66 {
67  std::vector<uint32_t> knownDetId;
68 
69  // To get the list of unique DetIds we need to iterate over the various equal_ranges
70  // in the map associated to each unique key, and count them only once.
71 
72  for (auto allpairs_it = cablingMapDetIdToDTCELinkId_.begin(), allpairs_end = cablingMapDetIdToDTCELinkId_.end(); allpairs_it != allpairs_end; )
73  {
74  // ***Store the first instance of the key***
75  knownDetId.push_back(uint32_t(allpairs_it->first));
76 
77  // *** Skip to the end of the equal range ***
78  // The following is just explicative, the bottom expression is equivalent
79  //auto const current_key = allpairs_it->first;
80  //auto const current_key_equal_range = cablingMapDetIdToDTCELinkId_.equal_range(current_key);
81  //auto const current_key_range_end = current_key_equal_range.second;
82  auto const current_key_range_end = cablingMapDetIdToDTCELinkId_.equal_range(allpairs_it->first).second;
83 
84  while (allpairs_it != current_key_range_end)
85  ++allpairs_it;
86  }
87 
88  return knownDetId;
89 }
90 
91 
92 void TrackerDetToDTCELinkCablingMap::insert(DTCELinkId const& dtcELinkId, uint32_t const detId)
93 {
94  cablingMapDTCELinkIdToDetId_.insert(std::make_pair(DTCELinkId(dtcELinkId), uint32_t(detId)));
95  cablingMapDetIdToDTCELinkId_.insert(std::make_pair(uint32_t(detId), DTCELinkId(dtcELinkId)));
96 }
97 
98 
100 {
103 }
auto gbtlink_id() const noexcept
Definition: DTCELinkId.h:41
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:42
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:40
std::unordered_multimap< uint32_t, DTCELinkId > cablingMapDetIdToDTCELinkId_