21 #include <boost/bind.hpp>
22 #include <boost/function.hpp>
26 FileInPath_(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
27 SiStripDetCabling_(
NULL),
29 useEmptyRunInfo_(
false)
53 LogTrace(
"SiStripQuality") <<
"SiStripQuality destructor" << std::endl;
70 std::vector<unsigned int> ovect,vect;
72 unsigned short Nstrips;
83 if (range.first!=range.second){
90 if(orange.second-orange.first!=1
92 || data_.
range<Nstrips){
94 ovect.insert(ovect.end(),orange.first,orange.second);
95 vect.insert(vect.end(),range.first,range.second);
100 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
123 std::vector<unsigned int> vect;
128 std::vector<uint32_t> vdets;
130 std::vector<uint32_t>::const_iterator iter=vdets.begin();
131 std::vector<uint32_t>::const_iterator iterEnd=vdets.end();
133 for(;iter!=iterEnd;++iter){
136 LogTrace(
"SiStripQuality") <<
"[add Voff] add detid " << *iter <<
" first strip " << firstStrip <<
" range " << range << std::endl;
137 vect.push_back(
encode(firstStrip,range));
145 bool allFedsEmpty = runInfo->
m_fed_in.empty();
147 std::stringstream ss;
148 ss <<
"WARNING: the full list of feds in RunInfo is empty. ";
150 ss <<
" SiStripQuality will still use it and all tracker will be off." << std::endl;
153 ss <<
" SiStripQuality will not use it." << std::endl;
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));
193 std::vector<int>
check;
194 std::set_difference(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
195 activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
196 std::back_inserter(check));
198 if( !check.empty() ) {
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";
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;
225 for(;iter!=iterEnd;++iter)
228 range=iter->second.nApvs*128;
229 LogTrace(
"SiStripQuality") <<
"[addNotConnectedConnectionFromCabling] add detid " << iter->first << std::endl;
230 vect.push_back(
encode(firstStrip,range));
238 std::vector<uint32_t> 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){
245 std::vector<const FedChannelConnection *>::const_iterator itconns=fedconns.begin();
246 std::vector<const FedChannelConnection *>::const_iterator itconnsEnd=fedconns.end();
249 short ngoodConn=0, goodConn=0;
250 for(;itconns!=itconnsEnd;++itconns){
255 goodConn = goodConn | ( 0x1 << (*itconns)->apvPairNumber() );
258 if (ngoodConn!=nApvPairs){
259 std::vector<unsigned int> vect;
261 if( !(goodConn & ( 0x1 <<
idx)) ) {
262 short firstStrip=
idx*256;
264 LogTrace(
"SiStripQuality") <<
"[addInvalidConnectionFromCabling] add detid " <<*itdet <<
"firstStrip " << firstStrip<< std::endl;
265 vect.push_back(
encode(firstStrip,range));
284 uint32_t
detid=basep->detid;
285 LogTrace(
"SiStripQuality") <<
"add detid " <<detid << std::endl;
289 add(detid,baserange);
295 std::vector<unsigned int> vect,
tmp;
304 if (range.first==range.second){
305 LogTrace(
"SiStripQuality") <<
"new detid" << std::endl;
307 tmp.insert(tmp.end(),baserange.first,baserange.second);
308 std::stable_sort(tmp.begin(),tmp.end());
309 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
311 LogTrace(
"SiStripQuality") <<
"already exists" << std::endl;
316 if(range.second-range.first==1
318 && data_.
range>=Nstrips){
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;
332 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
337 std::vector<unsigned int>
tmp=vect;
339 std::stable_sort(tmp.begin(),tmp.end());
349 size_t sd= input.second-input.first;
351 detregistry.
detid=DetId;
357 if (p!=
indexes.end() && p->detid==DetId){
358 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::put_replace] Replacing SiStripQuality for already stored DetID " << DetId << std::endl;
379 uint16_t BadStripPerApv[6], ipos;
380 std::vector<unsigned int> vect;
382 for (; rp != rend; ++rp) {
383 uint32_t
detid=rp->detid;
385 BadStripPerApv[0]=0; BadStripPerApv[1]=0; BadStripPerApv[2]=0; BadStripPerApv[3]=0; BadStripPerApv[4]=0; BadStripPerApv[5]=0;
390 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 " << data_.
firstStrip <<
" lastStrip " << data_.
firstStrip+data_.
range-1 <<
" range " << data_.
range;
402 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] Total for detid " << detid <<
" values " << BadStripPerApv[0] <<
" " << BadStripPerApv[1] <<
" " << BadStripPerApv[2] <<
" " <<BadStripPerApv[3] <<
" " <<BadStripPerApv[4] <<
" " << BadStripPerApv[5];
406 for(
size_t i=0;
i<6;++
i){
407 if (BadStripPerApv[
i]>=threshold*128){
408 vect.push_back(
encode(
i*128,128));
434 for(;it!=tmp.end();++it){
462 for(;it!=itend;++it){
470 std::vector<unsigned int>
tmp;
475 for(;jt!=jtend;++jt){
506 std::vector<unsigned int> v_badstrips_tmp=
v_badstrips;
507 std::vector<DetRegistry> indexes_tmp=
indexes;
509 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] before cleanUp v_badstrips.size()= " <<
v_badstrips.size() <<
" indexes.size()=" <<
indexes.size() << std::endl;
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;
525 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " <<
v_badstrips.size() <<
" indexes.size()=" <<
indexes.size() << std::endl;
538 unsigned short resultA=0, resultF=0;
545 fs=
decode(*(range.first));
546 if (basep->iend - basep->ibegin == 1 &&
549 result.
detid=basep->detid;
552 result.
BadApvs=(1<< (Nstrips/128))-1;
563 for(
short apvNb=0;apvNb<6;++apvNb){
565 resultA=resultA | (1<<apvNb);
569 for(
short fiberNb=0;fiberNb<3;++fiberNb){
571 resultF=resultF | (1<<fiberNb);
576 result.
detid=basep->detid;
614 return ((p->BadFibers>>fiberNb)&0x1);
622 return ((p->BadApvs>>apvNb)&0x1);
700 layer = theTIBDetId.
layer();
701 stereo = theTIBDetId.stereo();
708 layer = theTOBDetId.
layer();
709 stereo = theTOBDetId.stereo();
717 layer = theTECDetId.
wheel();
718 stereo = theTECDetId.stereo();
726 layer = theTIDDetId.
wheel();
727 stereo = theTIDDetId.stereo();
732 ss << detId <<
" and apv = " << apvPairNumber <<
" of subDet = " << subDetName <<
", layer = " << layer <<
" stereo = " << stereo << std::endl;
736 const std::vector<int> & activeFedsFromRunInfo,
737 const std::vector<int> & differentFeds,
740 std::ostringstream ss;
743 ss <<
"activeFedsFromCabling:" << std::endl;
744 std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(ss,
" "));
746 ss <<
"activeFedsFromRunInfo:" << std::endl;
747 std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(ss,
" "));
750 if( differentFeds.size() != 440 ) {
751 ss <<
"differentFeds : " << std::endl;
752 std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(ss,
" "));
756 ss <<
"There are 440 feds (all) active for Cabling but off for RunInfo. Tracker was probably not in this run" << std::endl;
758 edm::LogInfo(
"SiStripQuality") << ss.str() << std::endl;
764 std::stringstream ss;
766 ss <<
"associated to detIds : " << std::endl;
769 std::vector<int>::const_iterator fedIdIt = fedsList.begin();
770 for( ; fedIdIt != fedsList.end(); ++fedIdIt ) {
773 uint32_t detId = fedChIt->detId();
774 if (detId == 0 || detId == 0xFFFFFFFF)
continue;
775 uint16_t apvPairNumber = fedChIt->apvPairNumber();
781 if( turnOffStrips ) {
783 std::vector<unsigned int> vect;
784 vect.push_back(
encode(apvPairNumber*256,256));
787 LogTrace(
"SiStripQuality") <<
"[addOffForRunInfo] adding apvPairNumber "<<apvPairNumber<<
" for detId "<<detId<<
" off according to RunInfo" << std::endl;
792 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
Registry::const_iterator RegistryIterator
std::vector< BadComponent > BadComponentVect
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
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_
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...
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)