test
CMS 3D CMS Logo

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