18 #include <boost/bind.hpp> 19 #include <boost/function.hpp> 23 FileInPath_(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
24 SiStripDetCabling_(
NULL),
26 useEmptyRunInfo_(
false)
50 LogTrace(
"SiStripQuality") <<
"SiStripQuality destructor" << std::endl;
67 std::vector<unsigned int> ovect,vect;
69 unsigned short Nstrips;
80 if (range.first!=range.second){
87 if(orange.second-orange.first!=1
89 || data_.
range<Nstrips){
91 ovect.insert(ovect.end(),orange.first,orange.second);
92 vect.insert(vect.end(),range.first,range.second);
97 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
120 std::vector<unsigned int> vect;
125 std::vector<uint32_t> vdets;
127 std::vector<uint32_t>::const_iterator iter=vdets.begin();
128 std::vector<uint32_t>::const_iterator iterEnd=vdets.end();
130 for(;iter!=iterEnd;++iter){
133 LogTrace(
"SiStripQuality") <<
"[add Voff] add detid " << *iter <<
" first strip " << firstStrip <<
" range " << range << std::endl;
134 vect.push_back(
encode(firstStrip,range));
142 bool allFedsEmpty = runInfo->
m_fed_in.empty();
144 std::stringstream ss;
145 ss <<
"WARNING: the full list of feds in RunInfo is empty. ";
147 ss <<
" SiStripQuality will still use it and all tracker will be off." << std::endl;
150 ss <<
" SiStripQuality will not use it." << std::endl;
159 std::vector<uint16_t> activeFedsFromCabling(ids.begin(), ids.end());
161 std::vector<int> activeFedsFromRunInfo;
163 std::remove_copy_if( runInfo->
m_fed_in.begin(),
165 std::back_inserter(activeFedsFromRunInfo),
166 !boost::bind(std::logical_and<bool>(),
174 std::sort(activeFedsFromCabling.begin(), activeFedsFromCabling.end());
175 std::sort(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end());
176 std::vector<int> differentFeds;
178 std::set_difference(activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
179 activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
180 std::back_inserter(differentFeds));
192 std::vector<int>
check;
193 std::set_difference(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(),
194 activeFedsFromCabling.begin(), activeFedsFromCabling.end(),
195 std::back_inserter(check));
197 if( !check.empty() ) {
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";
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;
224 for(;iter!=iterEnd;++iter)
227 range=iter->second.nApvs*128;
228 LogTrace(
"SiStripQuality") <<
"[addNotConnectedConnectionFromCabling] add detid " << iter->first << std::endl;
229 vect.push_back(
encode(firstStrip,range));
237 std::vector<uint32_t> 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){
244 std::vector<const FedChannelConnection *>::const_iterator itconns=fedconns.begin();
245 std::vector<const FedChannelConnection *>::const_iterator itconnsEnd=fedconns.end();
248 short ngoodConn=0, goodConn=0;
249 for(;itconns!=itconnsEnd;++itconns){
254 goodConn = goodConn | ( 0x1 << (*itconns)->apvPairNumber() );
257 if (ngoodConn!=nApvPairs){
258 std::vector<unsigned int> vect;
260 if( !(goodConn & ( 0x1 <<
idx)) ) {
261 short firstStrip=
idx*256;
263 LogTrace(
"SiStripQuality") <<
"[addInvalidConnectionFromCabling] add detid " <<*itdet <<
"firstStrip " << firstStrip<< std::endl;
264 vect.push_back(
encode(firstStrip,range));
283 uint32_t detid=basep->detid;
284 LogTrace(
"SiStripQuality") <<
"add detid " <<detid << std::endl;
288 add(detid,baserange);
294 std::vector<unsigned int> vect,
tmp;
303 if (range.first==range.second){
304 LogTrace(
"SiStripQuality") <<
"new detid" << std::endl;
306 tmp.insert(tmp.end(),baserange.first,baserange.second);
307 std::stable_sort(tmp.begin(),tmp.end());
308 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
310 LogTrace(
"SiStripQuality") <<
"already exists" << std::endl;
315 if(range.second-range.first==1
317 && data_.
range>=Nstrips){
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;
331 edm::LogError(
"SiStripQuality")<<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
336 std::vector<unsigned int>
tmp=vect;
338 std::stable_sort(tmp.begin(),tmp.end());
348 size_t sd= input.second-input.first;
350 detregistry.
detid=DetId;
356 if (p!=
indexes.end() && p->detid==DetId){
357 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::put_replace] Replacing SiStripQuality for already stored DetID " << DetId << std::endl;
378 uint16_t BadStripPerApv[6], ipos;
379 std::vector<unsigned int> vect;
381 for (; rp != rend; ++rp) {
382 uint32_t detid=rp->detid;
384 BadStripPerApv[0]=0; BadStripPerApv[1]=0; BadStripPerApv[2]=0; BadStripPerApv[3]=0; BadStripPerApv[4]=0; BadStripPerApv[5]=0;
389 for(
int it=0;it<sqrange.second-sqrange.first;it++){
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;
401 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] Total for detid " << detid <<
" values " << BadStripPerApv[0] <<
" " << BadStripPerApv[1] <<
" " << BadStripPerApv[2] <<
" " <<BadStripPerApv[3] <<
" " <<BadStripPerApv[4] <<
" " << BadStripPerApv[5];
405 for(
size_t i=0;
i<6;++
i){
406 if (BadStripPerApv[
i]>=threshold*128){
407 vect.push_back(
encode(
i*128,128));
433 for(;it!=tmp.end();++it){
461 for(;it!=itend;++it){
469 std::vector<unsigned int>
tmp;
474 for(;jt!=jtend;++jt){
505 std::vector<unsigned int> v_badstrips_tmp=
v_badstrips;
506 std::vector<DetRegistry> indexes_tmp=
indexes;
508 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] before cleanUp v_badstrips.size()= " <<
v_badstrips.size() <<
" indexes.size()=" <<
indexes.size() << std::endl;
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;
524 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " <<
v_badstrips.size() <<
" indexes.size()=" <<
indexes.size() << std::endl;
537 unsigned short resultA=0, resultF=0;
544 fs=
decode(*(range.first));
545 if (basep->iend - basep->ibegin == 1 &&
548 result.
detid=basep->detid;
551 result.
BadApvs=(1<< (Nstrips/128))-1;
562 for(
short apvNb=0;apvNb<6;++apvNb){
564 resultA=resultA | (1<<apvNb);
568 for(
short fiberNb=0;fiberNb<3;++fiberNb){
570 resultF=resultF | (1<<fiberNb);
575 result.
detid=basep->detid;
613 return ((p->BadFibers>>fiberNb)&0x1);
621 return ((p->BadApvs>>apvNb)&0x1);
693 int layer = tTopo->
layer(detid);
721 ss << detId <<
" and apv = " << apvPairNumber <<
" of subDet = " << subDetName <<
", layer = " << layer <<
" stereo = " << stereo << std::endl;
725 const std::vector<int> & activeFedsFromRunInfo,
726 const std::vector<int> & differentFeds,
729 std::ostringstream ss;
732 ss <<
"activeFedsFromCabling:" << std::endl;
733 std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(ss,
" "));
735 ss <<
"activeFedsFromRunInfo:" << std::endl;
736 std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(ss,
" "));
739 if( differentFeds.size() != 440 ) {
740 ss <<
"differentFeds : " << std::endl;
741 std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(ss,
" "));
745 ss <<
"There are 440 feds (all) active for Cabling but off for RunInfo. Tracker was probably not in this run" << std::endl;
747 edm::LogInfo(
"SiStripQuality") << ss.str() << std::endl;
753 std::stringstream ss;
755 ss <<
"associated to detIds : " << std::endl;
758 std::vector<int>::const_iterator fedIdIt = fedsList.begin();
759 for( ; fedIdIt != fedsList.end(); ++fedIdIt ) {
762 uint32_t detId = fedChIt->detId();
763 if (detId == 0 || detId == 0xFFFFFFFF)
continue;
764 uint16_t apvPairNumber = fedChIt->apvPairNumber();
770 if( turnOffStrips ) {
772 std::vector<unsigned int> vect;
773 vect.push_back(
encode(apvPairNumber*256,256));
776 LogTrace(
"SiStripQuality") <<
"[addOffForRunInfo] adding apvPairNumber "<<apvPairNumber<<
" for detId "<<detId<<
" off according to RunInfo" << std::endl;
781 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
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
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
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
FedsConstIterRange fedIds() const
void compact(unsigned int &, std::vector< unsigned int > &)
const SiStripDetCabling * SiStripDetCabling_
bool IsModuleBad(const uint32_t &detid) const
base
Make Sure CMSSW is Setup ##.
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 &)
void printDebug(std::stringstream &ss) const
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
bool tibIsStereo(const DetId &id) const
static const uint16_t invalid_
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
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 &)
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)