50 #include "DQM/SiStripMonitorHardware/interface/FEDHistograms.hh" 51 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh" 77 static bool pairComparison(
const std::pair<unsigned int, unsigned int> & pair1,
78 const std::pair<unsigned int, unsigned int> & pair2);
80 void getMajority(
const std::vector<std::pair<unsigned int,unsigned int> > & aFeMajVec,
81 unsigned int & aMajorityCounter,
82 std::vector<unsigned int> & afedIds);
125 :
rawDataTag_(iConfig.getUntrackedParameter<
edm::InputTag>(
"RawDataTag",
edm::InputTag(
"source",
""))),
129 printDebug_(iConfig.getUntrackedParameter<unsigned
int>(
"PrintDebugMessages",1)),
142 std::ostringstream debugStream;
144 debugStream <<
"[SiStripFEDMonitorPlugin]Configuration for SiStripFEDMonitorPlugin: " << std::endl
145 <<
"[SiStripFEDMonitorPlugin]\tRawDataTag: " <<
rawDataTag_ << std::endl
146 <<
"[SiStripFEDMonitorPlugin]\tHistogramFolderName: " << folderName_ << std::endl
148 <<
"[SiStripFEDMonitorPlugin]\tFillWithEventNumber?" << (
fillWithEvtNum_ ?
"yes" :
"no") << std::endl
149 <<
"[SiStripFEDMonitorPlugin]\tPrintDebugMessages? " << (
printDebug_ ?
"yes" :
"no") << std::endl;
153 std::ostringstream* pDebugStream = (
printDebug_>1 ? &debugStream :
nullptr);
155 fedHists_.initialise(iConfig,pDebugStream);
164 LogTrace(
"SiStripMonitorHardware") << debugStream.str();
209 std::map<unsigned int,std::pair<unsigned short,unsigned short> > badChannelFraction;
211 unsigned int lNFEDMonitoring = 0;
212 unsigned int lNFEDUnpacker = 0;
213 unsigned int lNChannelMonitoring = 0;
214 unsigned int lNChannelUnpacker = 0;
216 unsigned int lNTotBadFeds = 0;
217 unsigned int lNTotBadChannels = 0;
218 unsigned int lNTotBadActiveChannels = 0;
220 std::vector<std::vector<std::pair<unsigned int,unsigned int> > > lFeMajFrac;
221 const unsigned int nParts = 4;
223 lFeMajFrac.resize(nParts);
225 lFeMajFrac[0].reserve(912);
226 lFeMajFrac[1].reserve(1080);
227 lFeMajFrac[2].reserve(768);
228 lFeMajFrac[3].reserve(760);
237 unsigned int lNBadChannels_perFEDID = 0;
243 double aLumiSection = iEvent.
orbitNumber()/262144.0;
247 bool lDataExist =
fedErrors_.checkDataPresent(fedData);
269 bool lFailUnpackerFEDcheck =
fedErrors_.failUnpackerFEDCheck();
272 unsigned int lSize = fedData.
size();
280 bool lFailMonitoringFEDcheck =
fedErrors_.failMonitoringFEDCheck();
281 if (lFailMonitoringFEDcheck) lNTotBadFeds++;
287 if (lFailMonitoringFEDcheck != lFailUnpackerFEDcheck) {
289 std::ostringstream debugStream;
290 debugStream <<
" --- WARNING: FED " <<
fedId << std::endl
291 <<
" ------ Monitoring FED check " ;
292 if (lFailMonitoringFEDcheck) debugStream <<
"failed." << std::endl;
293 else debugStream <<
"passed." << std::endl ;
294 debugStream <<
" ------ Unpacker FED check " ;
295 if (lFailUnpackerFEDcheck) debugStream <<
"failed." << std::endl;
296 else debugStream <<
"passed." << std::endl ;
297 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
300 if (lFailMonitoringFEDcheck) lNFEDMonitoring++;
301 else if (lFailUnpackerFEDcheck) lNFEDUnpacker++;
310 <<
", TkHistoMap enabled but pointer is null." << std::endl;
317 lNTotBadActiveChannels,
318 lNBadChannels_perFEDID
325 for (
unsigned int iP(0); iP<nParts; ++iP){
328 if (lFeMajFrac[iP].
empty())
continue;
331 unsigned int lMajorityCounter = 0;
332 std::vector<unsigned int> lfedIds;
334 getMajority(lFeMajFrac[iP],lMajorityCounter,lfedIds);
336 fedHists_.fillMajorityHistograms(iP,static_cast<float>(lMajorityCounter)/lFeMajFrac[iP].
size(),lfedIds);
340 if ((lNTotBadFeds> 0 || lNTotBadChannels>0) &&
printDebug_>1) {
341 std::ostringstream debugStream;
342 debugStream <<
"[SiStripFEDMonitorPlugin] --- Total number of bad feds = " 343 << lNTotBadFeds << std::endl
344 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad channels = " 345 << lNTotBadChannels << std::endl
346 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad active channels = " 347 << lNTotBadActiveChannels << std::endl;
348 edm::LogInfo(
"SiStripMonitorHardware") << debugStream.str();
351 if ((lNFEDMonitoring > 0 || lNFEDUnpacker > 0 || lNChannelMonitoring > 0 || lNChannelUnpacker > 0) &&
printDebug_) {
352 std::ostringstream debugStream;
354 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
355 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
356 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at FED level : " << std::endl
357 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNFEDMonitoring << std::endl
358 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNFEDUnpacker << std::endl
359 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
360 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at Channel level : " << std::endl
361 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNChannelMonitoring << std::endl
362 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNChannelUnpacker << std::endl
363 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
364 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl ;
365 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
369 fedErrors_.getFEDErrorsCounters().nTotalBadChannels = lNTotBadChannels;
370 fedErrors_.getFEDErrorsCounters().nTotalBadActiveChannels = lNTotBadActiveChannels;
375 double eventNumber =
static_cast<double>(iEvent.
id().
event());
396 const std::pair<unsigned int, unsigned int> & pair2){
397 return (pair1.second < pair2.second) ;
401 unsigned int & aMajorityCounter,
402 std::vector<unsigned int> & afedIds) {
405 unsigned int lMajAddress = 0;
406 std::vector<std::pair<unsigned int,unsigned int> >::const_iterator lIter = aFeMajVec.begin();
407 unsigned int lMajAddr = (*lIter).second;
408 unsigned int lCounter = 0;
413 for ( ; lIter != aFeMajVec.end(); ++lIter,++iele) {
415 if ((*lIter).second == lMajAddr) {
421 if (lCounter > aMajorityCounter) {
423 aMajorityCounter = lCounter;
425 lMajAddress = lMajAddr;
430 lMajAddr = (*lIter).second;
437 if (lCounter > aMajorityCounter) {
439 aMajorityCounter = lCounter;
440 lMajAddress = lMajAddr;
445 lIter = aFeMajVec.begin();
446 afedIds.reserve(135);
447 for ( ; lIter != aFeMajVec.end(); ++lIter ) {
448 if((*lIter).second != lMajAddress) {
449 afedIds.push_back((*lIter).first);
452 lIter += aMajorityCounter-1;
453 if(lIter >= aFeMajVec.end()) {
454 std::cout <<
"Here it is a bug: " << aMajorityCounter <<
" " << aFeMajVec.size() <<
" " << lIter - aFeMajVec.end() << std::endl;
459 if (!afedIds.empty()) {
460 std::sort(afedIds.begin(),afedIds.end());
461 std::vector<unsigned int>::iterator lIt =
std::unique(afedIds.begin(),afedIds.end());
462 afedIds.erase(lIt,afedIds.end());
475 fedHists_.bookTopLevelHistograms(ibooker, tkDetMap);
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
bool fillAllDetailedHistograms_
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
long long deltaBX(const unsigned int ev2, const unsigned int ev1) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const SiStripFedCabling * cabling_
#define DEFINE_FWK_MODULE(type)
void analyze(const edm::Event &, const edm::EventSetup &) override
void getMajority(const std::vector< std::pair< unsigned int, unsigned int > > &aFeMajVec, unsigned int &aMajorityCounter, std::vector< unsigned int > &afedIds)
std::string topFolderName_
unsigned int maxFedBufferSize_
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
size_t size() const
Lenght of the data buffer in bytes.
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void setCurrentFolder(std::string const &fullpath)
SiStripFEDMonitorPlugin(const edm::ParameterSet &)
def unique(seq, keepstr=True)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
edm::InputTag rawDataTag_
static bool pairComparison(const std::pair< unsigned int, unsigned int > &pair1, const std::pair< unsigned int, unsigned int > &pair2)
edm::EDGetTokenT< EventWithHistory > heToken_
~SiStripFEDMonitorPlugin() override
T const * product() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void updateCabling(const edm::EventSetup &eventSetup)