CMS 3D CMS Logo

SiStripLatency.cc
Go to the documentation of this file.
4 
5 #include <algorithm>
6 #include <iterator>
7 #include <iostream>
8 #include <sstream>
9 
10 bool SiStripLatency::put(const uint32_t detId, const uint16_t apv, const uint16_t latency, const uint16_t mode) {
11  if (detId > 536870911) {
12  std::stringstream error;
13  error << "ERROR: the detId = " << detId
14  << " is bigger than the maximum acceptable value = 2^(29) - 1 = " << 536870911 << std::endl;
15  error << "Since we are using 29 bits for the detId and 3 bits for the apv value. The maximum tracker detId at the "
16  "moment"
17  << std::endl;
18  error
19  << "of the writing of this class was 47017836 as defined in CalibTracker/SiStripCommon/data/SiStripDetInfo.dat."
20  << std::endl;
21  error << "If the maximum value has changed a revision of this calss is needed, possibly changing the detIdAndApv "
22  "value from"
23  << std::endl;
24  error << "from uint32_t to uint64_t." << std::endl;
25  edm::LogError("SiStripLatency::put") << error.str();
26  throw cms::Exception("InsertFailure");
27  }
28 
29  // Store all the values in the vectors
30  uint32_t detIdAndApv = (detId << 3) | apv;
31  latIt pos = lower_bound(latencies_.begin(), latencies_.end(), detIdAndApv, OrderByDetIdAndApv());
32 
33  if (pos != latencies_.end() && pos->detIdAndApv == detIdAndApv) {
34  std::cout << "Value already inserted, skipping insertion" << std::endl;
35  return false;
36  }
37  // std::cout << "Filling with: latency = " << latency << ", mode = " << mode << std::endl;
38  latencies_.insert(pos, Latency(detIdAndApv, latency, mode));
39 
40  return true;
41 }
42 
44  latIt lat = latencies_.begin();
45  while (lat != latencies_.end()) {
46  // If it is not the last and it has the same latency and mode as the next one remove it
47  if (((lat + 1) != latencies_.end()) && ((lat + 1)->mode == lat->mode) && ((lat + 1)->latency == lat->latency)) {
48  lat = latencies_.erase(lat);
49  } else {
50  ++lat;
51  }
52  }
53 }
54 
55 uint16_t SiStripLatency::latency(const uint32_t detId, const uint16_t apv) const {
56  const latConstIt& pos = position(detId, apv);
57  if (pos == latencies_.end()) {
58  return 255;
59  }
60  return pos->latency;
61 }
62 
63 uint16_t SiStripLatency::mode(const uint32_t detId, const uint16_t apv) const {
64  const latConstIt& pos = position(detId, apv);
65  if (pos == latencies_.end()) {
66  return 0;
67  }
68  return pos->mode;
69 }
70 
71 std::pair<uint16_t, uint16_t> SiStripLatency::latencyAndMode(const uint32_t detId, const uint16_t apv) const {
72  const latConstIt& pos = position(detId, apv);
73  if (pos == latencies_.end()) {
74  return std::make_pair(255, 0);
75  }
76  return std::make_pair(pos->latency, pos->mode);
77 }
78 
80  if (latencies_.size() == 1) {
81  return latencies_[0].latency;
82  }
83  int differentLatenciesNum = 0;
84  // Count the number of different latencies
85  for (latConstIt it = latencies_.begin(); it != latencies_.end() - 1; ++it) {
86  if (it->latency != (it + 1)->latency) {
87  ++differentLatenciesNum;
88  }
89  }
90  if (differentLatenciesNum == 0) {
91  return latencies_[0].latency;
92  }
93  return 255;
94 }
95 
96 uint16_t SiStripLatency::singleMode() const {
97  if (latencies_.size() == 1) {
98  return latencies_[0].mode;
99  }
100  int differentModesNum = 0;
101  // Count the number of different modes
102  for (latConstIt it = latencies_.begin(); it != latencies_.end() - 1; ++it) {
103  if (it->mode != (it + 1)->mode) {
104  ++differentModesNum;
105  }
106  }
107  if (differentModesNum == 0) {
108  return latencies_[0].mode;
109  }
110  return 0;
111 }
112 
113 void SiStripLatency::allModes(std::vector<uint16_t>& allModesVector) const {
114  for (latConstIt it = latencies_.begin(); it != latencies_.end(); ++it) {
115  allModesVector.push_back(it->mode);
116  }
117  // The Latencies are sorted by DetIdAndApv, we need to sort the modes again and then remove duplicates
118  sort(allModesVector.begin(), allModesVector.end());
119  allModesVector.erase(unique(allModesVector.begin(), allModesVector.end()), allModesVector.end());
120 }
121 
123  uint16_t mode = singleMode();
124  if (mode != 0) {
125  if ((mode & READMODEMASK) == READMODEMASK)
126  return 1;
127  if ((mode & READMODEMASK) == 0)
128  return 0;
129  } else {
130  // If we are here the Tracker is not in single mode. Check if it is in single Read-out mode.
131  bool allInPeakMode = true;
132  bool allInDecoMode = true;
133  std::vector<uint16_t> allModesVector;
134  allModes(allModesVector);
135  std::vector<uint16_t>::const_iterator it = allModesVector.begin();
136  if (allModesVector.size() == 1 && allModesVector[0] == 0)
137  allInPeakMode = false;
138  else {
139  for (; it != allModesVector.end(); ++it) {
140  if ((*it) % 2 == 0)
141  continue;
142  if (((*it) & READMODEMASK) == READMODEMASK)
143  allInDecoMode = false;
144  if (((*it) & READMODEMASK) == 0)
145  allInPeakMode = false;
146  }
147  }
148  if (allInPeakMode)
149  return 1;
150  if (allInDecoMode)
151  return 0;
152  }
153  return -1;
154 }
155 
156 void SiStripLatency::allLatencies(std::vector<uint16_t>& allLatenciesVector) const {
157  for (latConstIt it = latencies_.begin(); it != latencies_.end(); ++it) {
158  allLatenciesVector.push_back(it->latency);
159  }
160  // The Latencies are sorted by DetIdAndApv, we need to sort the latencies again and then remove duplicates
161  sort(allLatenciesVector.begin(), allLatenciesVector.end());
162  allLatenciesVector.erase(unique(allLatenciesVector.begin(), allLatenciesVector.end()), allLatenciesVector.end());
163 }
164 
165 std::vector<SiStripLatency::Latency> SiStripLatency::allUniqueLatencyAndModes() {
166  std::vector<Latency> latencyCopy(latencies_);
167  sort(latencyCopy.begin(), latencyCopy.end(), OrderByLatencyAndMode());
168  latencyCopy.erase(unique(latencyCopy.begin(), latencyCopy.end(), SiStripLatency::EqualByLatencyAndMode()),
169  latencyCopy.end());
170  return latencyCopy;
171 }
172 
173 void SiStripLatency::printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const {
174  ss << std::endl;
175  if (singleReadOutMode() == 1) {
176  ss << "SingleReadOut = PEAK" << std::endl;
177  } else if (singleReadOutMode() == 0) {
178  ss << "SingleReadOut = DECO" << std::endl;
179  } else {
180  ss << "SingleReadOut = MIXED" << std::endl;
181  }
182  uint16_t lat = singleLatency();
183  if (lat != 255) {
184  ss << "All the Tracker has the same latency = " << lat << std::endl;
185  } else {
186  std::vector<uint16_t> allLatenciesVector;
187  allLatencies(allLatenciesVector);
188  if (allLatenciesVector.size() > 1) {
189  ss << "There is more than one latency value in the Tracker" << std::endl;
190  } else {
191  ss << "Latency value is " << lat << " that means invalid" << std::endl;
192  }
193  }
194  ss << "Total number of ranges = " << latencies_.size() << std::endl;
195  printDebug(ss, trackerTopo);
196 }
197 
198 void SiStripLatency::printDebug(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const {
199  ss << "List of all the latencies and modes for the " << latencies_.size() << " ranges in the object:" << std::endl;
200  for (latConstIt it = latencies_.begin(); it != latencies_.end(); ++it) {
201  int detId = it->detIdAndApv >> 3;
202  int apv = it->detIdAndApv & 7; // 7 is 0...0111
203  ss << "for detId = " << detId << " and apv pair = " << apv << " latency = " << int(it->latency)
204  << " and mode = " << int(it->mode) << std::endl;
205  }
206 }
207 
208 #undef READMODEMASK
SiStripLatency::position
const latConstIt position(const uint32_t detId, const uint16_t apv) const
Used to compute the position with the lower_bound binary search.
Definition: SiStripLatency.h:135
MessageLogger.h
config_102169_raw_cff.latency
latency
Definition: config_102169_raw_cff.py:29
SiStripLatency::OrderByDetIdAndApv
Definition: SiStripLatency.h:113
TrackerTopology
Definition: TrackerTopology.h:16
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
SiStripLatency::latencyAndMode
std::pair< uint16_t, uint16_t > latencyAndMode(const uint32_t detId, const uint16_t apv) const
Definition: SiStripLatency.cc:71
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
SiStripLatency::allUniqueLatencyAndModes
std::vector< Latency > allUniqueLatencyAndModes()
Definition: SiStripLatency.cc:165
relativeConstraints.error
error
Definition: relativeConstraints.py:53
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
SiStripLatency::latencies_
std::vector< Latency > latencies_
Definition: SiStripLatency.h:144
SiStripLatency::printDebug
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints the full list of all ranges and corresponding values of latency and mode.
Definition: SiStripLatency.cc:198
SiStripLatency::compress
void compress()
Definition: SiStripLatency.cc:43
cuda_std::lower_bound
__host__ constexpr __device__ RandomIt lower_bound(RandomIt first, RandomIt last, const T &value, Compare comp={})
Definition: cudastdAlgorithm.h:27
SiStripLatency::put
bool put(const uint32_t detId, const uint16_t apv, const uint16_t latency, const uint16_t mode)
Definition: SiStripLatency.cc:10
SiStripLatency::printSummary
void printSummary(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Prints the number of ranges as well as the value of singleLatency and singleMode.
Definition: SiStripLatency.cc:173
SiStripLatency::OrderByLatencyAndMode
Definition: SiStripLatency.h:117
edm::LogError
Definition: MessageLogger.h:183
SiStripLatency::allLatencies
void allLatencies(std::vector< uint16_t > &allLatenciesVector) const
Fills the passed vector with all the possible latencies in the Tracker.
Definition: SiStripLatency.cc:156
SiStripLatency::latency
uint16_t latency(const uint32_t detId, const uint16_t apv) const
Definition: SiStripLatency.cc:55
SiStripLatency::latIt
std::vector< Latency >::iterator latIt
Definition: SiStripLatency.h:75
READMODEMASK
#define READMODEMASK
Definition: SiStripLatency.h:13
SiStripLatency::singleMode
uint16_t singleMode() const
Definition: SiStripLatency.cc:96
createfilelist.int
int
Definition: createfilelist.py:10
SiStripLatency::singleReadOutMode
int16_t singleReadOutMode() const
Definition: SiStripLatency.cc:122
SiStripLatency::EqualByLatencyAndMode
Definition: SiStripLatency.h:126
SiStripLatency::allModes
void allModes(std::vector< uint16_t > &allModesVector) const
Fills the passed vector with all the possible modes in the Tracker.
Definition: SiStripLatency.cc:113
SiStripLatency::latConstIt
std::vector< Latency >::const_iterator latConstIt
Definition: SiStripLatency.h:76
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
Exception
Definition: hltDiff.cc:246
Exception.h
SiStripLatency::mode
uint16_t mode(const uint32_t detId, const uint16_t apv) const
Definition: SiStripLatency.cc:63
SiStripLatency.h
SiStripLatency::singleLatency
uint16_t singleLatency() const
If all the latency values stored are equal return that value, otherwise return -1.
Definition: SiStripLatency.cc:79
SiStripLatency::Latency
Definition: SiStripLatency.h:64