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