CMS 3D CMS Logo

SiStripQuality.cc
Go to the documentation of this file.
1 //
2 // Author: Domenico Giordano
3 // Created: Wed Sep 26 17:42:12 CEST 2007
4 //
13 
14 // Needed only for output
16 
18  : toCleanUp(false),
19  FileInPath_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
20  SiStripDetCabling_(nullptr),
21  printDebug_(false),
22  useEmptyRunInfo_(false) {
24 }
25 
27  : toCleanUp(false), FileInPath_(file), SiStripDetCabling_(nullptr), printDebug_(false), useEmptyRunInfo_(false) {
29 }
30 
32  FileInPath_ = other.FileInPath_;
33  reader = new SiStripDetInfoFileReader(*(other.reader));
34  toCleanUp = other.toCleanUp;
35  indexes = other.indexes;
36  v_badstrips = other.v_badstrips;
37  BadComponentVect = other.BadComponentVect;
38  SiStripDetCabling_ = other.SiStripDetCabling_;
39  printDebug_ = other.printDebug_;
40  useEmptyRunInfo_ = other.useEmptyRunInfo_;
41 }
42 
44  LogTrace("SiStripQuality") << "SiStripQuality destructor" << std::endl;
45  delete reader;
46 }
47 
49  this->add(&other);
50  this->cleanUp();
51  this->fillBadComponents();
52  return *this;
53 }
54 
56  SiStripBadStrip::RegistryIterator rbegin = other.getRegistryVectorBegin();
57  SiStripBadStrip::RegistryIterator rend = other.getRegistryVectorEnd();
58  std::vector<unsigned int> ovect, vect;
59  uint32_t detid;
60  unsigned short Nstrips;
61 
62  for (SiStripBadStrip::RegistryIterator rp = rbegin; rp != rend; ++rp) {
63  detid = rp->detid;
64  Nstrips = reader->getNumberOfApvsAndStripLength(detid).first * 128;
65 
66  SiStripBadStrip::Range orange =
67  SiStripBadStrip::Range(other.getDataVectorBegin() + rp->ibegin, other.getDataVectorBegin() + rp->iend);
68 
69  // Is this detid already in the collections owned by this class?
71  if (range.first != range.second) { // yes, it is
72 
73  vect.clear();
74  ovect.clear();
75 
76  // if other full det is bad, remove det from this
77  SiStripBadStrip::data data_ = decode(*(orange.first));
78  if (orange.second - orange.first != 1 || data_.firstStrip != 0 || data_.range < Nstrips) {
79  ovect.insert(ovect.end(), orange.first, orange.second);
80  vect.insert(vect.end(), range.first, range.second);
81  subtract(vect, ovect);
82  }
83  SiStripBadStrip::Range newrange(vect.begin(), vect.end());
84  if (!put_replace(detid, newrange))
85  edm::LogError("SiStripQuality") << "[" << __PRETTY_FUNCTION__ << "] " << std::endl;
86  }
87  }
88  cleanUp();
90  return *this;
91 }
92 
94  return SiStripQuality(*this) -= other;
95 }
96 
98  SiStripQuality a = (*this) - other;
99  return a.getRegistryVectorBegin() == a.getRegistryVectorEnd();
100 }
101 
102 bool SiStripQuality::operator!=(const SiStripQuality &other) const { return !(*this == other); }
103 
105  std::vector<unsigned int> vect;
106  short firstStrip = 0;
107  short range = 0;
108 
109  // Get vector of Voff dets
110  std::vector<uint32_t> vdets;
111  Voff->getDetIds(vdets);
112  std::vector<uint32_t>::const_iterator iter = vdets.begin();
113  std::vector<uint32_t>::const_iterator iterEnd = vdets.end();
114 
115  for (; iter != iterEnd; ++iter) {
116  vect.clear();
117  range = (short)(reader->getNumberOfApvsAndStripLength(*iter).first * 128.);
118  LogTrace("SiStripQuality") << "[add Voff] add detid " << *iter << " first strip " << firstStrip << " range "
119  << range << std::endl;
120  vect.push_back(encode(firstStrip, range));
121  SiStripBadStrip::Range Range(vect.begin(), vect.end());
122  add(*iter, Range);
123  }
124 }
125 
127  bool allFedsEmpty = runInfo->m_fed_in.empty();
128  if (allFedsEmpty) {
129  std::stringstream ss;
130  ss << "WARNING: the full list of feds in RunInfo is empty. ";
131  if (useEmptyRunInfo_) {
132  ss << " SiStripQuality will still use it and all tracker will be off." << std::endl;
133  } else {
134  ss << " SiStripQuality will not use it." << std::endl;
135  }
136  edm::LogInfo("SiStripQuality") << ss.str();
137  }
138 
139  if (!allFedsEmpty || useEmptyRunInfo_) {
140  // Take the list of active feds from fedCabling
141  auto ids = SiStripDetCabling_->fedCabling()->fedIds();
142 
143  std::vector<uint16_t> activeFedsFromCabling(ids.begin(), ids.end());
144  // Take the list of active feds from RunInfo
145  std::vector<int> activeFedsFromRunInfo;
146  // Take only Tracker feds (remove all non Tracker)
147  std::remove_copy_if(
148  runInfo->m_fed_in.begin(), runInfo->m_fed_in.end(), std::back_inserter(activeFedsFromRunInfo), [&](int x) {
150  });
151 
152  // Compare the two. If a fedId from RunInfo is not present in the fedCabling
153  // we need to get all the corresponding fedChannels and then the single apv
154  // pairs and use them to turn off the corresponding strips (apvNumber*256).
155  // set_difference returns the set of elements that are in the first and not
156  // in the second
157  std::sort(activeFedsFromCabling.begin(), activeFedsFromCabling.end());
158  std::sort(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end());
159  std::vector<int> differentFeds;
160  // Take the feds active for cabling but not for runInfo
161  std::set_difference(activeFedsFromCabling.begin(),
162  activeFedsFromCabling.end(),
163  activeFedsFromRunInfo.begin(),
164  activeFedsFromRunInfo.end(),
165  std::back_inserter(differentFeds));
166 
167  // IGNORE for time being.
168  // printActiveFedsInfo(activeFedsFromCabling, activeFedsFromRunInfo,
169  // differentFeds, printDebug_);
170 
171  // Feds in the differentFeds vector are now to be turned off as they are off
172  // according to RunInfo but were not off in cabling and thus are still
173  // active for the SiStripQuality. The "true" means that the strips are to be
174  // set as bad.
175  turnOffFeds(differentFeds, true, printDebug_);
176 
177  // Consistency check
178  // -----------------
179  std::vector<int> check;
180  std::set_difference(activeFedsFromRunInfo.begin(),
181  activeFedsFromRunInfo.end(),
182  activeFedsFromCabling.begin(),
183  activeFedsFromCabling.end(),
184  std::back_inserter(check));
185  // This must not happen
186  if (!check.empty()) {
187  // throw cms::Exception("LogicError")
188  edm::LogInfo("SiStripQuality") << "The cabling should always include the active feds in runInfo and "
189  "possibly have some more"
190  << "there are instead " << check.size() << " feds only active in runInfo";
191  // The "false" means that we are only printing the output, but not setting
192  // the strips as bad. The second bool means that we always want the debug
193  // output in this case.
194  turnOffFeds(check, false, true);
195  }
196  }
197 }
198 
200  SiStripDetCabling_ = cab;
203 }
204 
206  std::map<uint32_t, SiStripDetInfoFileReader::DetInfo> allData = reader->getAllData();
207  std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator iter = allData.begin();
208  std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator iterEnd = allData.end();
209  std::vector<unsigned int> vect;
210  short firstStrip = 0;
211  short range = 0;
212  for (; iter != iterEnd; ++iter)
213  if (!SiStripDetCabling_->IsConnected(iter->first)) {
214  vect.clear();
215  range = iter->second.nApvs * 128;
216  LogTrace("SiStripQuality") << "[addNotConnectedConnectionFromCabling] add detid " << iter->first << std::endl;
217  vect.push_back(encode(firstStrip, range));
218  SiStripBadStrip::Range Range(vect.begin(), vect.end());
219  add(iter->first, Range);
220  }
221 }
222 
224  std::vector<uint32_t> connected_detids;
225  SiStripDetCabling_->addActiveDetectorsRawIds(connected_detids);
226  std::vector<uint32_t>::const_iterator itdet = connected_detids.begin();
227  std::vector<uint32_t>::const_iterator itdetEnd = connected_detids.end();
228  for (; itdet != itdetEnd; ++itdet) {
229  // LogTrace("SiStripQuality") << "[addInvalidConnectionFromCabling] looking
230  // at detid " <<*itdet << std::endl;
231  const std::vector<const FedChannelConnection *> &fedconns = SiStripDetCabling_->getConnections(*itdet);
232  std::vector<const FedChannelConnection *>::const_iterator itconns = fedconns.begin();
233  std::vector<const FedChannelConnection *>::const_iterator itconnsEnd = fedconns.end();
234 
235  unsigned short nApvPairs = SiStripDetCabling_->nApvPairs(*itdet);
236  short ngoodConn = 0, goodConn = 0;
237  for (; itconns != itconnsEnd; ++itconns) {
238  // LogTrace("SiStripQuality") << "[addInvalidConnectionFromCabling]
239  // apvpair " << (*itconns)->apvPairNumber() << " napvpair " <<
240  // (*itconns)->nApvPairs()<< " detid " << (*itconns)->detId() <<
241  // std::endl;
242  if ((*itconns == nullptr) || ((*itconns)->nApvPairs() == sistrip::invalid_))
243  continue;
244  ngoodConn++;
245  goodConn = goodConn | (0x1 << (*itconns)->apvPairNumber());
246  }
247 
248  if (ngoodConn != nApvPairs) {
249  std::vector<unsigned int> vect;
250  for (size_t idx = 0; idx < nApvPairs; ++idx) {
251  if (!(goodConn & (0x1 << idx))) {
252  short firstStrip = idx * 256;
253  short range = 256;
254  LogTrace("SiStripQuality") << "[addInvalidConnectionFromCabling] add detid " << *itdet << "firstStrip "
255  << firstStrip << std::endl;
256  vect.push_back(encode(firstStrip, range));
257  }
258  }
259  if (!vect.empty()) {
260  SiStripBadStrip::Range Range(vect.begin(), vect.end());
261  add(*itdet, Range);
262  }
263  }
264  }
265 }
266 
268  SiStripBadStrip::RegistryIterator basebegin = base->getRegistryVectorBegin();
269  SiStripBadStrip::RegistryIterator baseend = base->getRegistryVectorEnd();
270 
271  // the Registry already contains data
272  // Loop on detids
273  for (SiStripBadStrip::RegistryIterator basep = basebegin; basep != baseend; ++basep) {
274  uint32_t detid = basep->detid;
275  LogTrace("SiStripQuality") << "add detid " << detid << std::endl;
276 
277  SiStripBadStrip::Range baserange =
278  SiStripBadStrip::Range(base->getDataVectorBegin() + basep->ibegin, base->getDataVectorBegin() + basep->iend);
279 
280  add(detid, baserange);
281  }
282 }
283 
284 void SiStripQuality::add(const uint32_t &detid, const SiStripBadStrip::Range &baserange) {
285  std::vector<unsigned int> vect, tmp;
286 
287  unsigned short Nstrips = reader->getNumberOfApvsAndStripLength(detid).first * 128;
288 
289  // Is this detid already in the collections owned by this class?
291 
292  // Append bad strips
293  tmp.clear();
294  if (range.first == range.second) {
295  LogTrace("SiStripQuality") << "new detid" << std::endl;
296  // It's a new detid
297  tmp.insert(tmp.end(), baserange.first, baserange.second);
298  std::stable_sort(tmp.begin(), tmp.end());
299  LogTrace("SiStripQuality") << "ordered" << std::endl;
300  } else {
301  LogTrace("SiStripQuality") << "already exists" << std::endl;
302  // alredy existing detid
303 
304  // if full det is bad go to next detid
305  SiStripBadStrip::data data_ = decode(*(range.first));
306  if (range.second - range.first == 1 && data_.firstStrip == 0 && data_.range >= Nstrips) {
307  LogTrace("SiStripQuality") << "full det is bad.. " << range.second - range.first << " "
308  << decode(*(range.first)).firstStrip << " " << decode(*(range.first)).range << " "
309  << decode(*(range.first)).flag << "\n"
310  << std::endl;
311  return;
312  }
313 
314  tmp.insert(tmp.end(), baserange.first, baserange.second);
315  tmp.insert(tmp.end(), range.first, range.second);
316  std::stable_sort(tmp.begin(), tmp.end());
317  LogTrace("SiStripQuality") << "ordered" << std::endl;
318  }
319  // Compact data
320  compact(tmp, vect, Nstrips);
321  SiStripBadStrip::Range newrange(vect.begin(), vect.end());
322  if (!put_replace(detid, newrange))
323  edm::LogError("SiStripQuality") << "[" << __PRETTY_FUNCTION__ << "] " << std::endl;
324 }
325 
326 void SiStripQuality::compact(unsigned int &detid, std::vector<unsigned int> &vect) {
327  std::vector<unsigned int> tmp = vect;
328  vect.clear();
329  std::stable_sort(tmp.begin(), tmp.end());
330  unsigned short Nstrips = reader->getNumberOfApvsAndStripLength(detid).first * 128;
331  compact(tmp, vect, Nstrips);
332 }
333 
335  // put in SiStripQuality::v_badstrips of DetId
336  Registry::iterator p = std::lower_bound(indexes.begin(), indexes.end(), DetId, SiStripBadStrip::StrictWeakOrdering());
337 
338  size_t sd = input.second - input.first;
339  DetRegistry detregistry;
340  detregistry.detid = DetId;
341  detregistry.ibegin = v_badstrips.size();
342  detregistry.iend = v_badstrips.size() + sd;
343 
344  v_badstrips.insert(v_badstrips.end(), input.first, input.second);
345 
346  if (p != indexes.end() && p->detid == DetId) {
347  LogTrace("SiStripQuality") << "[SiStripQuality::put_replace] Replacing "
348  "SiStripQuality for already stored DetID "
349  << DetId << std::endl;
350  toCleanUp = true;
351  *p = detregistry;
352  } else {
353  indexes.insert(p, detregistry);
354  }
355 
356  return true;
357 }
358 
359 /*
360 Method to reduce the granularity of badcomponents:
361 if in an apv there are more than ratio*128 bad strips,
362 the full apv is declared as bad.
363 Method needed to help the
364  */
368  SiStripBadStrip::data data_;
369  uint16_t BadStripPerApv[6], ipos;
370  std::vector<unsigned int> vect;
371 
372  for (; rp != rend; ++rp) {
373  uint32_t detid = rp->detid;
374 
375  BadStripPerApv[0] = 0;
376  BadStripPerApv[1] = 0;
377  BadStripPerApv[2] = 0;
378  BadStripPerApv[3] = 0;
379  BadStripPerApv[4] = 0;
380  BadStripPerApv[5] = 0;
381  ipos = 0;
382 
383  SiStripBadStrip::Range sqrange =
384  SiStripBadStrip::Range(getDataVectorBegin() + rp->ibegin, getDataVectorBegin() + rp->iend);
385 
386  for (int it = 0; it < sqrange.second - sqrange.first; it++) {
387  data_ = decode(*(sqrange.first + it));
388  LogTrace("SiStripQuality") << "[SiStripQuality::ReduceGranularity] detid " << detid << " first strip "
389  << data_.firstStrip << " lastStrip " << data_.firstStrip + data_.range - 1 << " range "
390  << data_.range;
391  ipos = data_.firstStrip / 128;
392  while (ipos <= (data_.firstStrip + data_.range - 1) / 128) {
393  BadStripPerApv[ipos] +=
394  std::min(data_.firstStrip + data_.range, (ipos + 1) * 128) - std::max(data_.firstStrip * 1, ipos * 128);
395  LogTrace("SiStripQuality") << "[SiStripQuality::ReduceGranularity] ipos " << ipos << " Counter "
396  << BadStripPerApv[ipos] << " min "
397  << std::min(data_.firstStrip + data_.range, (ipos + 1) * 128) << " max "
398  << std::max(data_.firstStrip * 1, ipos * 128) << " added "
399  << std::min(data_.firstStrip + data_.range, (ipos + 1) * 128) -
400  std::max(data_.firstStrip * 1, ipos * 128);
401  ipos++;
402  }
403  }
404 
405  LogTrace("SiStripQuality") << "[SiStripQuality::ReduceGranularity] Total for detid " << detid << " values "
406  << BadStripPerApv[0] << " " << BadStripPerApv[1] << " " << BadStripPerApv[2] << " "
407  << BadStripPerApv[3] << " " << BadStripPerApv[4] << " " << BadStripPerApv[5];
408 
409  vect.clear();
410  for (size_t i = 0; i < 6; ++i) {
411  if (BadStripPerApv[i] >= threshold * 128) {
412  vect.push_back(encode(i * 128, 128));
413  }
414  }
415  if (!vect.empty()) {
416  SiStripBadStrip::Range Range(vect.begin(), vect.end());
417  add(detid, Range);
418  }
419  }
420 }
421 
422 void SiStripQuality::compact(std::vector<unsigned int> &tmp, std::vector<unsigned int> &vect, unsigned short &Nstrips) {
423  SiStripBadStrip::data fs_0, fs_1;
424  vect.clear();
425 
426  ContainerIterator it = tmp.begin();
427  fs_0 = decode(*it);
428 
429  // Check if at the module end
430  if (fs_0.firstStrip + fs_0.range >= Nstrips) {
431  vect.push_back(encode(fs_0.firstStrip, Nstrips - fs_0.firstStrip));
432  return;
433  }
434 
435  ++it;
436  for (; it != tmp.end(); ++it) {
437  fs_1 = decode(*it);
438 
439  if (fs_0.firstStrip + fs_0.range >= fs_1.firstStrip + fs_1.range) {
440  // fs_0 includes fs_1, go ahead
441  } else if (fs_0.firstStrip + fs_0.range >= fs_1.firstStrip) {
442  // contiguous or superimposed intervals
443  // Check if at the module end
444  if (fs_1.firstStrip + fs_1.range >= Nstrips) {
445  vect.push_back(encode(fs_0.firstStrip, Nstrips - fs_0.firstStrip));
446  return;
447  } else {
448  // create new fs_0
449  fs_0.range = fs_1.firstStrip + fs_1.range - fs_0.firstStrip;
450  }
451  } else {
452  // separated intervals
453  vect.push_back(encode(fs_0.firstStrip, fs_0.range));
454  fs_0 = fs_1;
455  }
456  }
457  vect.push_back(encode(fs_0.firstStrip, fs_0.range));
458 }
459 
460 void SiStripQuality::subtract(std::vector<unsigned int> &A, const std::vector<unsigned int> &B) {
461  ContainerIterator it = B.begin();
462  ContainerIterator itend = B.end();
463  for (; it != itend; ++it) {
464  subtraction(A, *it);
465  }
466 }
467 
468 void SiStripQuality::subtraction(std::vector<unsigned int> &A, const unsigned int &B) {
469  SiStripBadStrip::data fs_A, fs_B, fs_m, fs_M;
470  std::vector<unsigned int> tmp;
471 
472  fs_B = decode(B);
473  ContainerIterator jt = A.begin();
474  ContainerIterator jtend = A.end();
475  for (; jt != jtend; ++jt) {
476  fs_A = decode(*jt);
477  if (B < *jt) {
478  fs_m = fs_B;
479  fs_M = fs_A;
480  } else {
481  fs_m = fs_A;
482  fs_M = fs_B;
483  }
484  // A) Verify the range to be subtracted crosses the new range
485  if (fs_m.firstStrip + fs_m.range > fs_M.firstStrip) {
486  if (*jt < B) {
487  tmp.push_back(encode(fs_A.firstStrip, fs_B.firstStrip - fs_A.firstStrip));
488  }
489  if (fs_A.firstStrip + fs_A.range > fs_B.firstStrip + fs_B.range) {
490  tmp.push_back(
491  encode(fs_B.firstStrip + fs_B.range, fs_A.firstStrip + fs_A.range - (fs_B.firstStrip + fs_B.range)));
492  }
493  } else {
494  tmp.push_back(*jt);
495  }
496  }
497  A = tmp;
498 }
499 
501  if (!toCleanUp && !force)
502  return false;
503 
504  toCleanUp = false;
505 
506  std::vector<unsigned int> v_badstrips_tmp = v_badstrips;
507  std::vector<DetRegistry> indexes_tmp = indexes;
508 
509  LogTrace("SiStripQuality") << "[SiStripQuality::cleanUp] before cleanUp v_badstrips.size()= " << v_badstrips.size()
510  << " indexes.size()=" << indexes.size() << std::endl;
511 
512  v_badstrips.clear();
513  indexes.clear();
514 
515  SiStripBadStrip::RegistryIterator basebegin = indexes_tmp.begin();
516  SiStripBadStrip::RegistryIterator baseend = indexes_tmp.end();
517 
518  for (SiStripBadStrip::RegistryIterator basep = basebegin; basep != baseend; ++basep) {
519  if (basep->ibegin != basep->iend) {
520  SiStripBadStrip::Range range(v_badstrips_tmp.begin() + basep->ibegin, v_badstrips_tmp.begin() + basep->iend);
521  if (!put(basep->detid, range))
522  edm::LogError("SiStripQuality") << "[" << __PRETTY_FUNCTION__ << "] " << std::endl;
523  }
524  }
525 
526  LogTrace("SiStripQuality") << "[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " << v_badstrips.size()
527  << " indexes.size()=" << indexes.size() << std::endl;
528  return true;
529 }
530 
532  BadComponentVect.clear();
533 
534  for (SiStripBadStrip::RegistryIterator basep = indexes.begin(); basep != indexes.end(); ++basep) {
535  SiStripBadStrip::Range range(v_badstrips.begin() + basep->ibegin, v_badstrips.begin() + basep->iend);
536 
537  // Fill BadModules, BadFibers, BadApvs vectors
538  unsigned short resultA = 0, resultF = 0;
540 
542  unsigned short Nstrips = reader->getNumberOfApvsAndStripLength(basep->detid).first * 128;
543 
544  // BadModules
545  fs = decode(*(range.first));
546  if (basep->iend - basep->ibegin == 1 && fs.firstStrip == 0 && fs.range == Nstrips) {
547  result.detid = basep->detid;
548  result.BadModule = true;
549  result.BadFibers = (1 << (Nstrips / 256)) - 1;
550  result.BadApvs = (1 << (Nstrips / 128)) - 1;
551 
552  BadComponentVect.push_back(result);
553 
554  } else {
555  // Bad Fibers and Apvs
556  for (SiStripBadStrip::ContainerIterator it = range.first; it != range.second; ++it) {
557  fs = decode(*it);
558 
559  // BadApvs
560  for (short apvNb = 0; apvNb < 6; ++apvNb) {
561  if (fs.firstStrip <= apvNb * 128 && (apvNb + 1) * 128 <= fs.firstStrip + fs.range) {
562  resultA = resultA | (1 << apvNb);
563  }
564  }
565  // BadFibers
566  for (short fiberNb = 0; fiberNb < 3; ++fiberNb) {
567  if (fs.firstStrip <= fiberNb * 256 && (fiberNb + 1) * 256 <= fs.firstStrip + fs.range) {
568  resultF = resultF | (1 << fiberNb);
569  }
570  }
571  }
572  if (resultA != 0) {
573  result.detid = basep->detid;
574  result.BadModule = false;
575  result.BadFibers = resultF;
576  result.BadApvs = resultA;
577  BadComponentVect.push_back(result);
578  }
579  }
580  }
581 }
582 
583 //--------------------------------------------------------------//
584 
585 bool SiStripQuality::IsModuleUsable(const uint32_t &detid) const {
586  std::vector<BadComponent>::const_iterator p = std::lower_bound(
588  if (p != BadComponentVect.end() && p->detid == detid)
589  if (p->BadModule)
590  return false;
591 
592  if (SiStripDetCabling_ != nullptr)
593  if (!SiStripDetCabling_->IsConnected(detid))
594  return false;
595 
596  return true;
597 }
598 
599 bool SiStripQuality::IsModuleBad(const uint32_t &detid) const {
600  std::vector<BadComponent>::const_iterator p = std::lower_bound(
602  if (p != BadComponentVect.end() && p->detid == detid)
603  return p->BadModule;
604  return false;
605 }
606 
607 bool SiStripQuality::IsFiberBad(const uint32_t &detid, const short &fiberNb) const {
608  std::vector<BadComponent>::const_iterator p = std::lower_bound(
610  if (p != BadComponentVect.end() && p->detid == detid)
611  return ((p->BadFibers >> fiberNb) & 0x1);
612  return false;
613 }
614 
615 bool SiStripQuality::IsApvBad(const uint32_t &detid, const short &apvNb) const {
616  std::vector<BadComponent>::const_iterator p = std::lower_bound(
618  if (p != BadComponentVect.end() && p->detid == detid)
619  return ((p->BadApvs >> apvNb) & 0x1);
620  return false;
621 }
622 
623 bool SiStripQuality::IsStripBad(const uint32_t &detid, const short &strip) const {
625  return IsStripBad(range, strip);
626 }
627 
628 bool SiStripQuality::IsStripBad(const Range &range, const short &strip) const {
629  bool result = false;
631  for (SiStripBadStrip::ContainerIterator it = range.first; it != range.second; ++it) {
632  fs = decode(*it);
633  if ((fs.firstStrip <= strip) & (strip < fs.firstStrip + fs.range)) {
634  result = true;
635  break;
636  }
637  }
638  return result;
639 }
640 
641 int SiStripQuality::nBadStripsOnTheLeft(const Range &range, const short &strip) const {
642  int result = 0;
644  for (SiStripBadStrip::ContainerIterator it = range.first; it != range.second; ++it) {
645  fs = decode(*it);
646  if (fs.firstStrip <= strip && strip < fs.firstStrip + fs.range) {
647  result = strip - fs.firstStrip + 1;
648  break;
649  }
650  }
651  return result;
652 }
653 
654 int SiStripQuality::nBadStripsOnTheRight(const Range &range, const short &strip) const {
655  int result = 0;
657  for (SiStripBadStrip::ContainerIterator it = range.first; it != range.second; ++it) {
658  fs = decode(*it);
659  if (fs.firstStrip <= strip && strip < fs.firstStrip + fs.range) {
660  result = fs.firstStrip + fs.range - strip;
661  break;
662  }
663  }
664  return result;
665 }
666 
667 short SiStripQuality::getBadApvs(const uint32_t &detid) const {
668  std::vector<BadComponent>::const_iterator p = std::lower_bound(
670  if (p != BadComponentVect.end() && p->detid == detid)
671  return p->BadApvs;
672  return 0;
673 }
674 
675 short SiStripQuality::getBadFibers(const uint32_t &detid) const {
676  std::vector<BadComponent>::const_iterator p = std::lower_bound(
678  if (p != BadComponentVect.end() && p->detid == detid)
679  return p->BadFibers;
680  return 0;
681 }
682 
684  const uint32_t &detId,
685  const uint32_t &apvPairNumber,
686  std::stringstream &ss) {
687  std::string subDetName;
688  DetId detid(detId);
689  int layer = tTopo->layer(detid);
690  int stereo = 0;
691  switch (detid.subdetId()) {
692  case StripSubdetector::TIB: {
693  stereo = tTopo->tibIsStereo(detid);
694  subDetName = "TIB";
695  break;
696  }
697  case StripSubdetector::TOB: {
698  stereo = tTopo->tobIsStereo(detid);
699  subDetName = "TOB";
700  break;
701  }
702  case StripSubdetector::TEC: {
703  stereo = tTopo->tecIsStereo(detid);
704  subDetName = "TEC";
705  break;
706  }
707  case StripSubdetector::TID: {
708  stereo = tTopo->tidIsStereo(detid);
709  subDetName = "TID";
710  break;
711  }
712  }
713  ss << detId << " and apv = " << apvPairNumber << " of subDet = " << subDetName << ", layer = " << layer
714  << " stereo = " << stereo << std::endl;
715 }
716 
717 void SiStripQuality::printActiveFedsInfo(const std::vector<uint16_t> &activeFedsFromCabling,
718  const std::vector<int> &activeFedsFromRunInfo,
719  const std::vector<int> &differentFeds,
720  const bool printDebug) {
721  std::ostringstream ss;
722 
723  if (printDebug) {
724  ss << "activeFedsFromCabling:" << std::endl;
725  std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(ss, " "));
726  ss << std::endl;
727  ss << "activeFedsFromRunInfo:" << std::endl;
728  std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(ss, " "));
729  ss << std::endl;
730  }
731  if (differentFeds.size() != 440) {
732  ss << "differentFeds : " << std::endl;
733  std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(ss, " "));
734  ss << std::endl;
735  } else {
736  ss << "There are 440 feds (all) active for Cabling but off for RunInfo. "
737  "Tracker was probably not in this run"
738  << std::endl;
739  }
740  edm::LogInfo("SiStripQuality") << ss.str() << std::endl;
741 }
742 
743 void SiStripQuality::turnOffFeds(const std::vector<int> &fedsList, const bool turnOffStrips, const bool printDebug) {
744  std::stringstream ss;
745  if (printDebug) {
746  ss << "associated to detIds : " << std::endl;
747  }
748 
749  std::vector<int>::const_iterator fedIdIt = fedsList.begin();
750  for (; fedIdIt != fedsList.end(); ++fedIdIt) {
751  std::vector<FedChannelConnection>::const_iterator fedChIt =
752  SiStripDetCabling_->fedCabling()->fedConnections(*fedIdIt).begin();
753  for (; fedChIt != SiStripDetCabling_->fedCabling()->fedConnections(*fedIdIt).end(); ++fedChIt) {
754  uint32_t detId = fedChIt->detId();
755  if (detId == 0 || detId == 0xFFFFFFFF)
756  continue;
757  uint16_t apvPairNumber = fedChIt->apvPairNumber();
758 
759  if (printDebug) {
760  printDetInfo(SiStripDetCabling_->trackerTopology(), detId, apvPairNumber, ss);
761  }
762 
763  if (turnOffStrips) {
764  // apvPairNumber == i it means that the i*256 strips are to be set off
765  std::vector<unsigned int> vect;
766  vect.push_back(encode(apvPairNumber * 256, 256));
767  SiStripBadStrip::Range Range(vect.begin(), vect.end());
768  add(detId, Range);
769  LogTrace("SiStripQuality") << "[addOffForRunInfo] adding apvPairNumber " << apvPairNumber << " for detId "
770  << detId << " off according to RunInfo" << std::endl;
771  }
772  }
773  }
774  if (printDebug) {
775  edm::LogInfo("SiStripQuality") << ss.str() << std::endl;
776  }
777 }
SiStripDetCabling::trackerTopology
const TrackerTopology *const trackerTopology() const
Definition: SiStripDetCabling.h:87
FEDNumbering.h
SiStripQuality::getBadApvs
short getBadApvs(const uint32_t &detid) const
Definition: SiStripQuality.cc:667
SiStripQuality::operator==
bool operator==(const SiStripQuality &) const
Definition: SiStripQuality.cc:97
SiStripDetCabling::addActiveDetectorsRawIds
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
Definition: SiStripDetCabling.cc:134
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
cmsStageWithFailover.force
force
Definition: cmsStageWithFailover.py:19
HLT_FULL_cff.printDebug
printDebug
Definition: HLT_FULL_cff.py:35515
mps_fire.i
i
Definition: mps_fire.py:428
input
static const std::string input
Definition: EdmProvDump.cc:48
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
SiStripBadStrip::getRange
const Range getRange(const uint32_t detID) const
Definition: SiStripBadStrip.cc:27
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
SiStripQuality::add
void add(const uint32_t &, const SiStripBadStrip::Range &)
Definition: SiStripQuality.cc:284
TrackerTopology::tobIsStereo
bool tobIsStereo(const DetId &id) const
Definition: TrackerTopology.h:264
min
T min(T a, T b)
Definition: MathUtil.h:58
TrackerTopology
Definition: TrackerTopology.h:16
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
SiStripQuality::IsModuleBad
bool IsModuleBad(const uint32_t &detid) const
Definition: SiStripQuality.cc:599
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
SiStripBadStrip::DetRegistry::iend
uint32_t iend
Definition: SiStripBadStrip.h:41
SiStripQuality::cleanUp
bool cleanUp(bool force=false)
Definition: SiStripQuality.cc:500
TrackerTopology::tecIsStereo
bool tecIsStereo(const DetId &id) const
Definition: TrackerTopology.h:265
SiStripBadStrip::decode
data decode(const unsigned int &value) const
Definition: SiStripBadStrip.h:78
typelookup.h
SiStripQuality::IsModuleUsable
bool IsModuleUsable(const uint32_t &detid) const
Definition: SiStripQuality.cc:585
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
DDAxes::x
SiStripDetCabling::fedCabling
const SiStripFedCabling * fedCabling() const
Definition: SiStripDetCabling.h:86
SiStripBadStrip::put
bool put(const uint32_t &detID, const InputVector &vect)
Definition: SiStripBadStrip.h:65
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
SiStripDetInfoFileReader
Definition: SiStripDetInfoFileReader.h:30
SiStripBadStrip::getDataVectorBegin
ContainerIterator getDataVectorBegin() const
Definition: SiStripBadStrip.h:73
SiStripQuality::printDebug_
bool printDebug_
Definition: SiStripQuality.h:159
SiStripQuality::printDetInfo
void printDetInfo(const TrackerTopology *const tTopo, const uint32_t &detId, const uint32_t &apvPairNumber, std::stringstream &ss)
Prints debug output for a given detId.
Definition: SiStripQuality.cc:683
SiStripBadStrip
Definition: SiStripBadStrip.h:30
heavyIonCSV_trainingSettings.idx
idx
Definition: heavyIonCSV_trainingSettings.py:5
SiStripQuality::BadComponentVect
std::vector< BadComponent > BadComponentVect
Definition: SiStripQuality.h:156
TrackerTopology::tidIsStereo
bool tidIsStereo(const DetId &id) const
Definition: TrackerTopology.h:267
SiStripQuality::IsFiberBad
bool IsFiberBad(const uint32_t &detid, const short &fiberNb) const
Definition: SiStripQuality.cc:607
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
DetId
Definition: DetId.h:17
edm::FileInPath
Definition: FileInPath.h:64
SiStripBadStrip::DetRegistry::ibegin
uint32_t ibegin
Definition: SiStripBadStrip.h:40
TrackerTopology.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
RPCNoise_example.check
check
Definition: RPCNoise_example.py:71
SiStripBadStrip::Range
std::pair< ContainerIterator, ContainerIterator > Range
Definition: SiStripBadStrip.h:53
RunInfo
Definition: RunInfo.h:18
SiStripDetCabling.h
SiStripBadStrip::getRegistryVectorBegin
RegistryIterator getRegistryVectorBegin() const
Definition: SiStripBadStrip.h:75
SiStripBadStrip::printDebug
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
Definition: SiStripBadStrip.cc:76
SiStripBadStrip::data::flag
unsigned short flag
Definition: SiStripBadStrip.h:35
SiStripQuality::compact
void compact(unsigned int &, std::vector< unsigned int > &)
Definition: SiStripQuality.cc:326
SiStripDetCabling
Definition: SiStripDetCabling.h:21
SiStripBadStrip::DetRegistry::detid
uint32_t detid
Definition: SiStripBadStrip.h:39
TrackerTopology::tibIsStereo
bool tibIsStereo(const DetId &id) const
Definition: TrackerTopology.h:266
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
SiStripDetCabling::IsConnected
bool IsConnected(const uint32_t &det_id) const
Definition: SiStripDetCabling.cc:375
trackingPlots.other
other
Definition: trackingPlots.py:1460
SiStripDetVOff::getDetIds
void getDetIds(std::vector< uint32_t > &DetIds_) const
Definition: SiStripDetVOff.cc:64
SiStripDetInfoFileReader.h
SiStripBadStrip::DetRegistry
Definition: SiStripBadStrip.h:38
SiStripQuality::IsStripBad
bool IsStripBad(const uint32_t &detid, const short &strip) const
Definition: SiStripQuality.cc:623
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiStripQuality::operator+=
SiStripQuality & operator+=(const SiStripQuality &)
Definition: SiStripQuality.cc:48
SiStripQuality::nBadStripsOnTheLeft
int nBadStripsOnTheLeft(const Range &range, const short &strip) const
Definition: SiStripQuality.cc:641
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
FEDNumbering::MAXSiStripFEDID
Definition: FEDNumbering.h:30
SiStripQuality::nBadStripsOnTheRight
int nBadStripsOnTheRight(const Range &range, const short &strip) const
Definition: SiStripQuality.cc:654
SiStripQuality::getBadFibers
short getBadFibers(const uint32_t &detid) const
Definition: SiStripQuality.cc:675
a
double a
Definition: hdecay.h:119
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
A
SiStripQuality::subtract
void subtract(std::vector< unsigned int > &, const std::vector< unsigned int > &)
Definition: SiStripQuality.cc:460
SiStripQuality::SiStripDetCabling_
const SiStripDetCabling * SiStripDetCabling_
Definition: SiStripQuality.h:158
createfilelist.int
int
Definition: createfilelist.py:10
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
SiStripBadStrip::data::firstStrip
unsigned short firstStrip
Definition: SiStripBadStrip.h:33
SiStripDetVOff
Definition: SiStripDetVOff.h:31
SiStripBadStrip::indexes
Registry indexes
Definition: SiStripBadStrip.h:96
SiStripBadStrip::v_badstrips
Container v_badstrips
Definition: SiStripBadStrip.h:95
SiStripQuality::fillBadComponents
void fillBadComponents()
Definition: SiStripQuality.cc:531
SiStripQuality::printActiveFedsInfo
void printActiveFedsInfo(const std::vector< uint16_t > &activeFedsFromCabling, const std::vector< int > &activeFedsFromRunInfo, const std::vector< int > &differentFeds, const bool printDebug)
Definition: SiStripQuality.cc:717
SiStripQuality::operator-=
SiStripQuality & operator-=(const SiStripQuality &)
Definition: SiStripQuality.cc:55
sistrip::invalid_
static const uint16_t invalid_
Definition: Constants.h:16
SiStripQuality::put_replace
bool put_replace(const uint32_t &DetId, Range input)
Definition: SiStripQuality.cc:334
SiStripQuality::subtraction
void subtraction(std::vector< unsigned int > &, const unsigned int &)
Definition: SiStripQuality.cc:468
SiStripQuality::IsApvBad
bool IsApvBad(const uint32_t &detid, const short &apvNb) const
Definition: SiStripQuality.cc:615
SiStripQuality::SiStripQuality
SiStripQuality()
Definition: SiStripQuality.cc:17
SiStripQuality::BadComponentStrictWeakOrdering
Definition: SiStripQuality.h:41
TtFullHadDaughter::B
static const std::string B
Definition: TtFullHadronicEvent.h:9
SiStripDetInfoFileReader::getNumberOfApvsAndStripLength
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
Definition: SiStripDetInfoFileReader.cc:101
SiStripQuality::BadComponent
Definition: SiStripQuality.h:34
StripSubdetector::TEC
static constexpr auto TEC
Definition: StripSubdetector.h:19
SiStripQuality::useEmptyRunInfo_
bool useEmptyRunInfo_
Definition: SiStripQuality.h:160
DetId.h
SiStripQuality::operator-
const SiStripQuality operator-(const SiStripQuality &) const
Definition: SiStripQuality.cc:93
SiStripDetCabling::nApvPairs
const uint16_t nApvPairs(uint32_t det_id) const
Definition: SiStripDetCabling.cc:209
SiStripDetInfoFileReader::getAllData
const std::map< uint32_t, DetInfo > & getAllData() const
Definition: SiStripDetInfoFileReader.h:58
SiStripQuality.h
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
submitPVValidationJobs.runInfo
dictionary runInfo
Definition: submitPVValidationJobs.py:1013
SiStripQuality::reader
SiStripDetInfoFileReader * reader
Definition: SiStripQuality.h:154
SiStripBadStrip::RegistryIterator
Registry::const_iterator RegistryIterator
Definition: SiStripBadStrip.h:55
sd
double sd
Definition: CascadeWrapper.h:113
SiStripBadStrip::data::range
unsigned short range
Definition: SiStripBadStrip.h:34
SiStripFedCabling::fedIds
FedsConstIterRange fedIds() const
Definition: SiStripFedCabling.h:154
mps_fire.result
result
Definition: mps_fire.py:311
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
SiStripQuality::addInvalidConnectionFromCabling
void addInvalidConnectionFromCabling()
Definition: SiStripQuality.cc:223
SiStripBadStrip::StrictWeakOrdering
Definition: SiStripBadStrip.h:46
SiStripQuality::~SiStripQuality
~SiStripQuality() override
Definition: SiStripQuality.cc:43
SiStripFedCabling::fedConnections
ConnsConstIterRange fedConnections(uint16_t fed_id) const
Definition: SiStripFedCabling.cc:160
remoteMonitoring_LED_IterMethod_cfg.threshold
threshold
Definition: remoteMonitoring_LED_IterMethod_cfg.py:430
newFWLiteAna.base
base
Definition: newFWLiteAna.py:92
SiStripQuality::toCleanUp
bool toCleanUp
Definition: SiStripQuality.h:152
SiStripQuality::turnOffFeds
void turnOffFeds(const std::vector< int > &fedsList, const bool turnOffStrips, const bool printDebug)
Definition: SiStripQuality.cc:743
SiStripBadStrip::encode
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)
Definition: SiStripBadStrip.h:86
edm::Log
Definition: MessageLogger.h:70
StripSubdetector.h
SiStripQuality::operator!=
bool operator!=(const SiStripQuality &) const
Definition: SiStripQuality.cc:102
SiStripBadStrip::ContainerIterator
std::vector< unsigned int >::const_iterator ContainerIterator
Definition: SiStripBadStrip.h:52
SiStripQuality::FileInPath_
edm::FileInPath FileInPath_
Definition: SiStripQuality.h:153
SiStripDetCabling::getConnections
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
Definition: SiStripDetCabling.cc:161
SiStripQuality::ReduceGranularity
void ReduceGranularity(double)
Definition: SiStripQuality.cc:365
SiStripBadStrip::getRegistryVectorEnd
RegistryIterator getRegistryVectorEnd() const
Definition: SiStripBadStrip.h:76
SiStripQuality::addNotConnectedConnectionFromCabling
void addNotConnectedConnectionFromCabling()
Definition: SiStripQuality.cc:205
StripSubdetector::TID
static constexpr auto TID
Definition: StripSubdetector.h:17
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:161
SiStripBadStrip::data
Definition: SiStripBadStrip.h:32
FEDNumbering::MINSiStripFEDID
Definition: FEDNumbering.h:29
SiStripQuality
Definition: SiStripQuality.h:32