17 #include <boost/bind.hpp>
18 #include <boost/function.hpp>
22 FileInPath_(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
23 SiStripDetCabling_(
NULL),
25 useEmptyRunInfo_(
false)
61 std::vector<unsigned int> ovect,vect;
63 unsigned short Nstrips;
74 if (range.first!=range.second){
81 if(orange.second-orange.first!=1
83 || data_.
range<Nstrips){
85 ovect.insert(ovect.end(),orange.first,orange.second);
86 vect.insert(vect.end(),range.first,range.second);
91 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
114 std::vector<unsigned int> vect;
119 std::vector<uint32_t> vdets;
121 std::vector<uint32_t>::const_iterator iter=vdets.begin();
122 std::vector<uint32_t>::const_iterator iterEnd=vdets.end();
124 for(;iter!=iterEnd;++iter){
127 LogTrace(
"SiStripQuality") <<
"[add Voff] add detid " << *iter <<
" first strip " << firstStrip <<
" range " << range << std::endl;
128 vect.push_back(
encode(firstStrip,range));
136 bool allFedsEmpty = runInfo->
m_fed_in.empty();
138 std::stringstream ss;
139 ss <<
"WARNING: the full list of feds in RunInfo is empty. ";
141 ss <<
" SiStripQuality will still use it and all tracker will be off." << std::endl;
144 ss <<
" SiStripQuality will not use it." << std::endl;
154 std::vector<int> activeFedsFromRunInfo;
156 std::remove_copy_if( runInfo->
m_fed_in.begin(),
158 std::back_inserter(activeFedsFromRunInfo),
159 !boost::bind(std::logical_and<bool>(),
167 std::sort(activeFedsFromCabling.begin(), activeFedsFromCabling.end());
168 std::sort(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end());
169 std::vector<int> differentFeds;
171 std::set_difference(activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
172 activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
173 std::back_inserter(differentFeds));
184 std::vector<int>
check;
185 std::set_difference(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
186 activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
187 std::back_inserter(check));
189 if( !check.empty() ) {
192 <<
"The cabling should always include the active feds in runInfo and possibly have some more"
193 <<
"there are instead " << check.size() <<
" feds only active in runInfo";
210 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > allData =
reader->
getAllData();
211 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator iter=allData.begin();
212 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator iterEnd=allData.end();
213 std::vector<unsigned int> vect;
216 for(;iter!=iterEnd;++iter)
219 range=iter->second.nApvs*128;
220 LogTrace(
"SiStripQuality") <<
"[addNotConnectedConnectionFromCabling] add detid " << iter->first << std::endl;
221 vect.push_back(
encode(firstStrip,range));
229 std::vector<uint32_t> 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){
236 std::vector<FedChannelConnection>::const_iterator itconns=fedconns.begin();
237 std::vector<FedChannelConnection>::const_iterator itconnsEnd=fedconns.end();
240 short ngoodConn=0, goodConn=0;
241 for(;itconns!=itconnsEnd;++itconns){
246 goodConn = goodConn | ( 0x1 << itconns->apvPairNumber() );
249 if (ngoodConn!=nApvPairs){
250 std::vector<unsigned int> vect;
251 for (
size_t idx=0;idx<nApvPairs;++idx){
252 if( !(goodConn & ( 0x1 << idx)) ) {
253 short firstStrip=idx*256;
255 LogTrace(
"SiStripQuality") <<
"[addInvalidConnectionFromCabling] add detid " <<*itdet <<
"firstStrip " << firstStrip<< std::endl;
256 vect.push_back(
encode(firstStrip,range));
275 uint32_t
detid=basep->detid;
276 LogTrace(
"SiStripQuality") <<
"add detid " <<detid << std::endl;
280 add(detid,baserange);
286 std::vector<unsigned int> vect,
tmp;
295 if (range.first==range.second){
296 LogTrace(
"SiStripQuality") <<
"new detid" << std::endl;
298 tmp.insert(tmp.end(),baserange.first,baserange.second);
299 std::stable_sort(tmp.begin(),tmp.end());
300 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
302 LogTrace(
"SiStripQuality") <<
"already exists" << std::endl;
307 if(range.second-range.first==1
309 && data_.
range>=Nstrips){
314 tmp.insert(tmp.end(),baserange.first,baserange.second);
315 tmp.insert(tmp.end(),range.first,range.second);
316 std::stable_sort(tmp.begin(),tmp.end());
317 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
323 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
328 std::vector<unsigned int>
tmp=vect;
330 std::stable_sort(tmp.begin(),tmp.end());
340 size_t sd= input.second-input.first;
342 detregistry.
detid=DetId;
348 if (p!=
indexes.end() && p->detid==DetId){
349 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::put_replace] Replacing SiStripQuality for already stored DetID " << DetId << std::endl;
370 uint16_t BadStripPerApv[6], ipos;
371 std::vector<unsigned int> vect;
373 for (; rp != rend; ++rp) {
374 uint32_t
detid=rp->detid;
376 BadStripPerApv[0]=0; BadStripPerApv[1]=0; BadStripPerApv[2]=0; BadStripPerApv[3]=0; BadStripPerApv[4]=0; BadStripPerApv[5]=0;
381 for(
int it=0;it<sqrange.second-sqrange.first;it++){
383 data_=
decode( *(sqrange.first+it) );
384 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] detid " << detid <<
" first strip " << data_.
firstStrip <<
" lastStrip " << data_.
firstStrip+data_.
range-1 <<
" range " << data_.
range;
393 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] Total for detid " << detid <<
" values " << BadStripPerApv[0] <<
" " << BadStripPerApv[1] <<
" " << BadStripPerApv[2] <<
" " <<BadStripPerApv[3] <<
" " <<BadStripPerApv[4] <<
" " << BadStripPerApv[5];
397 for(
size_t i=0;
i<6;++
i){
398 if (BadStripPerApv[
i]>=threshold*128){
399 vect.push_back(
encode(
i*128,128));
425 for(;it!=tmp.end();++it){
453 for(;it!=itend;++it){
461 std::vector<unsigned int>
tmp;
466 for(;jt!=jtend;++jt){
497 std::vector<unsigned int> v_badstrips_tmp=
v_badstrips;
498 std::vector<DetRegistry> indexes_tmp=
indexes;
500 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] before cleanUp v_badstrips.size()= " <<
v_badstrips.size() <<
" indexes.size()=" <<
indexes.size() << std::endl;
509 if(basep->ibegin!=basep->iend){
510 SiStripBadStrip::Range range( v_badstrips_tmp.begin()+basep->ibegin, v_badstrips_tmp.begin()+basep->iend );
511 if ( !
put(basep->detid,range) )
512 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
516 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " <<
v_badstrips.size() <<
" indexes.size()=" <<
indexes.size() << std::endl;
529 unsigned short resultA=0, resultF=0;
536 fs=
decode(*(range.first));
537 if (basep->iend - basep->ibegin == 1 &&
540 result.
detid=basep->detid;
543 result.
BadApvs=(1<< (Nstrips/128))-1;
554 for(
short apvNb=0;apvNb<6;++apvNb){
556 resultA=resultA | (1<<apvNb);
560 for(
short fiberNb=0;fiberNb<3;++fiberNb){
562 resultF=resultF | (1<<fiberNb);
567 result.
detid=basep->detid;
605 return ((p->BadFibers>>fiberNb)&0x1);
613 return ((p->BadApvs>>apvNb)&0x1);
685 std::string subDetName;
691 layer = theTIBDetId.
layer();
692 stereo = theTIBDetId.stereo();
699 layer = theTOBDetId.
layer();
700 stereo = theTOBDetId.stereo();
708 layer = theTECDetId.
wheel();
709 stereo = theTECDetId.stereo();
717 layer = theTIDDetId.
wheel();
718 stereo = theTIDDetId.stereo();
723 ss << detId <<
" and apv = " << apvPairNumber <<
" of subDet = " << subDetName <<
", layer = " << layer <<
" stereo = " << stereo << std::endl;
727 const std::vector<int> & activeFedsFromRunInfo,
728 const std::vector<int> & differentFeds,
731 std::ostringstream ss;
734 ss <<
"activeFedsFromCabling:" << std::endl;
735 std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(ss,
" "));
737 ss <<
"activeFedsFromRunInfo:" << std::endl;
738 std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(ss,
" "));
741 if( differentFeds.size() != 440 ) {
742 ss <<
"differentFeds : " << std::endl;
743 std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(ss,
" "));
747 ss <<
"There are 440 feds (all) active for Cabling but off for RunInfo. Tracker was probably not in this run" << std::endl;
749 edm::LogInfo(
"SiStripQuality") << ss.str() << std::endl;
755 std::stringstream ss;
757 ss <<
"associated to detIds : " << std::endl;
760 std::vector<int>::const_iterator fedIdIt = fedsList.begin();
761 for( ; fedIdIt != fedsList.end(); ++fedIdIt ) {
764 uint32_t detId = fedChIt->detId();
765 if (detId == 0 || detId == 0xFFFFFFFF)
continue;
766 uint16_t apvPairNumber = fedChIt->apvPairNumber();
772 if( turnOffStrips ) {
774 std::vector<unsigned int> vect;
775 vect.push_back(
encode(apvPairNumber*256,256));
778 LogTrace(
"SiStripQuality") <<
"[addOffForRunInfo] adding apvPairNumber "<<apvPairNumber<<
" for detId "<<detId<<
" off according to RunInfo" << std::endl;
783 edm::LogInfo(
"SiStripQuality") << ss.str() << std::endl;
bool IsApvBad(const uint32_t &detid, const short &apvNb) const
bool IsFiberBad(const uint32_t &detid, const short &fiberNb) const
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
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
bool operator!=(const SiStripQuality &) const
bool IsConnected(const uint32_t &det_id) const
tuple SiStripDetInfoFileReader
Registry::const_iterator RegistryIterator
std::vector< BadComponent > BadComponentVect
uint32_t rawId() const
get the raw id
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
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
void compact(unsigned int &, std::vector< unsigned int > &)
const SiStripDetCabling * SiStripDetCabling_
const std::vector< FedChannelConnection > & getConnections(uint32_t det_id) const
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's numbering enum) ...
SiStripQuality & operator+=(const SiStripQuality &)
const SiStripQuality operator-(const SiStripQuality &) const
bool put_replace(const uint32_t &DetId, Range input)
ContainerIterator getDataVectorBegin() const
const SiStripFedCabling * fedCabling() const
unsigned short firstStrip
const Range getRange(const uint32_t &detID) const
static const uint16_t invalid_
unsigned int wheel() const
wheel id
int nBadStripsOnTheLeft(const Range &range, const short &strip) const
unsigned int layer() const
layer id
RegistryIterator getRegistryVectorBegin() const
const uint16_t nApvPairs(uint32_t det_id) const
std::vector< std::vector< double > > tmp
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
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)