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