19 FileInPath_(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
20 SiStripDetCabling_(nullptr),
22 useEmptyRunInfo_(
false) {
27 : toCleanUp(
false), FileInPath_(
file), SiStripDetCabling_(nullptr), printDebug_(
false), useEmptyRunInfo_(
false) {
44 LogTrace(
"SiStripQuality") <<
"SiStripQuality destructor" << std::endl;
58 std::vector<unsigned int> ovect, vect;
60 unsigned short Nstrips;
78 if (orange.second - orange.first != 1 || data_.
firstStrip != 0 || data_.
range < Nstrips) {
79 ovect.insert(ovect.end(), orange.first, orange.second);
80 vect.insert(vect.end(),
range.first,
range.second);
85 edm::LogError(
"SiStripQuality") <<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
99 return a.getRegistryVectorBegin() ==
a.getRegistryVectorEnd();
105 std::vector<unsigned int> vect;
106 short firstStrip = 0;
110 std::vector<uint32_t> vdets;
112 std::vector<uint32_t>::const_iterator iter = vdets.begin();
113 std::vector<uint32_t>::const_iterator iterEnd = vdets.end();
115 for (; iter != iterEnd; ++iter) {
118 LogTrace(
"SiStripQuality") <<
"[add Voff] add detid " << *iter <<
" first strip " << firstStrip <<
" range "
119 <<
range << std::endl;
127 bool allFedsEmpty =
runInfo->m_fed_in.empty();
129 std::stringstream
ss;
130 ss <<
"WARNING: the full list of feds in RunInfo is empty. ";
132 ss <<
" SiStripQuality will still use it and all tracker will be off." << std::endl;
134 ss <<
" SiStripQuality will not use it." << std::endl;
143 std::vector<uint16_t> activeFedsFromCabling(ids.begin(), ids.end());
145 std::vector<int> activeFedsFromRunInfo;
148 runInfo->m_fed_in.begin(),
runInfo->m_fed_in.end(), std::back_inserter(activeFedsFromRunInfo), [&](
int x) {
157 std::sort(activeFedsFromCabling.begin(), activeFedsFromCabling.end());
158 std::sort(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end());
159 std::vector<int> differentFeds;
161 std::set_difference(activeFedsFromCabling.begin(),
162 activeFedsFromCabling.end(),
163 activeFedsFromRunInfo.begin(),
164 activeFedsFromRunInfo.end(),
165 std::back_inserter(differentFeds));
179 std::vector<int>
check;
180 std::set_difference(activeFedsFromRunInfo.begin(),
181 activeFedsFromRunInfo.end(),
182 activeFedsFromCabling.begin(),
183 activeFedsFromCabling.end(),
184 std::back_inserter(
check));
186 if (!
check.empty()) {
188 edm::LogInfo(
"SiStripQuality") <<
"The cabling should always include the active feds in runInfo and "
189 "possibly have some more"
190 <<
"there are instead " <<
check.size() <<
" feds only active in runInfo";
206 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo> allData =
reader->
getAllData();
207 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator iter = allData.begin();
208 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator iterEnd = allData.end();
209 std::vector<unsigned int> vect;
210 short firstStrip = 0;
212 for (; iter != iterEnd; ++iter)
215 range = iter->second.nApvs * 128;
216 LogTrace(
"SiStripQuality") <<
"[addNotConnectedConnectionFromCabling] add detid " << iter->first << std::endl;
224 std::vector<uint32_t> connected_detids;
226 std::vector<uint32_t>::const_iterator itdet = connected_detids.begin();
227 std::vector<uint32_t>::const_iterator itdetEnd = connected_detids.end();
228 for (; itdet != itdetEnd; ++itdet) {
232 std::vector<const FedChannelConnection *>::const_iterator itconns = fedconns.begin();
233 std::vector<const FedChannelConnection *>::const_iterator itconnsEnd = fedconns.end();
236 short ngoodConn = 0, goodConn = 0;
237 for (; itconns != itconnsEnd; ++itconns) {
245 goodConn = goodConn | (0x1 << (*itconns)->apvPairNumber());
248 if (ngoodConn != nApvPairs) {
249 std::vector<unsigned int> vect;
250 for (
size_t idx = 0;
idx < nApvPairs; ++
idx) {
251 if (!(goodConn & (0
x1 <<
idx))) {
252 short firstStrip =
idx * 256;
254 LogTrace(
"SiStripQuality") <<
"[addInvalidConnectionFromCabling] add detid " << *itdet <<
"firstStrip "
255 << firstStrip << std::endl;
274 uint32_t detid = basep->detid;
275 LogTrace(
"SiStripQuality") <<
"add detid " << detid << std::endl;
280 add(detid, baserange);
285 std::vector<unsigned int> vect,
tmp;
295 LogTrace(
"SiStripQuality") <<
"new detid" << std::endl;
297 tmp.insert(
tmp.end(), baserange.first, baserange.second);
298 std::stable_sort(
tmp.begin(),
tmp.end());
299 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
301 LogTrace(
"SiStripQuality") <<
"already exists" << std::endl;
307 LogTrace(
"SiStripQuality") <<
"full det is bad.. " <<
range.second -
range.first <<
" "
314 tmp.insert(
tmp.end(), baserange.first, baserange.second);
316 std::stable_sort(
tmp.begin(),
tmp.end());
317 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
323 edm::LogError(
"SiStripQuality") <<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
327 std::vector<unsigned int>
tmp = vect;
329 std::stable_sort(
tmp.begin(),
tmp.end());
347 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::put_replace] Replacing "
348 "SiStripQuality for already stored DetID "
349 <<
DetId << std::endl;
369 uint16_t BadStripPerApv[6], ipos;
370 std::vector<unsigned int> vect;
372 for (; rp != rend; ++rp) {
373 uint32_t detid = rp->detid;
375 BadStripPerApv[0] = 0;
376 BadStripPerApv[1] = 0;
377 BadStripPerApv[2] = 0;
378 BadStripPerApv[3] = 0;
379 BadStripPerApv[4] = 0;
380 BadStripPerApv[5] = 0;
386 for (
int it = 0; it < sqrange.second - sqrange.first; it++) {
387 data_ =
decode(*(sqrange.first + it));
388 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] detid " << detid <<
" first strip "
393 BadStripPerApv[ipos] +=
395 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] ipos " << ipos <<
" Counter "
396 << BadStripPerApv[ipos] <<
" min "
405 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] Total for detid " << detid <<
" values "
406 << BadStripPerApv[0] <<
" " << BadStripPerApv[1] <<
" " << BadStripPerApv[2] <<
" "
407 << BadStripPerApv[3] <<
" " << BadStripPerApv[4] <<
" " << BadStripPerApv[5];
410 for (
size_t i = 0;
i < 6; ++
i) {
412 vect.push_back(
encode(
i * 128, 128));
436 for (; it !=
tmp.end(); ++it) {
463 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()
510 <<
" indexes.size()=" <<
indexes.size() << std::endl;
519 if (basep->ibegin != basep->iend) {
522 edm::LogError(
"SiStripQuality") <<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
526 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " <<
v_badstrips.size()
527 <<
" indexes.size()=" <<
indexes.size() << std::endl;
538 unsigned short resultA = 0, resultF = 0;
546 if (basep->iend - basep->ibegin == 1 && fs.
firstStrip == 0 && fs.
range == Nstrips) {
547 result.detid = basep->detid;
549 result.BadFibers = (1 << (Nstrips / 256)) - 1;
550 result.BadApvs = (1 << (Nstrips / 128)) - 1;
560 for (
short apvNb = 0; apvNb < 6; ++apvNb) {
562 resultA = resultA | (1 << apvNb);
566 for (
short fiberNb = 0; fiberNb < 3; ++fiberNb) {
568 resultF = resultF | (1 << fiberNb);
573 result.detid = basep->detid;
575 result.BadFibers = resultF;
611 return ((
p->BadFibers >> fiberNb) & 0x1);
619 return ((
p->BadApvs >> apvNb) & 0x1);
684 const uint32_t &detId,
685 const uint32_t &apvPairNumber,
686 std::stringstream &
ss) {
689 int layer = tTopo->
layer(detid);
713 ss << detId <<
" and apv = " << apvPairNumber <<
" of subDet = " << subDetName <<
", layer = " << layer
714 <<
" stereo = " << stereo << std::endl;
718 const std::vector<int> &activeFedsFromRunInfo,
719 const std::vector<int> &differentFeds,
721 std::ostringstream
ss;
724 ss <<
"activeFedsFromCabling:" << std::endl;
725 std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(
ss,
" "));
727 ss <<
"activeFedsFromRunInfo:" << std::endl;
728 std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(
ss,
" "));
731 if (differentFeds.size() != 440) {
732 ss <<
"differentFeds : " << std::endl;
733 std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(
ss,
" "));
736 ss <<
"There are 440 feds (all) active for Cabling but off for RunInfo. "
737 "Tracker was probably not in this run"
744 std::stringstream
ss;
746 ss <<
"associated to detIds : " << std::endl;
749 std::vector<int>::const_iterator fedIdIt = fedsList.begin();
750 for (; fedIdIt != fedsList.end(); ++fedIdIt) {
751 std::vector<FedChannelConnection>::const_iterator fedChIt =
754 uint32_t detId = fedChIt->detId();
755 if (detId == 0 || detId == 0xFFFFFFFF)
757 uint16_t apvPairNumber = fedChIt->apvPairNumber();
765 std::vector<unsigned int> vect;
766 vect.push_back(
encode(apvPairNumber * 256, 256));
769 LogTrace(
"SiStripQuality") <<
"[addOffForRunInfo] adding apvPairNumber " << apvPairNumber <<
" for detId "
770 << detId <<
" off according to RunInfo" << std::endl;