CMS 3D CMS Logo

SiStripPopConFEDErrorsDQM.cc
Go to the documentation of this file.
7 
15 public:
18 
21  // interface methods: implemented in template
22  void initES(const edm::EventSetup& iSetup) override;
23  void dqmEndJob(DQMStore::IBooker& booker, DQMStore::IGetter& getter) override;
24  SiStripBadStrip* getObj() const override;
25 
26 private:
27  void readHistogram(MonitorElement* aMe, unsigned int& aCounter, const float aNorm, const unsigned int aFedId);
28 
29  void addBadAPV(const FedChannelConnection& aConnection,
30  const unsigned short aAPVNumber,
31  const unsigned short aFlag,
32  unsigned int& aCounter);
33 
34  void addBadStrips(const FedChannelConnection& aConnection,
35  const unsigned int aDetId,
36  const unsigned short aApvNum,
37  const unsigned short aFlag,
38  unsigned int& aCounter);
39 
41  void addErrors();
42 
43 private:
44  double threshold_;
45  unsigned int debug_;
50  std::map<uint32_t, std::vector<unsigned int> > detIdErrors_;
51 };
52 
57 
61  threshold_(iConfig.getUntrackedParameter<double>("Threshold", 0)),
62  debug_(iConfig.getUntrackedParameter<unsigned int>("Debug", 0)),
63  fedCablingToken_(iC.esConsumes<SiStripFedCabling, SiStripFedCablingRcd, edm::Transition::BeginRun>()) {
64  edm::LogInfo("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::SiStripFEDErrorsDQM()]";
65 }
66 
68  edm::LogInfo("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::~SiStripFEDErrorsDQM]";
69 }
70 
72  if (fedCablingWatcher_.check(iSetup)) {
74  }
75 }
76 
79 
80  std::ostringstream lPath;
81  lPath << "Run " << getRunNumber() << "/SiStrip/Run summary/ReadoutView/";
82  const std::string lBaseDir = lPath.str();
83 
84  getter.setCurrentFolder(lBaseDir);
85  LogTrace("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::readBadAPVs] Now in " << lBaseDir << std::endl;
86 
87  std::vector<std::pair<std::string, unsigned int> > lFedsFolder;
88  //for FED errors, use summary folder and fedId=0
89  //do not put a slash or "goToDir" won't work...
90  lFedsFolder.push_back(std::pair<std::string, unsigned int>("FedMonitoringSummary", 0));
91 
92  //for FE/channel/APV errors, they are written in a folder per FED,
93  //if there was at least one error.
94  //So just loop on folders and see which ones exist.
95  for (unsigned int ifed(FEDNumbering::MINSiStripFEDID); ifed <= FEDNumbering::MAXSiStripFEDID;
96  ifed++) { //loop on FEDs
97 
98  std::ostringstream lFedDir;
99  lFedDir << "FrontEndDriver" << ifed;
100  if (!getter.dirExists(lFedDir.str()))
101  continue;
102  else {
103  if (debug_)
104  LogTrace("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::readBadAPVs] - Errors detected for FED " << ifed
105  << std::endl;
106  lFedsFolder.push_back(std::pair<std::string, unsigned int>(lFedDir.str(), ifed));
107  }
108  }
109  getter.cd();
110 
111  unsigned int nAPVsTotal = 0;
112  //retrieve total number of APVs valid and connected from cabling:
113  if (!cabling_) {
114  edm::LogError("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::readBadAPVs] cabling not filled, return false "
115  << std::endl;
116  return;
117  }
118  auto lFedVec = cabling_->fedIds();
119  for (unsigned int iFed(0); iFed < lFedVec.size(); iFed++) {
120  if (*(lFedVec.begin() + iFed) < sistrip::FED_ID_MIN || *(lFedVec.begin() + iFed) > sistrip::FED_ID_MAX) {
121  edm::LogError("SiStripFEDErrorsDQM")
122  << "[SiStripFEDErrorsDQM::readBadAPVs] Invalid fedid : " << *(lFedVec.begin() + iFed) << std::endl;
123  continue;
124  }
125  auto lConnVec = cabling_->fedConnections(*(lFedVec.begin() + iFed));
126  for (unsigned int iConn(0); iConn < lConnVec.size(); iConn++) {
127  const FedChannelConnection& lConnection = *(lConnVec.begin() + iConn);
128  if (!lConnection.isConnected())
129  continue;
130  unsigned int lDetid = lConnection.detId();
131  if (!lDetid || lDetid == sistrip::invalid32_)
132  continue;
133  //2 APVs per channel....
134  nAPVsTotal += 2;
135  }
136  }
137 
138  edm::LogInfo("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::readBadAPVs] Total number of APVs found : "
139  << nAPVsTotal << std::endl;
140 
141  unsigned int nAPVsWithErrorTotal = 0;
142  unsigned int nFolders = 0;
143  float lNorm = 0;
144  for (const auto& iFolder : lFedsFolder) {
145  const std::string lDirName = lBaseDir + "/" + iFolder.first;
146  const unsigned int lFedId = iFolder.second;
147 
148  if (!getter.dirExists(lDirName))
149  continue;
150 
151  std::vector<MonitorElement*> lMeVec = getter.getContents(lDirName);
152 
153  if (nFolders == 0) {
154  for (auto iMe : lMeVec) { //loop on ME found in directory
155  std::string lMeName = iMe->getName();
156  if (lMeName.find("nFEDErrors") != lMeName.npos) {
157  lNorm = iMe->getEntries();
158  }
159  }
160  //if norm histo has not been found, no point in continuing....
161  if (lNorm < 1) {
162  edm::LogError("SiStripFEDErrorsDQM")
163  << "[SiStripFEDErrorsDQM::readBadAPVs] nFEDErrors not found, norm is " << lNorm << std::endl;
164  return;
165  }
166  }
167 
168  unsigned int nAPVsWithError = 0;
169  for (auto iMe : lMeVec) { //loop on ME found in directory
170  if (iMe->getEntries() == 0)
171  continue;
172  const std::string lMeName = iMe->getName();
173 
174  bool lookForErrors = false;
175  if (nFolders == 0) {
176  //for the first element of lFedsFolder: this is FED errors
177  lookForErrors = lMeName.find("DataMissing") != lMeName.npos || lMeName.find("AnyFEDErrors") != lMeName.npos ||
178  (lMeName.find("CorruptBuffer") != lMeName.npos && lMeName.find("nFED") == lMeName.npos);
179  } else {
180  //for the others, it is channel or FE errors.
181  lookForErrors = lMeName.find("APVAddressError") != lMeName.npos || lMeName.find("APVError") != lMeName.npos ||
182  lMeName.find("BadMajorityAddresses") != lMeName.npos ||
183  lMeName.find("FEMissing") != lMeName.npos || lMeName.find("OOSBits") != lMeName.npos ||
184  lMeName.find("UnlockedBits") != lMeName.npos;
185  }
186 
187  if (lookForErrors)
188  readHistogram(iMe, nAPVsWithError, lNorm, lFedId);
189 
190  } //loop on ME found in directory
191 
192  nAPVsWithErrorTotal += nAPVsWithError;
193  ++nFolders;
194  } //loop on lFedsFolders
195 
196  edm::LogInfo("SiStripFEDErrorsDQM")
197  << "[SiStripFEDErrorsDQM::readBadAPVs] Total APVs with error found above threshold = " << nAPVsWithErrorTotal
198  << std::endl;
199 
200  getter.cd();
201 
202  addErrors();
203 }
204 
206 
208  unsigned int& aCounter,
209  const float aNorm,
210  const unsigned int aFedId) {
211  unsigned short lFlag = 0;
212  std::string lMeName = aMe->getName();
213  if (lMeName.find("DataMissing") != lMeName.npos) {
214  lFlag = 0;
215  } else if (lMeName.find("AnyFEDErrors") != lMeName.npos) {
216  lFlag = 1;
217  } else if (lMeName.find("CorruptBuffer") != lMeName.npos && lMeName.find("nFED") == lMeName.npos) {
218  lFlag = 2;
219  } else if (lMeName.find("FEMissing") != lMeName.npos) {
220  lFlag = 3;
221  } else if (lMeName.find("BadMajorityAddresses") != lMeName.npos) {
222  lFlag = 4;
223  } else if (lMeName.find("UnlockedBits") != lMeName.npos) {
224  lFlag = 5;
225  } else if (lMeName.find("OOSBits") != lMeName.npos) {
226  lFlag = 6;
227  } else if (lMeName.find("APVAddressError") != lMeName.npos) {
228  lFlag = 7;
229  } else if (lMeName.find("APVError") != lMeName.npos) {
230  lFlag = 8;
231  } else {
232  edm::LogError("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::readHistogramError] Shouldn't be here ..."
233  << std::endl;
234  return;
235  }
236 
237  if (debug_) {
238  LogTrace("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::readHistogramError] Reading histo : " << lMeName
239  << ", flag = " << lFlag << std::endl;
240  }
241 
242  unsigned int lNBins = aMe->getNbinsX();
243  int lBinShift = 0;
244  bool lIsFedHist = false;
245  bool lIsAPVHist = false;
246  bool lIsFeHist = false;
247  bool lIsChHist = false;
248 
249  if (lNBins > 200) {
250  lBinShift = FEDNumbering::MINSiStripFEDID - 1; //shift for FED ID from bin number
251  lIsFedHist = true;
252  } else {
253  lBinShift = -1; //shift for channel/APV/FE id from bin number
254  if (lNBins > 100)
255  lIsAPVHist = true;
256  else if (lNBins < 10)
257  lIsFeHist = true;
258  else
259  lIsChHist = true;
260  }
261 
262  if (debug_) {
263  LogTrace("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::readHistogramError] lIsFedHist: " << lIsFedHist
264  << std::endl
265  << "[SiStripFEDErrorsDQM::readHistogramError] lIsAPVHist: " << lIsAPVHist
266  << std::endl
267  << "[SiStripFEDErrorsDQM::readHistogramError] lIsFeHist : " << lIsFeHist
268  << std::endl
269  << "[SiStripFEDErrorsDQM::readHistogramError] lIsChHist : " << lIsChHist
270  << std::endl;
271  }
272 
273  for (unsigned int ibin(1); ibin < lNBins + 1; ibin++) {
274  if (aMe->getBinContent(ibin) > 0) {
275  float lStat = aMe->getBinContent(ibin) * 1. / aNorm;
276  if (lStat <= threshold_) {
277  if (debug_)
278  LogTrace("SiStripFEDErrorsDQM")
279  << "[SiStripFEDErrorsDQM::readHistogramError] ---- Below threshold : " << lStat << std::endl;
280  continue;
281  }
282  if (lIsFedHist) {
283  unsigned int lFedId = ibin + lBinShift;
284  //loop on all enabled channels of this FED....
285  for (unsigned int iChId = 0; iChId < sistrip::FEDCH_PER_FED; iChId++) { //loop on channels
286  const FedChannelConnection& lConnection = cabling_->fedConnection(lFedId, iChId);
287  if (!lConnection.isConnected())
288  continue;
289  addBadAPV(lConnection, 0, lFlag, aCounter);
290  }
291  } else {
292  if (lIsFeHist) {
293  unsigned int iFeId = ibin + lBinShift;
294  //loop on all enabled channels of this FE....
295  for (unsigned int iFeCh = 0; iFeCh < sistrip::FEDCH_PER_FEUNIT; iFeCh++) { //loop on channels
296  unsigned int iChId = sistrip::FEDCH_PER_FEUNIT * iFeId + iFeCh;
297  const FedChannelConnection& lConnection = cabling_->fedConnection(aFedId, iChId);
298  if (!lConnection.isConnected())
299  continue;
300  addBadAPV(lConnection, 0, lFlag, aCounter);
301  }
302  } else {
303  unsigned int iChId = ibin + lBinShift;
304  if (lIsAPVHist) {
305  unsigned int iAPVid = iChId % 2 + 1;
306  iChId = static_cast<unsigned int>(iChId / 2.);
307  const FedChannelConnection& lConnection = cabling_->fedConnection(aFedId, iChId);
308  addBadAPV(lConnection, iAPVid, lFlag, aCounter);
309 
310  } //ifAPVhists
311  else {
312  const FedChannelConnection& lConnection = cabling_->fedConnection(aFedId, iChId);
313  addBadAPV(lConnection, 0, lFlag, aCounter);
314  }
315  } //if not FE hist
316  } //if not FED hist
317  } //if entries in histo
318  } //loop on bins
319 } //method readHistogram
320 
322  const unsigned short aAPVNumber,
323  const unsigned short aFlag,
324  unsigned int& aCounter) {
325  if (!aConnection.isConnected()) {
326  edm::LogWarning("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::addBadAPV] Warning, incompatible cabling ! "
327  "Channel is not connected, but entry found in histo ... "
328  << std::endl;
329  return;
330  }
331  unsigned int lDetid = aConnection.detId();
332  if (!lDetid || lDetid == sistrip::invalid32_) {
333  edm::LogWarning("SiStripFEDErrorsDQM")
334  << "[SiStripFEDErrorsDQM::addBadAPV] Warning, DetId is invalid: " << lDetid << std::endl;
335  return;
336  }
337  //unsigned short nChInModule = aConnection.nApvPairs();
338  unsigned short lApvNum = 0;
339  if (aAPVNumber < 2) {
340  lApvNum = 2 * aConnection.apvPairNumber();
341  addBadStrips(aConnection, lDetid, lApvNum, aFlag, aCounter);
342  }
343  if (aAPVNumber == 0 || aAPVNumber == 2) {
344  lApvNum = 2 * aConnection.apvPairNumber() + 1;
345  addBadStrips(aConnection, lDetid, lApvNum, aFlag, aCounter);
346  }
347 }
348 
350  const unsigned int aDetId,
351  const unsigned short aApvNum,
352  const unsigned short aFlag,
353  unsigned int& aCounter) {
354  // std::vector<unsigned int> lStripVector;
355  const unsigned short lFirstBadStrip = aApvNum * 128;
356  const unsigned short lConsecutiveBadStrips = 128;
357 
358  unsigned int lBadStripRange = obj_.encode(lFirstBadStrip, lConsecutiveBadStrips, aFlag);
359 
360  LogTrace("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::addBadStrips] ---- Adding : detid " << aDetId << " (FED "
361  << aConnection.fedId() << ", Ch " << aConnection.fedCh() << ")"
362  << ", APV " << aApvNum << ", flag " << aFlag << std::endl;
363 
364  detIdErrors_[aDetId].push_back(lBadStripRange);
365 
366  // lStripVector.push_back(lBadStripRange);
367  // SiStripBadStrip::Range lRange(lStripVector.begin(),lStripVector.end());
368  // if ( !obj.put(aDetId,lRange) ) {
369  // edm::LogError("SiStripFEDErrorsDQM")<<"[SiStripFEDErrorsDQM::addBadStrips] detid already exists." << std::endl;
370  // }
371 
372  aCounter++;
373 }
374 
375 namespace {
376  // set corresponding bit to 1 in flag
377  inline void setFlagBit(unsigned short& aFlag, const unsigned short aBit) { aFlag = aFlag | (0x1 << aBit); }
378 } // namespace
379 
381  for (const auto& it : detIdErrors_) {
382  const std::vector<uint32_t>& lList = it.second;
383 
384  //map of first strip number and flag
385  //purpose is to encode all existing flags into a unique one...
386  std::map<unsigned short, unsigned short> lAPVMap;
387  for (auto cCont : lList) {
388  SiStripBadStrip::data lData = obj_.decode(cCont);
389  unsigned short lFlag = 0;
390  setFlagBit(lFlag, lData.flag);
391 
392  //std::cout << " -- Detid " << it.first << ", strip " << lData.firstStrip << ", flag " << lData.flag << std::endl;
393 
394  auto lInsert = lAPVMap.emplace(lData.firstStrip, lFlag);
395  if (!lInsert.second) {
396  //std::cout << " ---- Adding bit : " << lData.flag << " to " << lInsert.first->second << ": ";
397  setFlagBit(lInsert.first->second, lData.flag);
398  //std::cout << lInsert.first->second << std::endl;
399  }
400  }
401 
402  //encode the new flag
403  std::vector<unsigned int> lStripVector;
404  const unsigned short lConsecutiveBadStrips = 128;
405  lStripVector.reserve(lAPVMap.size());
406  for (const auto& lIter : lAPVMap) {
407  lStripVector.push_back(obj_.encode(lIter.first, lConsecutiveBadStrips, lIter.second));
408  }
409 
410  SiStripBadStrip::Range lRange(lStripVector.begin(), lStripVector.end());
411  if (!obj_.put(it.first, lRange)) {
412  edm::LogError("SiStripFEDErrorsDQM") << "[SiStripFEDErrorsDQM::addBadStrips] detid already exists." << std::endl;
413  }
414  }
415 }
416 
void addBadStrips(const FedChannelConnection &aConnection, const unsigned int aDetId, const unsigned short aApvNum, const unsigned short aFlag, unsigned int &aCounter)
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
static const uint16_t FED_ID_MIN
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
static const uint32_t invalid32_
Definition: Constants.h:15
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
void dqmEndJob(DQMStore::IBooker &booker, DQMStore::IGetter &getter) override
virtual bool dirExists(std::string const &path) const
Definition: DQMStore.cc:730
Log< level::Error, false > LogError
#define LogTrace(id)
void initES(const edm::EventSetup &iSetup) override
std::map< uint32_t, std::vector< unsigned int > > detIdErrors_
Class containning control, module, detector and connection information, at the level of a FED channel...
const uint16_t & fedId() const
SiStripPopConFEDErrorsHandlerFromDQM(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
Transition
Definition: Transition.h:12
bool getData(T &iHolder) const
Definition: EventSetup.h:122
void addErrors()
Writes the errors to the db.
const uint32_t & detId() const
void addBadAPV(const FedChannelConnection &aConnection, const unsigned short aAPVNumber, const unsigned short aFlag, unsigned int &aCounter)
Log< level::Info, false > LogInfo
unsigned short firstStrip
static const uint16_t FEDCH_PER_FEUNIT
SiStripBadStrip * getObj() const override
void readHistogram(MonitorElement *aMe, unsigned int &aCounter, const float aNorm, const unsigned int aFedId)
uint16_t apvPairNumber() const
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
const std::string & getName() const
get name of ME
HLT enums.
static const uint16_t FEDCH_PER_FED
std::pair< ContainerIterator, ContainerIterator > Range
data decode(const unsigned int &value) const
virtual int getNbinsX() const
get # of bins in X-axis
static const uint16_t FED_ID_MAX
Log< level::Warning, false > LogWarning
const uint16_t & fedCh() const
bool put(const uint32_t &detID, const InputVector &vect)
FedsConstIterRange fedIds() const
unsigned int encode(const unsigned short &first, const unsigned short &NconsecutiveBadStrips, const unsigned short &flag=0)
ConnsConstIterRange fedConnections(uint16_t fed_id) const
virtual std::vector< dqm::harvesting::MonitorElement * > getContents(std::string const &path) const
Definition: DQMStore.cc:593
edm::ESWatcher< SiStripFedCablingRcd > fedCablingWatcher_
virtual double getBinContent(int binx) const
get content of bin (1-D)