50 #include "DQM/SiStripMonitorHardware/interface/FEDHistograms.hh"
51 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
87 static bool pairComparison(
const std::pair<unsigned int, unsigned int>& pair1,
88 const std::pair<unsigned int, unsigned int>& pair2);
91 unsigned int& aMajorityCounter,
92 std::vector<unsigned int>& afedIds);
141 topFolderName_(iConfig.getUntrackedParameter<
std::
string>(
"TopFolderName",
"SiStrip")),
142 fillAllDetailedHistograms_(iConfig.getUntrackedParameter<
bool>(
"FillAllDetailedHistograms",
false)),
143 fillWithEvtNum_(iConfig.getUntrackedParameter<
bool>(
"FillWithEventNumber",
false)),
144 printDebug_(iConfig.getUntrackedParameter<unsigned
int>(
"PrintDebugMessages", 1)),
149 maxFedBufferSize_(0),
150 fullDebugMode_(iConfig.getUntrackedParameter<
bool>(
"FullDebugMode",
false)) {
157 if (iConfig.
exists(
"ErrorFractionByLumiBlockHistogramConfig")) {
163 std::ostringstream debugStream;
165 debugStream <<
"[SiStripFEDMonitorPlugin]Configuration for SiStripFEDMonitorPlugin: " << std::endl
166 <<
"[SiStripFEDMonitorPlugin]\tRawDataTag: " <<
rawDataTag_ << std::endl
167 <<
"[SiStripFEDMonitorPlugin]\tHistogramFolderName: " <<
folderName_ << std::endl
168 <<
"[SiStripFEDMonitorPlugin]\tFillAllDetailedHistograms? "
170 <<
"[SiStripFEDMonitorPlugin]\tFillWithEventNumber?" << (
fillWithEvtNum_ ?
"yes" :
"no") << std::endl
171 <<
"[SiStripFEDMonitorPlugin]\tPrintDebugMessages? " << (
printDebug_ ?
"yes" :
"no") << std::endl;
175 std::ostringstream* pDebugStream = (
printDebug_ > 1 ? &debugStream :
nullptr);
177 fedHists_.initialise(iConfig, pDebugStream);
186 LogTrace(
"SiStripMonitorHardware") << debugStream.str();
216 auto lumiErrors = luminosityBlockCache(
iEvent.getLuminosityBlock().index());
217 auto& nToterr = lumiErrors->nTotal;
218 auto& nErr = lumiErrors->nErrors;
220 if (
he.isValid() && !
he.failedToGet()) {
225 std::map<unsigned int, std::pair<unsigned short, unsigned short> > badChannelFraction;
227 unsigned int lNFEDMonitoring = 0;
228 unsigned int lNFEDUnpacker = 0;
229 unsigned int lNChannelMonitoring = 0;
230 unsigned int lNChannelUnpacker = 0;
232 unsigned int lNTotBadFeds = 0;
233 unsigned int lNTotBadChannels = 0;
234 unsigned int lNTotBadActiveChannels = 0;
236 std::vector<std::vector<std::pair<unsigned int, unsigned int> > > lFeMajFrac;
237 const unsigned int nParts = 4;
239 lFeMajFrac.resize(nParts);
241 lFeMajFrac[0].reserve(912);
242 lFeMajFrac[1].reserve(1080);
243 lFeMajFrac[2].reserve(768);
244 lFeMajFrac[3].reserve(760);
252 unsigned int lNBadChannels_perFEDID = 0;
258 double aLumiSection =
iEvent.orbitNumber() / 262144.0;
262 bool lDataExist =
fedErrors_.checkDataPresent(fedData);
281 bool lFailUnpackerFEDcheck =
fedErrors_.failUnpackerFEDCheck();
284 unsigned int lSize = fedData.
size();
292 bool lFailMonitoringFEDcheck =
fedErrors_.failMonitoringFEDCheck();
293 if (lFailMonitoringFEDcheck)
299 if (lFailMonitoringFEDcheck != lFailUnpackerFEDcheck) {
301 std::ostringstream debugStream;
302 debugStream <<
" --- WARNING: FED " <<
fedId << std::endl <<
" ------ Monitoring FED check ";
303 if (lFailMonitoringFEDcheck)
304 debugStream <<
"failed." << std::endl;
306 debugStream <<
"passed." << std::endl;
307 debugStream <<
" ------ Unpacker FED check ";
308 if (lFailUnpackerFEDcheck)
309 debugStream <<
"failed." << std::endl;
311 debugStream <<
"passed." << std::endl;
312 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
315 if (lFailMonitoringFEDcheck)
317 else if (lFailUnpackerFEDcheck)
326 <<
" -- Fedid " <<
fedId <<
", TkHistoMap enabled but pointer is null." << std::endl;
333 lNTotBadActiveChannels,
334 lNBadChannels_perFEDID,
341 for (
unsigned int iP(0); iP < nParts; ++iP) {
344 if (lFeMajFrac[iP].
empty())
348 unsigned int lMajorityCounter = 0;
349 std::vector<unsigned int> lfedIds;
351 getMajority(lFeMajFrac[iP], lMajorityCounter, lfedIds);
353 fedHists_.fillMajorityHistograms(iP, static_cast<float>(lMajorityCounter) / lFeMajFrac[iP].
size(), lfedIds);
357 if ((lNTotBadFeds > 0 || lNTotBadChannels > 0) &&
printDebug_ > 1) {
358 std::ostringstream debugStream;
359 debugStream <<
"[SiStripFEDMonitorPlugin] --- Total number of bad feds = " << lNTotBadFeds << std::endl
360 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad channels = " << lNTotBadChannels << std::endl
361 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad active channels = " << lNTotBadActiveChannels
363 edm::LogInfo(
"SiStripMonitorHardware") << debugStream.str();
366 if ((lNFEDMonitoring > 0 || lNFEDUnpacker > 0 || lNChannelMonitoring > 0 || lNChannelUnpacker > 0) &&
printDebug_) {
367 std::ostringstream debugStream;
369 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
371 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
373 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at FED level : "
375 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNFEDMonitoring
377 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNFEDUnpacker
379 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
381 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at Channel level : "
383 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNChannelMonitoring
385 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNChannelUnpacker
387 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
389 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
391 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
394 fedErrors_.getFEDErrorsCounters().nTotalBadChannels = lNTotBadChannels;
395 fedErrors_.getFEDErrorsCounters().nTotalBadActiveChannels = lNTotBadActiveChannels;
400 double eventNumber = static_cast<double>(
iEvent.id().event());
404 double aTime =
iEvent.orbitNumber() / 11223.;
414 const std::pair<unsigned int, unsigned int>& pair2) {
415 return (pair1.second < pair2.second);
419 unsigned int& aMajorityCounter,
420 std::vector<unsigned int>& afedIds) {
421 unsigned int lMajAddress = 0;
422 std::vector<std::pair<unsigned int, unsigned int> >::const_iterator lIter = aFeMajVec.begin();
423 unsigned int lMajAddr = (*lIter).second;
424 unsigned int lCounter = 0;
427 unsigned int iele = 0;
429 for (; lIter != aFeMajVec.end(); ++lIter, ++iele) {
431 if ((*lIter).second == lMajAddr) {
436 if (lCounter > aMajorityCounter) {
438 aMajorityCounter = lCounter;
440 lMajAddress = lMajAddr;
445 lMajAddr = (*lIter).second;
452 if (lCounter > aMajorityCounter) {
454 aMajorityCounter = lCounter;
455 lMajAddress = lMajAddr;
460 lIter = aFeMajVec.begin();
461 afedIds.reserve(135);
462 for (; lIter != aFeMajVec.end(); ++lIter) {
463 if ((*lIter).second != lMajAddress) {
464 afedIds.push_back((*lIter).first);
466 lIter += aMajorityCounter - 1;
467 if (lIter >= aFeMajVec.end()) {
468 std::cout <<
"Here it is a bug: " << aMajorityCounter <<
" " << aFeMajVec.size() <<
" "
469 << lIter - aFeMajVec.end() << std::endl;
474 if (!afedIds.empty()) {
475 std::sort(afedIds.begin(), afedIds.end());
476 std::vector<unsigned int>::iterator lIt =
std::unique(afedIds.begin(), afedIds.end());
477 afedIds.erase(lIt, afedIds.end());
487 fedHists_.bookTopLevelHistograms(ibooker, tkDetMap);
498 ibooker.
book1D(
"lumiErrorFraction",
"Fraction of error per lumi section vs subdetector", 6, 0.5, 6.5);
514 auto lumiErrors = std::make_shared<sifedmon::LumiErrors>();
515 lumiErrors->nTotal.resize(6, 0);
516 lumiErrors->nErrors.resize(6, 0);
522 auto lumiErrors = luminosityBlockCache(
lumi.index());
524 for (
unsigned int iD(0); iD < lumiErrors->nTotal.size(); iD++) {
525 if (lumiErrors->nTotal[iD] > 0)
526 lumiErrfac_->
Fill(iD + 1, static_cast<float>(lumiErrors->nErrors[iD]) / lumiErrors->nTotal[iD]);