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);
137 topFolderName_(iConfig.getUntrackedParameter<
std::
string>(
"TopFolderName",
"SiStrip")),
138 fillAllDetailedHistograms_(iConfig.getUntrackedParameter<
bool>(
"FillAllDetailedHistograms",
false)),
139 fillWithEvtNum_(iConfig.getUntrackedParameter<
bool>(
"FillWithEventNumber",
false)),
140 printDebug_(iConfig.getUntrackedParameter<unsigned
int>(
"PrintDebugMessages", 1)),
142 maxFedBufferSize_(0),
143 fullDebugMode_(iConfig.getUntrackedParameter<
bool>(
"FullDebugMode",
false)) {
150 if (iConfig.
exists(
"ErrorFractionByLumiBlockHistogramConfig")) {
156 std::ostringstream debugStream;
158 debugStream <<
"[SiStripFEDMonitorPlugin]Configuration for SiStripFEDMonitorPlugin: " << std::endl
159 <<
"[SiStripFEDMonitorPlugin]\tRawDataTag: " <<
rawDataTag_ << std::endl
160 <<
"[SiStripFEDMonitorPlugin]\tHistogramFolderName: " <<
folderName_ << std::endl
161 <<
"[SiStripFEDMonitorPlugin]\tFillAllDetailedHistograms? "
163 <<
"[SiStripFEDMonitorPlugin]\tFillWithEventNumber?" << (
fillWithEvtNum_ ?
"yes" :
"no") << std::endl
164 <<
"[SiStripFEDMonitorPlugin]\tPrintDebugMessages? " << (
printDebug_ ?
"yes" :
"no") << std::endl;
168 std::ostringstream* pDebugStream = (
printDebug_ > 1 ? &debugStream :
nullptr);
170 fedHists_.initialise(iConfig, pDebugStream);
179 LogTrace(
"SiStripMonitorHardware") << debugStream.str();
214 auto lumiErrors = luminosityBlockCache(
iEvent.getLuminosityBlock().index());
215 auto& nToterr = lumiErrors->nTotal;
216 auto& nErr = lumiErrors->nErrors;
218 if (
he.isValid() && !
he.failedToGet()) {
223 std::map<unsigned int, std::pair<unsigned short, unsigned short> > badChannelFraction;
225 unsigned int lNFEDMonitoring = 0;
226 unsigned int lNFEDUnpacker = 0;
227 unsigned int lNChannelMonitoring = 0;
228 unsigned int lNChannelUnpacker = 0;
230 unsigned int lNTotBadFeds = 0;
231 unsigned int lNTotBadChannels = 0;
232 unsigned int lNTotBadActiveChannels = 0;
234 std::vector<std::vector<std::pair<unsigned int, unsigned int> > > lFeMajFrac;
235 const unsigned int nParts = 4;
237 lFeMajFrac.resize(nParts);
239 lFeMajFrac[0].reserve(912);
240 lFeMajFrac[1].reserve(1080);
241 lFeMajFrac[2].reserve(768);
242 lFeMajFrac[3].reserve(760);
250 unsigned int lNBadChannels_perFEDID = 0;
256 double aLumiSection =
iEvent.orbitNumber() / 262144.0;
260 bool lDataExist =
fedErrors_.checkDataPresent(fedData);
279 bool lFailUnpackerFEDcheck =
fedErrors_.failUnpackerFEDCheck();
282 unsigned int lSize = fedData.
size();
290 bool lFailMonitoringFEDcheck =
fedErrors_.failMonitoringFEDCheck();
291 if (lFailMonitoringFEDcheck)
297 if (lFailMonitoringFEDcheck != lFailUnpackerFEDcheck) {
299 std::ostringstream debugStream;
300 debugStream <<
" --- WARNING: FED " <<
fedId << std::endl <<
" ------ Monitoring FED check ";
301 if (lFailMonitoringFEDcheck)
302 debugStream <<
"failed." << std::endl;
304 debugStream <<
"passed." << std::endl;
305 debugStream <<
" ------ Unpacker FED check ";
306 if (lFailUnpackerFEDcheck)
307 debugStream <<
"failed." << std::endl;
309 debugStream <<
"passed." << std::endl;
310 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
313 if (lFailMonitoringFEDcheck)
315 else if (lFailUnpackerFEDcheck)
324 <<
" -- Fedid " <<
fedId <<
", TkHistoMap enabled but pointer is null." << std::endl;
331 lNTotBadActiveChannels,
332 lNBadChannels_perFEDID,
339 for (
unsigned int iP(0); iP < nParts; ++iP) {
342 if (lFeMajFrac[iP].
empty())
346 unsigned int lMajorityCounter = 0;
347 std::vector<unsigned int> lfedIds;
349 getMajority(lFeMajFrac[iP], lMajorityCounter, lfedIds);
351 fedHists_.fillMajorityHistograms(iP, static_cast<float>(lMajorityCounter) / lFeMajFrac[iP].
size(), lfedIds);
355 if ((lNTotBadFeds > 0 || lNTotBadChannels > 0) &&
printDebug_ > 1) {
356 std::ostringstream debugStream;
357 debugStream <<
"[SiStripFEDMonitorPlugin] --- Total number of bad feds = " << lNTotBadFeds << std::endl
358 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad channels = " << lNTotBadChannels << std::endl
359 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad active channels = " << lNTotBadActiveChannels
361 edm::LogInfo(
"SiStripMonitorHardware") << debugStream.str();
364 if ((lNFEDMonitoring > 0 || lNFEDUnpacker > 0 || lNChannelMonitoring > 0 || lNChannelUnpacker > 0) &&
printDebug_) {
365 std::ostringstream debugStream;
367 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
369 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
371 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at FED level : "
373 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNFEDMonitoring
375 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNFEDUnpacker
377 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
379 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at Channel level : "
381 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNChannelMonitoring
383 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNChannelUnpacker
385 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
387 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------"
389 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
392 fedErrors_.getFEDErrorsCounters().nTotalBadChannels = lNTotBadChannels;
393 fedErrors_.getFEDErrorsCounters().nTotalBadActiveChannels = lNTotBadActiveChannels;
398 double eventNumber = static_cast<double>(
iEvent.id().event());
402 double aTime =
iEvent.orbitNumber() / 11223.;
412 const std::pair<unsigned int, unsigned int>& pair2) {
413 return (pair1.second < pair2.second);
417 unsigned int& aMajorityCounter,
418 std::vector<unsigned int>& afedIds) {
419 unsigned int lMajAddress = 0;
420 std::vector<std::pair<unsigned int, unsigned int> >::const_iterator lIter = aFeMajVec.begin();
421 unsigned int lMajAddr = (*lIter).second;
422 unsigned int lCounter = 0;
425 unsigned int iele = 0;
427 for (; lIter != aFeMajVec.end(); ++lIter, ++iele) {
429 if ((*lIter).second == lMajAddr) {
434 if (lCounter > aMajorityCounter) {
436 aMajorityCounter = lCounter;
438 lMajAddress = lMajAddr;
443 lMajAddr = (*lIter).second;
450 if (lCounter > aMajorityCounter) {
452 aMajorityCounter = lCounter;
453 lMajAddress = lMajAddr;
458 lIter = aFeMajVec.begin();
459 afedIds.reserve(135);
460 for (; lIter != aFeMajVec.end(); ++lIter) {
461 if ((*lIter).second != lMajAddress) {
462 afedIds.push_back((*lIter).first);
464 lIter += aMajorityCounter - 1;
465 if (lIter >= aFeMajVec.end()) {
466 std::cout <<
"Here it is a bug: " << aMajorityCounter <<
" " << aFeMajVec.size() <<
" "
467 << lIter - aFeMajVec.end() << std::endl;
472 if (!afedIds.empty()) {
473 std::sort(afedIds.begin(), afedIds.end());
474 std::vector<unsigned int>::iterator lIt =
std::unique(afedIds.begin(), afedIds.end());
475 afedIds.erase(lIt, afedIds.end());
488 fedHists_.bookTopLevelHistograms(ibooker, tkDetMap);
499 ibooker.
book1D(
"lumiErrorFraction",
"Fraction of error per lumi section vs subdetector", 6, 0.5, 6.5);
515 auto lumiErrors = std::make_shared<sifedmon::LumiErrors>();
516 lumiErrors->nTotal.resize(6, 0);
517 lumiErrors->nErrors.resize(6, 0);
523 auto lumiErrors = luminosityBlockCache(
lumi.index());
525 for (
unsigned int iD(0); iD < lumiErrors->nTotal.size(); iD++) {
526 if (lumiErrors->nTotal[iD] > 0)
527 lumiErrfac_->
Fill(iD + 1, static_cast<float>(lumiErrors->nErrors[iD]) / lumiErrors->nTotal[iD]);