17 #include <boost/bind.hpp> 18 #include <boost/function.hpp> 22 FileInPath_(
"CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"),
25 useEmptyRunInfo_(
false) {
47 LogTrace(
"SiStripQuality") <<
"SiStripQuality destructor" << std::endl;
61 std::vector<unsigned int> ovect, vect;
63 unsigned short Nstrips;
74 if (range.first != range.second) {
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;
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;
123 vect.push_back(
encode(firstStrip, range));
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;
222 vect.push_back(
encode(firstStrip, range));
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;
261 vect.push_back(
encode(firstStrip, range));
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;
299 if (range.first == range.second) {
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;
311 if (range.second - range.first == 1 && data_.
firstStrip == 0 && data_.
range >= Nstrips) {
312 LogTrace(
"SiStripQuality") <<
"full det is bad.. " << range.second - range.first <<
" " 319 tmp.insert(tmp.end(), baserange.first, baserange.second);
320 tmp.insert(tmp.end(), range.first, range.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());
343 size_t sd = input.second - input.first;
345 detregistry.
detid = DetId;
351 if (p !=
indexes.end() && p->detid == DetId) {
352 LogTrace(
"SiStripQuality") <<
"[SiStripQuality::put_replace] Replacing " 353 "SiStripQuality for already stored DetID " 354 << DetId << std::endl;
358 indexes.insert(p, detregistry);
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) {
416 if (BadStripPerApv[
i] >= threshold * 128) {
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) {
525 SiStripBadStrip::Range range(v_badstrips_tmp.begin() + basep->ibegin, v_badstrips_tmp.begin() + basep->iend);
526 if (!
put(basep->detid, range))
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;
550 fs =
decode(*(range.first));
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;
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" 745 edm::LogInfo(
"SiStripQuality") << ss.str() << std::endl;
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;
780 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
void printDebug(std::stringstream &ss, const TrackerTopology *trackerTopo) const
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_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool IsModuleBad(const uint32_t &detid) const
base
Make Sure CMSSW is Setup ##.
static const std::string B
void subtraction(std::vector< unsigned int > &, const unsigned int &)
SiStripQuality & operator+=(const SiStripQuality &)
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
~SiStripQuality() override
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)
std::string fullPath() const
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)
SiStripQuality & operator-=(const SiStripQuality &)
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)