CMS 3D CMS Logo

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