17 #include <boost/bind.hpp>
18 #include <boost/function.hpp>
22 FileInPath_(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
23 SiStripDetCabling_(nullptr),
25 useEmptyRunInfo_(
false) {
30 : toCleanUp(
false), FileInPath_(
file), SiStripDetCabling_(nullptr), printDebug_(
false), useEmptyRunInfo_(
false) {
47 LogTrace(
"SiStripQuality") <<
"SiStripQuality destructor" << std::endl;
61 std::vector<unsigned int> ovect, vect;
63 unsigned short Nstrips;
81 if (orange.second - orange.first != 1 || data_.
firstStrip != 0 || data_.
range < Nstrips) {
82 ovect.insert(ovect.end(), orange.first, orange.second);
83 vect.insert(vect.end(),
range.first,
range.second);
88 edm::LogError(
"SiStripQuality") <<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
102 return a.getRegistryVectorBegin() ==
a.getRegistryVectorEnd();
108 std::vector<unsigned int> vect;
109 short firstStrip = 0;
113 std::vector<uint32_t> vdets;
115 std::vector<uint32_t>::const_iterator iter = vdets.begin();
116 std::vector<uint32_t>::const_iterator iterEnd = vdets.end();
118 for (; iter != iterEnd; ++iter) {
121 LogTrace(
"SiStripQuality") <<
"[add Voff] add detid " << *iter <<
" first strip " << firstStrip <<
" range "
122 <<
range << std::endl;
130 bool allFedsEmpty = runInfo->
m_fed_in.empty();
132 std::stringstream
ss;
133 ss <<
"WARNING: the full list of feds in RunInfo is empty. ";
135 ss <<
" SiStripQuality will still use it and all tracker will be off." << std::endl;
137 ss <<
" SiStripQuality will not use it." << std::endl;
146 std::vector<uint16_t> activeFedsFromCabling(ids.begin(), ids.end());
148 std::vector<int> activeFedsFromRunInfo;
150 std::remove_copy_if(runInfo->
m_fed_in.begin(),
152 std::back_inserter(activeFedsFromRunInfo),
153 !boost::bind(std::logical_and<bool>(),
162 std::sort(activeFedsFromCabling.begin(), activeFedsFromCabling.end());
163 std::sort(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end());
164 std::vector<int> differentFeds;
166 std::set_difference(activeFedsFromCabling.begin(),
167 activeFedsFromCabling.end(),
168 activeFedsFromRunInfo.begin(),
169 activeFedsFromRunInfo.end(),
170 std::back_inserter(differentFeds));
184 std::vector<int>
check;
185 std::set_difference(activeFedsFromRunInfo.begin(),
186 activeFedsFromRunInfo.end(),
187 activeFedsFromCabling.begin(),
188 activeFedsFromCabling.end(),
189 std::back_inserter(
check));
191 if (!
check.empty()) {
193 edm::LogInfo(
"SiStripQuality") <<
"The cabling should always include the active feds in runInfo and "
194 "possibly have some more"
195 <<
"there are instead " <<
check.size() <<
" feds only active in runInfo";
211 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo> allData =
reader->
getAllData();
212 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator iter = allData.begin();
213 std::map<uint32_t, SiStripDetInfoFileReader::DetInfo>::const_iterator iterEnd = allData.end();
214 std::vector<unsigned int> vect;
215 short firstStrip = 0;
217 for (; iter != iterEnd; ++iter)
220 range = iter->second.nApvs * 128;
221 LogTrace(
"SiStripQuality") <<
"[addNotConnectedConnectionFromCabling] add detid " << iter->first << std::endl;
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) {
237 std::vector<const FedChannelConnection *>::const_iterator itconns = fedconns.begin();
238 std::vector<const FedChannelConnection *>::const_iterator itconnsEnd = fedconns.end();
241 short ngoodConn = 0, goodConn = 0;
242 for (; itconns != itconnsEnd; ++itconns) {
250 goodConn = goodConn | (0x1 << (*itconns)->apvPairNumber());
253 if (ngoodConn != nApvPairs) {
254 std::vector<unsigned int> vect;
255 for (
size_t idx = 0;
idx < nApvPairs; ++
idx) {
256 if (!(goodConn & (0
x1 <<
idx))) {
257 short firstStrip =
idx * 256;
259 LogTrace(
"SiStripQuality") <<
"[addInvalidConnectionFromCabling] add detid " << *itdet <<
"firstStrip "
260 << firstStrip << std::endl;
279 uint32_t detid = basep->detid;
280 LogTrace(
"SiStripQuality") <<
"add detid " << detid << std::endl;
285 add(detid, baserange);
290 std::vector<unsigned int> vect,
tmp;
300 LogTrace(
"SiStripQuality") <<
"new detid" << std::endl;
302 tmp.insert(
tmp.end(), baserange.first, baserange.second);
303 std::stable_sort(
tmp.begin(),
tmp.end());
304 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
306 LogTrace(
"SiStripQuality") <<
"already exists" << std::endl;
312 LogTrace(
"SiStripQuality") <<
"full det is bad.. " <<
range.second -
range.first <<
" "
319 tmp.insert(
tmp.end(), baserange.first, baserange.second);
321 std::stable_sort(
tmp.begin(),
tmp.end());
322 LogTrace(
"SiStripQuality") <<
"ordered" << std::endl;
328 edm::LogError(
"SiStripQuality") <<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
332 std::vector<unsigned int>
tmp = vect;
334 std::stable_sort(
tmp.begin(),
tmp.end());
352 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::put_replace] Replacing "
353 "SiStripQuality for already stored DetID "
354 <<
DetId << std::endl;
374 uint16_t BadStripPerApv[6], ipos;
375 std::vector<unsigned int> vect;
377 for (; rp != rend; ++rp) {
378 uint32_t detid = rp->detid;
380 BadStripPerApv[0] = 0;
381 BadStripPerApv[1] = 0;
382 BadStripPerApv[2] = 0;
383 BadStripPerApv[3] = 0;
384 BadStripPerApv[4] = 0;
385 BadStripPerApv[5] = 0;
391 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 "
398 BadStripPerApv[ipos] +=
400 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] ipos " << ipos <<
" Counter "
401 << BadStripPerApv[ipos] <<
" min "
410 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::ReduceGranularity] Total for detid " << detid <<
" values "
411 << BadStripPerApv[0] <<
" " << BadStripPerApv[1] <<
" " << BadStripPerApv[2] <<
" "
412 << BadStripPerApv[3] <<
" " << BadStripPerApv[4] <<
" " << BadStripPerApv[5];
415 for (
size_t i = 0;
i < 6; ++
i) {
417 vect.push_back(
encode(
i * 128, 128));
441 for (; it !=
tmp.end(); ++it) {
468 for (; it != itend; ++it) {
475 std::vector<unsigned int>
tmp;
480 for (; jt != jtend; ++jt) {
511 std::vector<unsigned int> v_badstrips_tmp =
v_badstrips;
512 std::vector<DetRegistry> indexes_tmp =
indexes;
514 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] before cleanUp v_badstrips.size()= " <<
v_badstrips.size()
515 <<
" indexes.size()=" <<
indexes.size() << std::endl;
524 if (basep->ibegin != basep->iend) {
527 edm::LogError(
"SiStripQuality") <<
"[" << __PRETTY_FUNCTION__ <<
"] " << std::endl;
531 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::cleanUp] after cleanUp v_badstrips.size()= " <<
v_badstrips.size()
532 <<
" indexes.size()=" <<
indexes.size() << std::endl;
543 unsigned short resultA = 0, resultF = 0;
551 if (basep->iend - basep->ibegin == 1 && fs.
firstStrip == 0 && fs.
range == Nstrips) {
552 result.detid = basep->detid;
554 result.BadFibers = (1 << (Nstrips / 256)) - 1;
555 result.BadApvs = (1 << (Nstrips / 128)) - 1;
565 for (
short apvNb = 0; apvNb < 6; ++apvNb) {
567 resultA = resultA | (1 << apvNb);
571 for (
short fiberNb = 0; fiberNb < 3; ++fiberNb) {
573 resultF = resultF | (1 << fiberNb);
578 result.detid = basep->detid;
580 result.BadFibers = resultF;
616 return ((
p->BadFibers >> fiberNb) & 0x1);
624 return ((
p->BadApvs >> apvNb) & 0x1);
689 const uint32_t &detId,
690 const uint32_t &apvPairNumber,
691 std::stringstream &
ss) {
694 int layer = tTopo->
layer(detid);
718 ss << detId <<
" and apv = " << apvPairNumber <<
" of subDet = " << subDetName <<
", layer = " << layer
719 <<
" stereo = " << stereo << std::endl;
723 const std::vector<int> &activeFedsFromRunInfo,
724 const std::vector<int> &differentFeds,
726 std::ostringstream
ss;
729 ss <<
"activeFedsFromCabling:" << std::endl;
730 std::copy(activeFedsFromCabling.begin(), activeFedsFromCabling.end(), std::ostream_iterator<uint16_t>(
ss,
" "));
732 ss <<
"activeFedsFromRunInfo:" << std::endl;
733 std::copy(activeFedsFromRunInfo.begin(), activeFedsFromRunInfo.end(), std::ostream_iterator<int>(
ss,
" "));
736 if (differentFeds.size() != 440) {
737 ss <<
"differentFeds : " << std::endl;
738 std::copy(differentFeds.begin(), differentFeds.end(), std::ostream_iterator<int>(
ss,
" "));
741 ss <<
"There are 440 feds (all) active for Cabling but off for RunInfo. "
742 "Tracker was probably not in this run"
749 std::stringstream
ss;
751 ss <<
"associated to detIds : " << std::endl;
754 std::vector<int>::const_iterator fedIdIt = fedsList.begin();
755 for (; fedIdIt != fedsList.end(); ++fedIdIt) {
756 std::vector<FedChannelConnection>::const_iterator fedChIt =
759 uint32_t detId = fedChIt->detId();
760 if (detId == 0 || detId == 0xFFFFFFFF)
762 uint16_t apvPairNumber = fedChIt->apvPairNumber();
770 std::vector<unsigned int> vect;
771 vect.push_back(
encode(apvPairNumber * 256, 256));
774 LogTrace(
"SiStripQuality") <<
"[addOffForRunInfo] adding apvPairNumber " << apvPairNumber <<
" for detId "
775 << detId <<
" off according to RunInfo" << std::endl;