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",
""))),
126 topFolderName_(iConfig.getUntrackedParameter<std::
string>(
"TopFolderName",
"SiStrip")),
127 fillAllDetailedHistograms_(iConfig.getUntrackedParameter<bool>(
"FillAllDetailedHistograms",
false)),
128 fillWithEvtNum_(iConfig.getUntrackedParameter<bool>(
"FillWithEventNumber",
false)),
129 printDebug_(iConfig.getUntrackedParameter<unsigned int>(
"PrintDebugMessages",1)),
131 maxFedBufferSize_(0),
132 fullDebugMode_(iConfig.getUntrackedParameter<bool>(
"FullDebugMode",
false))
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 :
NULL);
155 fedHists_.initialise(iConfig,pDebugStream);
164 LogTrace(
"SiStripMonitorHardware") << debugStream.str();
205 fedErrors_.fillEventProperties(he->deltaBX());
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);
244 bool lDataExist =
fedErrors_.checkDataPresent(fedData);
266 bool lFailUnpackerFEDcheck =
fedErrors_.failUnpackerFEDCheck();
269 unsigned int lSize = fedData.
size();
277 bool lFailMonitoringFEDcheck =
fedErrors_.failMonitoringFEDCheck();
278 if (lFailMonitoringFEDcheck) lNTotBadFeds++;
284 if (lFailMonitoringFEDcheck != lFailUnpackerFEDcheck) {
286 std::ostringstream debugStream;
287 debugStream <<
" --- WARNING: FED " << fedId << std::endl
288 <<
" ------ Monitoring FED check " ;
289 if (lFailMonitoringFEDcheck) debugStream <<
"failed." << std::endl;
290 else debugStream <<
"passed." << std::endl ;
291 debugStream <<
" ------ Unpacker FED check " ;
292 if (lFailUnpackerFEDcheck) debugStream <<
"failed." << std::endl;
293 else debugStream <<
"passed." << std::endl ;
294 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
297 if (lFailMonitoringFEDcheck) lNFEDMonitoring++;
298 else if (lFailUnpackerFEDcheck) lNFEDUnpacker++;
307 <<
", TkHistoMap enabled but pointer is null." << std::endl;
314 lNTotBadActiveChannels);
319 for (
unsigned int iP(0); iP<nParts; ++iP){
322 if (lFeMajFrac[iP].
size()==0)
continue;
325 unsigned int lMajorityCounter = 0;
326 std::vector<unsigned int> lfedIds;
328 getMajority(lFeMajFrac[iP],lMajorityCounter,lfedIds);
330 fedHists_.fillMajorityHistograms(iP,static_cast<float>(lMajorityCounter)/lFeMajFrac[iP].
size(),lfedIds);
334 if ((lNTotBadFeds> 0 || lNTotBadChannels>0) &&
printDebug_>1) {
335 std::ostringstream debugStream;
336 debugStream <<
"[SiStripFEDMonitorPlugin] --- Total number of bad feds = "
337 << lNTotBadFeds << std::endl
338 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad channels = "
339 << lNTotBadChannels << std::endl
340 <<
"[SiStripFEDMonitorPlugin] --- Total number of bad active channels = "
341 << lNTotBadActiveChannels << std::endl;
342 edm::LogInfo(
"SiStripMonitorHardware") << debugStream.str();
345 if ((lNFEDMonitoring > 0 || lNFEDUnpacker > 0 || lNChannelMonitoring > 0 || lNChannelUnpacker > 0) &&
printDebug_) {
346 std::ostringstream debugStream;
348 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
349 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
350 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at FED level : " << std::endl
351 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNFEDMonitoring << std::endl
352 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNFEDUnpacker << std::endl
353 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
354 <<
"[SiStripFEDMonitorPlugin]-- Summary of differences between unpacker and monitoring at Channel level : " << std::endl
355 <<
"[SiStripFEDMonitorPlugin] ---- Number of times monitoring fails but not unpacking = " << lNChannelMonitoring << std::endl
356 <<
"[SiStripFEDMonitorPlugin] ---- Number of times unpacking fails but not monitoring = " << lNChannelUnpacker << std::endl
357 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl
358 <<
"[SiStripFEDMonitorPlugin]-------------------------------------------------------------------------" << std::endl ;
359 edm::LogError(
"SiStripMonitorHardware") << debugStream.str();
363 fedErrors_.getFEDErrorsCounters().nTotalBadChannels = lNTotBadChannels;
364 fedErrors_.getFEDErrorsCounters().nTotalBadActiveChannels = lNTotBadActiveChannels;
369 double eventNumber =
static_cast<double>(iEvent.
id().
event());
390 const std::pair<unsigned int, unsigned int> & pair2){
391 return (pair1.second < pair2.second) ;
395 unsigned int & aMajorityCounter,
396 std::vector<unsigned int> & afedIds) {
399 unsigned int lMajAddress = 0;
400 std::vector<std::pair<unsigned int,unsigned int> >::const_iterator lIter = aFeMajVec.begin();
401 unsigned int lMajAddr = (*lIter).second;
402 unsigned int lCounter = 0;
407 for ( ; lIter != aFeMajVec.end(); ++lIter,++iele) {
409 if ((*lIter).second == lMajAddr) {
415 if (lCounter > aMajorityCounter) {
417 aMajorityCounter = lCounter;
419 lMajAddress = lMajAddr;
424 lMajAddr = (*lIter).second;
431 if (lCounter > aMajorityCounter) {
433 aMajorityCounter = lCounter;
434 lMajAddress = lMajAddr;
439 lIter = aFeMajVec.begin();
440 afedIds.reserve(135);
441 for ( ; lIter != aFeMajVec.end(); ++lIter ) {
442 if((*lIter).second != lMajAddress) {
443 afedIds.push_back((*lIter).first);
446 lIter += aMajorityCounter-1;
447 if(lIter >= aFeMajVec.end()) {
448 std::cout <<
"Here it is a bug: " << aMajorityCounter <<
" " << aFeMajVec.size() <<
" " << lIter - aFeMajVec.end() << std::endl;
453 if (afedIds.size()>0) {
454 std::sort(afedIds.begin(),afedIds.end());
455 std::vector<unsigned int>::iterator lIt = std::unique(afedIds.begin(),afedIds.end());
456 afedIds.erase(lIt,afedIds.end());
464 fedHists_.bookTopLevelHistograms(ibooker);
EventNumber_t event() const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< FEDRawDataCollection > rawDataToken_
~SiStripFEDMonitorPlugin()
bool fillAllDetailedHistograms_
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 setCurrentFolder(const std::string &fullpath)
T const * product() const
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_
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
tuple size
Write out results.
void updateCabling(const edm::EventSetup &eventSetup)