Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:31

0001 #include "DQM/SiStripCommissioningClients/interface/FastFedCablingHistograms.h"
0002 #include "CondFormats/SiStripObjects/interface/FastFedCablingAnalysis.h"
0003 #include "DQM/SiStripCommissioningAnalysis/interface/FastFedCablingAlgorithm.h"
0004 #include "DQM/SiStripCommissioningSummary/interface/FastFedCablingSummaryFactory.h"
0005 #include "DQM/SiStripCommon/interface/ExtractTObject.h"
0006 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "TProfile.h"
0009 #include <iostream>
0010 #include <memory>
0011 
0012 #include <sstream>
0013 #include <iomanip>
0014 
0015 using namespace std;
0016 using namespace sistrip;
0017 
0018 // -----------------------------------------------------------------------------
0019 /** */
0020 FastFedCablingHistograms::FastFedCablingHistograms(const edm::ParameterSet& pset, DQMStore* bei)
0021     : CommissioningHistograms(
0022           pset.getParameter<edm::ParameterSet>("FastFedCablingParameters"), bei, sistrip::FAST_CABLING) {
0023   factory_ = std::make_unique<FastFedCablingSummaryFactory>();
0024   LogTrace(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0025                          << " Constructing object...";
0026 }
0027 
0028 // -----------------------------------------------------------------------------
0029 /** */
0030 FastFedCablingHistograms::~FastFedCablingHistograms() {
0031   LogTrace(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0032                          << " Destructing object...";
0033 }
0034 
0035 // -----------------------------------------------------------------------------
0036 /** */
0037 void FastFedCablingHistograms::histoAnalysis(bool debug) {
0038   LogTrace(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]";
0039 
0040   // Some initialisation
0041   uint16_t valid = 0;
0042   HistosMap::const_iterator iter;
0043   Analyses::iterator ianal;
0044   std::map<std::string, uint16_t> errors;
0045 
0046   // Clear map holding analysis objects
0047   for (ianal = data().begin(); ianal != data().end(); ianal++) {
0048     if (ianal->second) {
0049       delete ianal->second;
0050     }
0051   }
0052   data().clear();
0053 
0054   // Iterate through map containing histograms
0055   for (iter = histos().begin(); iter != histos().end(); iter++) {
0056     // Check vector of histos is not empty
0057     if (iter->second.empty()) {
0058       edm::LogWarning(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0059                                     << " Zero histograms found!";
0060       continue;
0061     }
0062 
0063     // Retrieve pointers to histos
0064     std::vector<TH1*> profs;
0065     Histos::const_iterator ihis = iter->second.begin();
0066     for (; ihis != iter->second.end(); ihis++) {
0067       TProfile* prof = ExtractTObject<TProfile>().extract((*ihis)->me_);
0068       if (prof) {
0069         profs.push_back(prof);
0070       }
0071     }
0072 
0073     // Perform histo analysis
0074     FastFedCablingAnalysis* anal = new FastFedCablingAnalysis(iter->first);
0075     FastFedCablingAlgorithm algo(this->pset(), anal);
0076     FedToFecMap::const_iterator ifed = mapping().find(iter->first);
0077     if (ifed != mapping().end()) {
0078       anal->fecKey(ifed->second);
0079     }
0080     algo.analysis(profs);
0081     data()[iter->first] = anal;
0082     if (anal->isValid()) {
0083       valid++;
0084     }
0085     if (!anal->getErrorCodes().empty()) {
0086       errors[anal->getErrorCodes()[0]]++;
0087     }
0088   }
0089 
0090   if (!histos().empty()) {
0091     edm::LogVerbatim(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0092                                    << " Analyzed histograms for " << histos().size() << " FED channels, of which "
0093                                    << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
0094     if (!errors.empty()) {
0095       uint16_t count = 0;
0096       std::stringstream ss;
0097       ss << std::endl;
0098       std::map<std::string, uint16_t>::const_iterator ii;
0099       for (ii = errors.begin(); ii != errors.end(); ++ii) {
0100         ss << " " << ii->first << ": " << ii->second << std::endl;
0101         count += ii->second;
0102       }
0103       edm::LogWarning(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0104                                     << " Found " << count << " error strings: " << ss.str();
0105     }
0106   } else {
0107     edm::LogWarning(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0108                                   << " No histograms to analyze!";
0109   }
0110 }
0111 
0112 // -----------------------------------------------------------------------------
0113 /** */
0114 void FastFedCablingHistograms::printAnalyses() {
0115   Analyses::iterator ianal = data().begin();
0116   Analyses::iterator janal = data().end();
0117   for (; ianal != janal; ++ianal) {
0118     FastFedCablingAnalysis* anal = dynamic_cast<FastFedCablingAnalysis*>(ianal->second);
0119     if (!anal) {
0120       edm::LogError(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0121                                   << " NULL pointer to analysis object!";
0122       continue;
0123     }
0124 
0125     std::stringstream ss;
0126     anal->print(ss);
0127     if (anal->isValid() && !(anal->isDirty()) && !(anal->badTrimDac())) {
0128       LogTrace(mlDqmClient_) << ss.str();
0129     } else {
0130       edm::LogWarning(mlDqmClient_) << ss.str();
0131     }
0132   }
0133 }
0134 
0135 // -----------------------------------------------------------------------------
0136 /** */
0137 void FastFedCablingHistograms::printSummary() {
0138   std::stringstream good;
0139   std::stringstream bad;
0140 
0141   Analyses::iterator ianal = data().begin();
0142   Analyses::iterator janal = data().end();
0143   for (; ianal != janal; ++ianal) {
0144     FastFedCablingAnalysis* anal = dynamic_cast<FastFedCablingAnalysis*>(ianal->second);
0145     if (!anal) {
0146       edm::LogError(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0147                                   << " NULL pointer to analysis object!";
0148       continue;
0149     }
0150 
0151     if (anal->isValid() && !(anal->isDirty()) && !(anal->badTrimDac())) {
0152       anal->summary(good);
0153     } else {
0154       anal->summary(bad);
0155     }
0156   }
0157 
0158   if (good.str().empty()) {
0159     good << "None found!";
0160   }
0161   LogTrace(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0162                          << " Printing summary of good analyses:"
0163                          << "\n"
0164                          << good.str();
0165 
0166   if (bad.str().empty()) {
0167     return;
0168   }  //@@ bad << "None found!"; }
0169   LogTrace(mlDqmClient_) << "[FastFedCablingHistograms::" << __func__ << "]"
0170                          << " Printing summary of bad analyses:"
0171                          << "\n"
0172                          << bad.str();
0173 }