51 #include "DQM/SiStripMonitorHardware/interface/FEDHistograms.hh"
52 #include "DQM/SiStripMonitorHardware/interface/FEDErrors.hh"
69 virtual void endJob()
override;
78 static bool pairComparison(
const std::pair<unsigned int, unsigned int> & pair1,
79 const std::pair<unsigned int, unsigned int> & pair2);
81 void getMajority(
const std::vector<std::pair<unsigned int,unsigned int> > & aFeMajVec,
82 unsigned int & aMajorityCounter,
83 std::vector<unsigned int> & afedIds);
130 : rawDataTag_(iConfig.getUntrackedParameter<edm::InputTag>(
"RawDataTag",edm::InputTag(
"source",
""))),
131 topFolderName_(iConfig.getUntrackedParameter<std::
string>(
"TopFolderName",
"SiStrip")),
132 fillAllDetailedHistograms_(iConfig.getUntrackedParameter<bool>(
"FillAllDetailedHistograms",
false)),
133 fillWithEvtNum_(iConfig.getUntrackedParameter<bool>(
"FillWithEventNumber",
false)),
134 printDebug_(iConfig.getUntrackedParameter<unsigned int>(
"PrintDebugMessages",1)),
136 writeDQMStore_(iConfig.getUntrackedParameter<bool>(
"WriteDQMStore",
false)),
137 dqmStoreFileName_(iConfig.getUntrackedParameter<std::
string>(
"DQMStoreFileName",
"DQMStore.root")),
150 std::ostringstream debugStream;
152 debugStream <<
"[SiStripFEDMonitorPlugin]Configuration for SiStripFEDMonitorPlugin: " << std::endl
153 <<
"[SiStripFEDMonitorPlugin]\tRawDataTag: " <<
rawDataTag_ << std::endl
154 <<
"[SiStripFEDMonitorPlugin]\tHistogramFolderName: " << folderName_ << std::endl
156 <<
"[SiStripFEDMonitorPlugin]\tFillWithEventNumber?" << (
fillWithEvtNum_ ?
"yes" :
"no") << std::endl
157 <<
"[SiStripFEDMonitorPlugin]\tPrintDebugMessages? " << (
printDebug_ ?
"yes" :
"no") << std::endl
158 <<
"[SiStripFEDMonitorPlugin]\tWriteDQMStore? " << (
writeDQMStore_ ?
"yes" :
"no") << std::endl;
163 std::ostringstream* pDebugStream = (
printDebug_>1 ? &debugStream :
NULL);
165 fedHists_.initialise(iConfig,pDebugStream);
174 LogTrace(
"SiStripMonitorHardware") << debugStream.str();
225 fedErrors_.fillEventProperties(he->deltaBX());
229 std::map<unsigned int,std::pair<unsigned short,unsigned short> > badChannelFraction;
231 unsigned int lNFEDMonitoring = 0;
232 unsigned int lNFEDUnpacker = 0;
233 unsigned int lNChannelMonitoring = 0;
234 unsigned int lNChannelUnpacker = 0;
236 unsigned int lNTotBadFeds = 0;
237 unsigned int lNTotBadChannels = 0;
238 unsigned int lNTotBadActiveChannels = 0;
240 std::vector<std::vector<std::pair<unsigned int,unsigned int> > > lFeMajFrac;
241 const unsigned int nParts = 4;
243 lFeMajFrac.resize(nParts);
245 lFeMajFrac[0].reserve(912);
246 lFeMajFrac[1].reserve(1080);
247 lFeMajFrac[2].reserve(768);
248 lFeMajFrac[3].reserve(760);
261 bool lFullDebug =
false;
265 bool lDataExist =
fedErrors_.checkDataPresent(fedData);
287 bool lFailUnpackerFEDcheck =
fedErrors_.failUnpackerFEDCheck();
290 unsigned int lSize = fedData.
size();
298 bool lFailMonitoringFEDcheck =
fedErrors_.failMonitoringFEDCheck();
299 if (lFailMonitoringFEDcheck) lNTotBadFeds++;
305 if (lFailMonitoringFEDcheck != lFailUnpackerFEDcheck) {
307 std::ostringstream debugStream;
308 debugStream <<
" --- WARNING: FED " << fedId << std::endl
309 <<
" ------ Monitoring FED check " ;
310 if (lFailMonitoringFEDcheck) debugStream <<
"failed." << std::endl;
311 else debugStream <<
"passed." << std::endl ;
312 debugStream <<
" ------ Unpacker FED check " ;
313 if (lFailUnpackerFEDcheck) debugStream <<
"failed." << std::endl;
314 else debugStream <<
"passed." << std::endl ;
315 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
318 if (lFailMonitoringFEDcheck) lNFEDMonitoring++;
319 else if (lFailUnpackerFEDcheck) lNFEDUnpacker++;
328 <<
", TkHistoMap enabled but pointer is null." << std::endl;
335 lNTotBadActiveChannels);
340 for (
unsigned int iP(0); iP<nParts; ++iP){
343 if (lFeMajFrac[iP].
size()==0)
continue;
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 = "
358 << lNTotBadFeds << std::endl
359 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad channels = "
360 << lNTotBadChannels << std::endl
361 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad active channels = "
362 << lNTotBadActiveChannels << std::endl;
363 edm::LogInfo(
"SiStripMonitorHardware") << debugStream.str();
366 if ((lNFEDMonitoring > 0 || lNFEDUnpacker > 0 || lNChannelMonitoring > 0 || lNChannelUnpacker > 0) &&
printDebug_) {
367 std::ostringstream debugStream;
369 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
370 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
371 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at FED level : " << std::endl
372 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNFEDMonitoring << std::endl
373 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNFEDUnpacker << std::endl
374 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
375 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at Channel level : " << std::endl
376 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNChannelMonitoring << std::endl
377 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNChannelUnpacker << std::endl
378 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
379 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl ;
380 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
384 FEDErrors::getFEDErrorsCounters().nTotalBadChannels = lNTotBadChannels;
385 FEDErrors::getFEDErrorsCounters().nTotalBadActiveChannels = lNTotBadActiveChannels;
398 const std::pair<unsigned int, unsigned int> & pair2){
399 return (pair1.second < pair2.second) ;
403 unsigned int & aMajorityCounter,
404 std::vector<unsigned int> & afedIds) {
407 unsigned int lMajAddress = 0;
408 std::vector<std::pair<unsigned int,unsigned int> >::const_iterator lIter = aFeMajVec.begin();
409 unsigned int lMajAddr = (*lIter).second;
410 unsigned int lCounter = 0;
415 for ( ; lIter != aFeMajVec.end(); ++lIter,++iele) {
417 if ((*lIter).second == lMajAddr) {
423 if (lCounter > aMajorityCounter) {
425 aMajorityCounter = lCounter;
427 lMajAddress = lMajAddr;
432 lMajAddr = (*lIter).second;
439 if (lCounter > aMajorityCounter) {
441 aMajorityCounter = lCounter;
442 lMajAddress = lMajAddr;
447 lIter = aFeMajVec.begin();
448 afedIds.reserve(135);
449 for ( ; lIter != aFeMajVec.end(); ++lIter ) {
450 if((*lIter).second != lMajAddress) {
451 afedIds.push_back((*lIter).first);
454 lIter += aMajorityCounter-1;
455 if(lIter >= aFeMajVec.end()) {
456 std::cout <<
"Here it is a bug: " << aMajorityCounter <<
" " << aFeMajVec.size() <<
" " << lIter - aFeMajVec.end() << std::endl;
461 if (afedIds.size()>0) {
462 std::sort(afedIds.begin(),afedIds.end());
463 std::vector<unsigned int>::iterator lIt = std::unique(afedIds.begin(),afedIds.end());
464 afedIds.erase(lIt,afedIds.end());
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
~SiStripFEDMonitorPlugin()
std::string dqmStoreFileName_
bool fillAllDetailedHistograms_
virtual void endJob() override
virtual void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &context) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const SiStripFedCabling * cabling_
#define DEFINE_FWK_MODULE(type)
virtual 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_
virtual 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
SiStripFEDMonitorPlugin(const edm::ParameterSet &)
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
T const * product() const
virtual void beginJob() override
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)
volatile std::atomic< bool > shutdown_flag false
edm::EDGetTokenT< EventWithHistory > heToken_
tuple size
Write out results.
void setCurrentFolder(const std::string &fullpath)
void updateCabling(const edm::EventSetup &eventSetup)