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  : info_(std::move(iInfo)),
19  toCleanUp(false),
20  SiStripDetCabling_(nullptr),
21  printDebug_(false),
22  useEmptyRunInfo_(false) {}
23 
25  SiStripBadStrip::RegistryIterator rbegin = other.getRegistryVectorBegin();
26  SiStripBadStrip::RegistryIterator rend = other.getRegistryVectorEnd();
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) {
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 
227  SiStripBadStrip::RegistryIterator basebegin = base->getRegistryVectorBegin();
228  SiStripBadStrip::RegistryIterator baseend = base->getRegistryVectorEnd();
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(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(uint32_t 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 
341  SiStripBadStrip::Range sqrange =
342  SiStripBadStrip::Range(getDataVectorBegin() + rp->ibegin, getDataVectorBegin() + rp->iend);
343 
344  for (int it = 0; it < sqrange.second - sqrange.first; it++) {
345  data_ = decode(*(sqrange.first + it));
346  LogTrace("SiStripQuality") << "[SiStripQuality::ReduceGranularity] detid " << detid << " first strip "
347  << data_.firstStrip << " lastStrip " << data_.firstStrip + data_.range - 1 << " range "
348  << data_.range;
349  ipos = data_.firstStrip / 128;
350  while (ipos <= (data_.firstStrip + data_.range - 1) / 128) {
351  BadStripPerApv[ipos] +=
352  std::min(data_.firstStrip + data_.range, (ipos + 1) * 128) - std::max(data_.firstStrip * 1, ipos * 128);
353  LogTrace("SiStripQuality") << "[SiStripQuality::ReduceGranularity] ipos " << ipos << " Counter "
354  << BadStripPerApv[ipos] << " min "
355  << std::min(data_.firstStrip + data_.range, (ipos + 1) * 128) << " max "
356  << std::max(data_.firstStrip * 1, ipos * 128) << " added "
357  << std::min(data_.firstStrip + data_.range, (ipos + 1) * 128) -
358  std::max(data_.firstStrip * 1, ipos * 128);
359  ipos++;
360  }
361  }
362 
363  LogTrace("SiStripQuality") << "[SiStripQuality::ReduceGranularity] Total for detid " << detid << " values "
364  << BadStripPerApv[0] << " " << BadStripPerApv[1] << " " << BadStripPerApv[2] << " "
365  << BadStripPerApv[3] << " " << BadStripPerApv[4] << " " << BadStripPerApv[5];
366 
367  vect.clear();
368  for (size_t i = 0; i < 6; ++i) {
369  if (BadStripPerApv[i] >= threshold * 128) {
370  vect.push_back(encode(i * 128, 128));
371  }
372  }
373  if (!vect.empty()) {
374  SiStripBadStrip::Range Range(vect.begin(), vect.end());
375  add(detid, Range);
376  }
377  }
378 }
379 
380 void SiStripQuality::compact(std::vector<unsigned int> &tmp, std::vector<unsigned int> &vect, unsigned short &Nstrips) {
381  SiStripBadStrip::data fs_0, fs_1;
382  vect.clear();
383 
384  ContainerIterator it = tmp.begin();
385  fs_0 = decode(*it);
386 
387  // Check if at the module end
388  if (fs_0.firstStrip + fs_0.range >= Nstrips) {
389  vect.push_back(encode(fs_0.firstStrip, Nstrips - fs_0.firstStrip));
390  return;
391  }
392 
393  ++it;
394  for (; it != tmp.end(); ++it) {
395  fs_1 = decode(*it);
396 
397  if (fs_0.firstStrip + fs_0.range >= fs_1.firstStrip + fs_1.range) {
398  // fs_0 includes fs_1, go ahead
399  } else if (fs_0.firstStrip + fs_0.range >= fs_1.firstStrip) {
400  // contiguous or superimposed intervals
401  // Check if at the module end
402  if (fs_1.firstStrip + fs_1.range >= Nstrips) {
403  vect.push_back(encode(fs_0.firstStrip, Nstrips - fs_0.firstStrip));
404  return;
405  } else {
406  // create new fs_0
407  fs_0.range = fs_1.firstStrip + fs_1.range - fs_0.firstStrip;
408  }
409  } else {
410  // separated intervals
411  vect.push_back(encode(fs_0.firstStrip, fs_0.range));
412  fs_0 = fs_1;
413  }
414  }
415  vect.push_back(encode(fs_0.firstStrip, fs_0.range));
416 }
417 
418 void SiStripQuality::subtract(std::vector<unsigned int> &A, const std::vector<unsigned int> &B) {
419  ContainerIterator it = B.begin();
420  ContainerIterator itend = B.end();
421  for (; it != itend; ++it) {
422  subtraction(A, *it);
423  }
424 }
425 
426 void SiStripQuality::subtraction(std::vector<unsigned int> &A, const unsigned int &B) {
427  SiStripBadStrip::data fs_A, fs_B, fs_m, fs_M;
428  std::vector<unsigned int> tmp;
429 
430  fs_B = decode(B);
431  ContainerIterator jt = A.begin();
432  ContainerIterator jtend = A.end();
433  for (; jt != jtend; ++jt) {
434  fs_A = decode(*jt);
435  if (B < *jt) {
436  fs_m = fs_B;
437  fs_M = fs_A;
438  } else {
439  fs_m = fs_A;
440  fs_M = fs_B;
441  }
442  // A) Verify the range to be subtracted crosses the new range
443  if (fs_m.firstStrip + fs_m.range > fs_M.firstStrip) {
444  if (*jt < B) {
445  tmp.push_back(encode(fs_A.firstStrip, fs_B.firstStrip - fs_A.firstStrip));
446  }
447  if (fs_A.firstStrip + fs_A.range > fs_B.firstStrip + fs_B.range) {
448  tmp.push_back(
449  encode(fs_B.firstStrip + fs_B.range, fs_A.firstStrip + fs_A.range - (fs_B.firstStrip + fs_B.range)));
450  }
451  } else {
452  tmp.push_back(*jt);
453  }
454  }
455  A = tmp;
456 }
457 
459  if (!toCleanUp && !force)
460  return false;
461 
462  toCleanUp = false;
463 
464  std::vector<unsigned int> v_badstrips_tmp = v_badstrips;
465  std::vector<DetRegistry> indexes_tmp = indexes;
466 
467  LogTrace("SiStripQuality") << "[SiStripQuality::cleanUp] before cleanUp v_badstrips.size()= " << v_badstrips.size()
468  << " indexes.size()=" << indexes.size() << std::endl;
469 
470  v_badstrips.clear();
471  indexes.clear();
472 
473  SiStripBadStrip::RegistryIterator basebegin = indexes_tmp.begin();
474  SiStripBadStrip::RegistryIterator baseend = indexes_tmp.end();
475 
476  for (SiStripBadStrip::RegistryIterator basep = basebegin; basep != baseend; ++basep) {
477  if (basep->ibegin != basep->iend) {
478  SiStripBadStrip::Range range(v_badstrips_tmp.begin() + basep->ibegin, v_badstrips_tmp.begin() + basep->iend);
479  if (!put(basep->detid, range))
480  edm::LogError("SiStripQuality") << "[" << __PRETTY_FUNCTION__ << "] " << std::endl;
481  }
482  }
483 
484  LogTrace("SiStripQuality") << "[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " << v_badstrips.size()
485  << " indexes.size()=" << indexes.size() << std::endl;
486  return true;
487 }
488 
490  BadComponentVect.clear();
491 
492  for (SiStripBadStrip::RegistryIterator basep = indexes.begin(); basep != indexes.end(); ++basep) {
493  SiStripBadStrip::Range range(v_badstrips.begin() + basep->ibegin, v_badstrips.begin() + basep->iend);
494 
495  // Fill BadModules, BadFibers, BadApvs vectors
496  unsigned short resultA = 0, resultF = 0;
498 
500  unsigned short Nstrips = info_.getNumberOfApvsAndStripLength(basep->detid).first * 128;
501 
502  // BadModules
503  fs = decode(*(range.first));
504  if (basep->iend - basep->ibegin == 1 && fs.firstStrip == 0 && fs.range == Nstrips) {
505  result.detid = basep->detid;
506  result.BadModule = true;
507  result.BadFibers = (1 << (Nstrips / 256)) - 1;
508  result.BadApvs = (1 << (Nstrips / 128)) - 1;
509 
510  BadComponentVect.push_back(result);
511 
512  } else {
513  // Bad Fibers and Apvs
514  for (SiStripBadStrip::ContainerIterator it = range.first; it != range.second; ++it) {
515  fs = decode(*it);
516 
517  // BadApvs
518  for (short apvNb = 0; apvNb < 6; ++apvNb) {
519  if (fs.firstStrip <= apvNb * 128 && (apvNb + 1) * 128 <= fs.firstStrip + fs.range) {
520  resultA = resultA | (1 << apvNb);
521  }
522  }
523  // BadFibers
524  for (short fiberNb = 0; fiberNb < 3; ++fiberNb) {
525  if (fs.firstStrip <= fiberNb * 256 && (fiberNb + 1) * 256 <= fs.firstStrip + fs.range) {
526  resultF = resultF | (1 << fiberNb);
527  }
528  }
529  }
530  if (resultA != 0) {
531  result.detid = basep->detid;
532  result.BadModule = false;
533  result.BadFibers = resultF;
534  result.BadApvs = resultA;
535  BadComponentVect.push_back(result);
536  }
537  }
538  }
539 }
540 
541 //--------------------------------------------------------------//
542 
543 bool SiStripQuality::IsModuleUsable(uint32_t detid) const {
544  std::vector<BadComponent>::const_iterator p = std::lower_bound(
546  if (p != BadComponentVect.end() && p->detid == detid)
547  if (p->BadModule)
548  return false;
549 
550  if (SiStripDetCabling_ != nullptr)
551  if (!SiStripDetCabling_->IsConnected(detid))
552  return false;
553 
554  return true;
555 }
556 
557 bool SiStripQuality::IsModuleBad(uint32_t detid) const {
558  std::vector<BadComponent>::const_iterator p = std::lower_bound(
560  if (p != BadComponentVect.end() && p->detid == detid)
561  return p->BadModule;
562  return false;
563 }
564 
565 bool SiStripQuality::IsFiberBad(uint32_t detid, short fiberNb) const {
566  std::vector<BadComponent>::const_iterator p = std::lower_bound(
568  if (p != BadComponentVect.end() && p->detid == detid)
569  return ((p->BadFibers >> fiberNb) & 0x1);
570  return false;
571 }
572 
573 bool SiStripQuality::IsApvBad(uint32_t detid, short apvNb) const {
574  std::vector<BadComponent>::const_iterator p = std::lower_bound(
576  if (p != BadComponentVect.end() && p->detid == detid)
577  return ((p->BadApvs >> apvNb) & 0x1);
578  return false;
579 }
580 
581 bool SiStripQuality::IsStripBad(uint32_t detid, short strip) const {
583  return IsStripBad(range, strip);
584 }
585 
586 bool SiStripQuality::IsStripBad(const Range &range, short strip) const {
587  bool result = false;
589  for (SiStripBadStrip::ContainerIterator it = range.first; it != range.second; ++it) {
590  fs = decode(*it);
591  if ((fs.firstStrip <= strip) & (strip < fs.firstStrip + fs.range)) {
592  result = true;
593  break;
594  }
595  }
596  return result;
597 }
598 
600  int result = 0;
602  for (SiStripBadStrip::ContainerIterator it = range.first; it != range.second; ++it) {
603  fs = decode(*it);
604  if (fs.firstStrip <= strip && strip < fs.firstStrip + fs.range) {
605  result = strip - fs.firstStrip + 1;
606  break;
607  }
608  }
609  return result;
610 }
611 
613  int result = 0;
615  for (SiStripBadStrip::ContainerIterator it = range.first; it != range.second; ++it) {
616  fs = decode(*it);
617  if (fs.firstStrip <= strip && strip < fs.firstStrip + fs.range) {
618  result = fs.firstStrip + fs.range - strip;
619  break;
620  }
621  }
622  return result;
623 }
624 
625 short SiStripQuality::getBadApvs(uint32_t detid) const {
626  std::vector<BadComponent>::const_iterator p = std::lower_bound(
628  if (p != BadComponentVect.end() && p->detid == detid)
629  return p->BadApvs;
630  return 0;
631 }
632 
633 short SiStripQuality::getBadFibers(uint32_t detid) const {
634  std::vector<BadComponent>::const_iterator p = std::lower_bound(
636  if (p != BadComponentVect.end() && p->detid == detid)
637  return p->BadFibers;
638  return 0;
639 }
640 
642  uint32_t detId,
643  uint32_t apvPairNumber,
644  std::stringstream &ss) {
645  std::string subDetName;
646  DetId detid(detId);
647  int layer = tTopo->layer(detid);
648  int stereo = 0;
649  switch (detid.subdetId()) {
650  case StripSubdetector::TIB: {
651  stereo = tTopo->tibIsStereo(detid);
652  subDetName = "TIB";
653  break;
654  }
655  case StripSubdetector::TOB: {
656  stereo = tTopo->tobIsStereo(detid);
657  subDetName = "TOB";
658  break;
659  }
660  case StripSubdetector::TEC: {
661  stereo = tTopo->tecIsStereo(detid);
662  subDetName = "TEC";
663  break;
664  }
665  case StripSubdetector::TID: {
666  stereo = tTopo->tidIsStereo(detid);
667  subDetName = "TID";
668  break;
669  }
670  }
671  ss << detId << " and apv = " << apvPairNumber << " of subDet = " << subDetName << ", layer = " << layer
672  << " stereo = " << stereo << std::endl;
673 }
674 
675 void SiStripQuality::printActiveFedsInfo(const std::vector<uint16_t> &activeFedsFromCabling,
676  const std::vector<int> &activeFedsFromRunInfo,
677  const std::vector<int> &differentFeds,
678  const bool printDebug) {
679  std::ostringstream ss;
680 
681  if (printDebug) {
682  ss << "activeFedsFromCabling:" << std::endl;
683  std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(ss, " "));
684  ss << std::endl;
685  ss << "activeFedsFromRunInfo:" << std::endl;
686  std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(ss, " "));
687  ss << std::endl;
688  }
689  if (differentFeds.size() != 440) {
690  ss << "differentFeds : " << std::endl;
691  std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(ss, " "));
692  ss << std::endl;
693  } else {
694  ss << "There are 440 feds (all) active for Cabling but off for RunInfo. "
695  "Tracker was probably not in this run"
696  << std::endl;
697  }
698  edm::LogInfo("SiStripQuality") << ss.str() << std::endl;
699 }
700 
701 void SiStripQuality::turnOffFeds(const std::vector<int> &fedsList, const bool turnOffStrips, const bool printDebug) {
702  std::stringstream ss;
703  if (printDebug) {
704  ss << "associated to detIds : " << std::endl;
705  }
706 
707  std::vector<int>::const_iterator fedIdIt = fedsList.begin();
708  for (; fedIdIt != fedsList.end(); ++fedIdIt) {
709  std::vector<FedChannelConnection>::const_iterator fedChIt =
710  SiStripDetCabling_->fedCabling()->fedConnections(*fedIdIt).begin();
711  for (; fedChIt != SiStripDetCabling_->fedCabling()->fedConnections(*fedIdIt).end(); ++fedChIt) {
712  uint32_t detId = fedChIt->detId();
713  if (detId == 0 || detId == 0xFFFFFFFF)
714  continue;
715  uint16_t apvPairNumber = fedChIt->apvPairNumber();
716 
717  if (printDebug) {
718  printDetInfo(SiStripDetCabling_->trackerTopology(), detId, apvPairNumber, ss);
719  }
720 
721  if (turnOffStrips) {
722  // apvPairNumber == i it means that the i*256 strips are to be set off
723  std::vector<unsigned int> vect;
724  vect.push_back(encode(apvPairNumber * 256, 256));
725  SiStripBadStrip::Range Range(vect.begin(), vect.end());
726  add(detId, Range);
727  LogTrace("SiStripQuality") << "[addOffForRunInfo] adding apvPairNumber " << apvPairNumber << " for detId "
728  << detId << " off according to RunInfo" << std::endl;
729  }
730  }
731  }
732  if (printDebug) {
733  edm::LogInfo("SiStripQuality") << ss.str() << std::endl;
734  }
735 }
unsigned short range
void getDetIds(std::vector< uint32_t > &DetIds_) const
static constexpr auto TEC
ContainerIterator getDataVectorBegin() const
bool cleanUp(bool force=false)
bool IsApvBad(uint32_t detid, short apvNb) const
Definition: APVGainStruct.h:7
void addInvalidConnectionFromCabling()
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
short getBadFibers(uint32_t detid) const
std::vector< unsigned int >::const_iterator ContainerIterator
base
Main Program
Definition: newFWLiteAna.py:92
bool IsModuleBad(uint32_t detid) const
Registry::const_iterator RegistryIterator
SiStripQuality()=delete
bool IsConnected(const uint32_t &det_id) const
const Range getRange(const uint32_t detID) const
void add(uint32_t, const SiStripBadStrip::Range &)
bool tibIsStereo(const DetId &id) const
std::vector< BadComponent > BadComponentVect
unsigned int layer(const DetId &id) const
#define LogTrace(id)
constexpr std::array< uint8_t, layerIndexSize > layer
static std::string const input
Definition: EdmProvDump.cc:50
bool tobIsStereo(const DetId &id) const
void subtract(std::vector< unsigned int > &, const std::vector< unsigned int > &)
const SiStripFedCabling * fedCabling() const
SiStripDetInfo info_
const SiStripDetCabling * SiStripDetCabling_
void compact(uint32_t detid, std::vector< unsigned int > &)
RegistryIterator getRegistryVectorEnd() const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
static constexpr auto TOB
int nBadStripsOnTheLeft(const Range &range, short strip) const
void subtraction(std::vector< unsigned int > &, const unsigned int &)
void fillBadComponents()
Log< level::Info, false > LogInfo
Definition: DetId.h:17
static constexpr auto TIB
unsigned short firstStrip
Container v_badstrips
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
int nBadStripsOnTheRight(const Range &range, short strip) const
bool IsStripBad(uint32_t detid, short strip) const
void printDetInfo(const TrackerTopology *const tTopo, uint32_t detId, uint32_t apvPairNumber, std::stringstream &ss)
Prints debug output for a given detId.
static const uint16_t invalid_
Definition: Constants.h:16
bool tecIsStereo(const DetId &id) const
SiStripQuality difference(const SiStripQuality &) const
bool put_replace(uint32_t detId, Range input)
bool tidIsStereo(const DetId &id) const
const std::map< uint32_t, DetInfo > & getAllData() const noexcept
std::pair< ContainerIterator, ContainerIterator > Range
void turnOffFeds(const std::vector< int > &fedsList, const bool turnOffStrips, const bool printDebug)
data decode(const unsigned int &value) const
const TrackerTopology *const trackerTopology() const
Definition: APVGainStruct.h:7
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
bool IsModuleUsable(uint32_t detid) const
FedsConstIterRange fedIds() const
static constexpr auto TID
bool IsFiberBad(uint32_t detid, short fiberNb) const
RegistryIterator getRegistryVectorBegin() const
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)
const uint16_t nApvPairs(uint32_t det_id) const
def move(src, dest)
Definition: eostools.py:511
ConnsConstIterRange fedConnections(uint16_t fed_id) const
void addActiveDetectorsRawIds(std::vector< uint32_t > &) const
void ReduceGranularity(double)
short getBadApvs(uint32_t detid) const