CMS 3D CMS Logo

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