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);
140 : rawDataTag_(iConfig.getUntrackedParameter<edm::
InputTag>(
"RawDataTag", edm::
InputTag(
"source",
""))),
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();
217 auto& nToterr = lumiErrors->nTotal;
218 auto& nErr = lumiErrors->nErrors;
221 fedErrors_.fillEventProperties(he->deltaBX());
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());
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]);
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
bool fillAllDetailedHistograms_
LuminosityBlockIndex index() const
virtual void setCurrentFolder(std::string const &fullpath)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const SiStripFedCabling * cabling_
#define DEFINE_FWK_MODULE(type)
void updateCabling(const SiStripFedCablingRcd &cablingRcd)
void analyze(const edm::Event &, const edm::EventSetup &) override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
void getMajority(const std::vector< std::pair< unsigned int, unsigned int > > &aFeMajVec, unsigned int &aMajorityCounter, std::vector< unsigned int > &afedIds)
void globalEndLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &iSetup) override
std::string topFolderName_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > tTopoToken_
std::shared_ptr< sifedmon::LumiErrors > globalBeginLuminosityBlock(const edm::LuminosityBlock &lumi, const edm::EventSetup &iSetup) const override
unsigned int maxFedBufferSize_
Log< level::Error, false > LogError
size_t size() const
Lenght of the data buffer in bytes.
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
bool getData(T &iHolder) const
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
SiStripFEDMonitorPlugin(const edm::ParameterSet &)
MonitorElement * lumiErrfac_
LuminosityBlock const & getLuminosityBlock() const
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
edm::ESGetToken< TkDetMap, TrackerTopologyRcd > tkDetMapToken_
Log< level::Info, false > LogInfo
std::vector< unsigned int > nTotal
std::vector< unsigned int > nErrors
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
bool check(const edm::EventSetup &iSetup)
edm::InputTag rawDataTag_
static bool pairComparison(const std::pair< unsigned int, unsigned int > &pair1, const std::pair< unsigned int, unsigned int > &pair2)
edm::ESWatcher< SiStripFedCablingRcd > fedCablingWatcher_
Log< level::Warning, false > LogWarning
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
edm::EDGetTokenT< EventWithHistory > heToken_
UseScope< MonitorElementData::Scope::RUN > UseRunScope
~SiStripFEDMonitorPlugin() override
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
tuple size
Write out results.
edm::ESGetToken< SiStripFedCabling, SiStripFedCablingRcd > fedCablingToken_
virtual void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)