20 #include <boost/bind.hpp>
21 #include <boost/function.hpp>
25 FileInPath_(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
26 SiStripDetCabling_(
NULL),
28 useEmptyRunInfo_(
false)
52 LogTrace(
"SiStripQuality") <<
"SiStripQuality destructor" << std::endl;
69 std::vector<unsigned int> ovect,vect;
71 unsigned short Nstrips;
82 if (range.first!=range.second){
89 if(orange.second-orange.first!=1
91 || data_.
range<Nstrips){
93 ovect.insert(ovect.end(),orange.first,orange.second);
94 vect.insert(vect.end(),range.first,range.second);
99 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
122 std::vector<unsigned int> vect;
127 std::vector<uint32_t> vdets;
129 std::vector<uint32_t>::const_iterator
iter=vdets.begin();
130 std::vector<uint32_t>::const_iterator iterEnd=vdets.end();
132 for(;iter!=iterEnd;++
iter){
135 LogTrace(
"SiStripQuality") <<
"[add Voff] add detid " << *iter <<
" first strip " << firstStrip <<
" range " << range << std::endl;
136 vect.push_back(
encode(firstStrip,range));
144 bool allFedsEmpty = runInfo->
m_fed_in.empty();
146 std::stringstream
ss;
147 ss <<
"WARNING: the full list of feds in RunInfo is empty. ";
149 ss <<
" SiStripQuality will still use it and all tracker will be off." << std::endl;
152 ss <<
" SiStripQuality will not use it." << std::endl;
161 std::vector<uint16_t> activeFedsFromCabling(ids.begin(), ids.end());
163 std::vector<int> activeFedsFromRunInfo;
165 std::remove_copy_if( runInfo->
m_fed_in.begin(),
167 std::back_inserter(activeFedsFromRunInfo),
168 !boost::bind(std::logical_and<bool>(),
176 std::sort(activeFedsFromCabling.begin(), activeFedsFromCabling.end());
177 std::sort(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end());
178 std::vector<int> differentFeds;
180 std::set_difference(activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
181 activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
182 std::back_inserter(differentFeds));
194 std::vector<int>
check;
195 std::set_difference(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
196 activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
197 std::back_inserter(check));
199 if( !check.empty() ) {
202 <<
"The cabling should always include the active feds in runInfo and possibly have some more"
203 <<
"there are instead " << check.size() <<
" feds only active in runInfo";
220 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > allData =
reader->
getAllData();
221 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator
iter=allData.begin();
222 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator iterEnd=allData.end();
223 std::vector<unsigned int> vect;
226 for(;iter!=iterEnd;++
iter)
229 range=iter->second.nApvs*128;
230 LogTrace(
"SiStripQuality") <<
"[addNotConnectedConnectionFromCabling] add detid " << iter->first << std::endl;
231 vect.push_back(
encode(firstStrip,range));
239 std::vector<uint32_t> connected_detids;
241 std::vector<uint32_t>::const_iterator itdet = connected_detids.begin();
242 std::vector<uint32_t>::const_iterator itdetEnd = connected_detids.end();
243 for(;itdet!=itdetEnd;++itdet){
246 std::vector<const FedChannelConnection *>::const_iterator itconns=fedconns.begin();
247 std::vector<const FedChannelConnection *>::const_iterator itconnsEnd=fedconns.end();
250 short ngoodConn=0, goodConn=0;
251 for(;itconns!=itconnsEnd;++itconns){
256 goodConn = goodConn | ( 0x1 << (*itconns)->apvPairNumber() );
259 if (ngoodConn!=nApvPairs){
260 std::vector<unsigned int> vect;
262 if( !(goodConn & ( 0x1 <<
idx)) ) {
263 short firstStrip=
idx*256;
265 LogTrace(
"SiStripQuality") <<
"[addInvalidConnectionFromCabling] add detid " <<*itdet <<
"firstStrip " << firstStrip<< std::endl;
266 vect.push_back(
encode(firstStrip,range));
285 uint32_t
detid=basep->detid;
286 LogTrace(
"SiStripQuality") <<
"add detid " <<detid << std::endl;
290 add(detid,baserange);
296 std::vector<unsigned int> vect,
tmp;
305 if (range.first==range.second){
306 LogTrace(
"SiStripQuality") <<
"new detid" << std::endl;
308 tmp.insert(tmp.end(),baserange.first,baserange.second);
309 std::stable_sort(tmp.begin(),tmp.end());
310 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
312 LogTrace(
"SiStripQuality") <<
"already exists" << std::endl;
317 if(range.second-range.first==1
319 && data_.
range>=Nstrips){
324 tmp.insert(tmp.end(),baserange.first,baserange.second);
325 tmp.insert(tmp.end(),range.first,range.second);
326 std::stable_sort(tmp.begin(),tmp.end());
327 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
333 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
338 std::vector<unsigned int>
tmp=vect;
340 std::stable_sort(tmp.begin(),tmp.end());
350 size_t sd= input.second-input.first;
352 detregistry.
detid=DetId;
358 if (p!=
indexes.end() && p->detid==DetId){
359 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::put_replace] Replacing SiStripQuality for already stored DetID " << DetId << std::endl;
380 uint16_t BadStripPerApv[6], ipos;
381 std::vector<unsigned int> vect;
383 for (; rp != rend; ++rp) {
384 uint32_t
detid=rp->detid;
386 BadStripPerApv[0]=0; BadStripPerApv[1]=0; BadStripPerApv[2]=0; BadStripPerApv[3]=0; BadStripPerApv[4]=0; BadStripPerApv[5]=0;
391 for(
int it=0;it<sqrange.second-sqrange.first;it++){
393 data_=
decode( *(sqrange.first+it) );
394 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] detid " << detid <<
" first strip " << data_.
firstStrip <<
" lastStrip " << data_.
firstStrip+data_.
range-1 <<
" range " << data_.
range;
403 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] Total for detid " << detid <<
" values " << BadStripPerApv[0] <<
" " << BadStripPerApv[1] <<
" " << BadStripPerApv[2] <<
" " <<BadStripPerApv[3] <<
" " <<BadStripPerApv[4] <<
" " << BadStripPerApv[5];
407 for(
size_t i=0;
i<6;++
i){
408 if (BadStripPerApv[
i]>=threshold*128){
409 vect.push_back(
encode(
i*128,128));
435 for(;it!=tmp.end();++it){
463 for(;it!=itend;++it){
471 std::vector<unsigned int>
tmp;
476 for(;jt!=jtend;++jt){
507 std::vector<unsigned int> v_badstrips_tmp=
v_badstrips;
508 std::vector<DetRegistry> indexes_tmp=
indexes;
510 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] before cleanUp v_badstrips.size()= " <<
v_badstrips.size() <<
" indexes.size()=" <<
indexes.size() << std::endl;
519 if(basep->ibegin!=basep->iend){
520 SiStripBadStrip::Range range( v_badstrips_tmp.begin()+basep->ibegin, v_badstrips_tmp.begin()+basep->iend );
521 if ( !
put(basep->detid,range) )
522 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
526 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " <<
v_badstrips.size() <<
" indexes.size()=" <<
indexes.size() << std::endl;
539 unsigned short resultA=0, resultF=0;
546 fs=
decode(*(range.first));
547 if (basep->iend - basep->ibegin == 1 &&
550 result.
detid=basep->detid;
553 result.
BadApvs=(1<< (Nstrips/128))-1;
564 for(
short apvNb=0;apvNb<6;++apvNb){
566 resultA=resultA | (1<<apvNb);
570 for(
short fiberNb=0;fiberNb<3;++fiberNb){
572 resultF=resultF | (1<<fiberNb);
577 result.
detid=basep->detid;
615 return ((p->BadFibers>>fiberNb)&0x1);
623 return ((p->BadApvs>>apvNb)&0x1);
701 layer = theTIBDetId.
layer();
702 stereo = theTIBDetId.stereo();
709 layer = theTOBDetId.
layer();
710 stereo = theTOBDetId.stereo();
718 layer = theTECDetId.
wheel();
719 stereo = theTECDetId.stereo();
727 layer = theTIDDetId.
wheel();
728 stereo = theTIDDetId.stereo();
733 ss << detId <<
" and apv = " << apvPairNumber <<
" of subDet = " << subDetName <<
", layer = " << layer <<
" stereo = " << stereo << std::endl;
737 const std::vector<int> & activeFedsFromRunInfo,
738 const std::vector<int> & differentFeds,
741 std::ostringstream
ss;
744 ss <<
"activeFedsFromCabling:" << std::endl;
745 std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(
ss,
" "));
747 ss <<
"activeFedsFromRunInfo:" << std::endl;
748 std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(
ss,
" "));
751 if( differentFeds.size() != 440 ) {
752 ss <<
"differentFeds : " << std::endl;
753 std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(
ss,
" "));
757 ss <<
"There are 440 feds (all) active for Cabling but off for RunInfo. Tracker was probably not in this run" << std::endl;
759 edm::LogInfo(
"SiStripQuality") << ss.str() << std::endl;
765 std::stringstream
ss;
767 ss <<
"associated to detIds : " << std::endl;
770 std::vector<int>::const_iterator fedIdIt = fedsList.begin();
771 for( ; fedIdIt != fedsList.end(); ++fedIdIt ) {
774 uint32_t detId = fedChIt->detId();
775 if (detId == 0 || detId == 0xFFFFFFFF)
continue;
776 uint16_t apvPairNumber = fedChIt->apvPairNumber();
782 if( turnOffStrips ) {
784 std::vector<unsigned int> vect;
785 vect.push_back(
encode(apvPairNumber*256,256));
788 LogTrace(
"SiStripQuality") <<
"[addOffForRunInfo] adding apvPairNumber "<<apvPairNumber<<
" for detId "<<detId<<
" off according to RunInfo" << std::endl;
793 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
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
Registry::const_iterator RegistryIterator
std::vector< BadComponent > BadComponentVect
static std::string const input
uint32_t rawId() const
get the raw id
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
void getDetIds(std::vector< uint32_t > &DetIds_) const
std::vector< int > m_fed_in
FedsConstIterRange fedIds() const
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
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'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
tuple SiStripDetInfoFileReader
const SiStripFedCabling * fedCabling() const
unsigned short firstStrip
tuple idx
DEBUGGING if hasattr(process,"trackMonIterativeTracking2012"): print "trackMonIterativeTracking2012 D...
static const uint16_t invalid_
ConnsConstIterRange fedConnections(uint16_t fed_id) const
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
const Range getRange(const uint32_t detID) const
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
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)