Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:31

0001 #include "DQM/SiStripCommissioningClients/interface/OptoScanHistograms.h"
0002 #include "CondFormats/SiStripObjects/interface/OptoScanAnalysis.h"
0003 #include "DQM/SiStripCommissioningAnalysis/interface/OptoScanAlgorithm.h"
0004 #include "DQM/SiStripCommissioningSummary/interface/OptoScanSummaryFactory.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 OptoScanHistograms::OptoScanHistograms(const edm::ParameterSet& pset, DQMStore* bei)
0021     : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("OptoScanParameters"), bei, sistrip::OPTO_SCAN) {
0022   factory_ = std::make_unique<OptoScanSummaryFactory>();
0023   LogTrace(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]"
0024                          << " Constructing object...";
0025 }
0026 
0027 // -----------------------------------------------------------------------------
0028 /** */
0029 OptoScanHistograms::~OptoScanHistograms() {
0030   LogTrace(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]"
0031                          << " Denstructing object...";
0032 }
0033 
0034 // -----------------------------------------------------------------------------
0035 /** */
0036 void OptoScanHistograms::histoAnalysis(bool debug) {
0037   LogTrace(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]";
0038 
0039   // Some initialisation
0040   uint16_t valid = 0;
0041   HistosMap::const_iterator iter;
0042   Analyses::iterator ianal;
0043   std::map<std::string, uint16_t> errors;
0044 
0045   // Clear map holding analysis objects
0046   for (ianal = data().begin(); ianal != data().end(); ianal++) {
0047     if (ianal->second) {
0048       delete ianal->second;
0049     }
0050   }
0051   data().clear();
0052 
0053   // Iterate through map containing histograms
0054   for (iter = histos().begin(); iter != histos().end(); iter++) {
0055     // Check vector of histos is not empty
0056     if (iter->second.empty()) {
0057       edm::LogWarning(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]"
0058                                     << " Zero histograms found!";
0059       continue;
0060     }
0061 
0062     // Retrieve pointers to histos
0063     std::vector<TH1*> profs;
0064     Histos::const_iterator ihis = iter->second.begin();
0065     for (; ihis != iter->second.end(); ihis++) {
0066       TProfile* prof = ExtractTObject<TProfile>().extract((*ihis)->me_);
0067       if (prof) {
0068         profs.push_back(prof);
0069       }
0070     }
0071 
0072     // Perform histo analysis
0073     OptoScanAnalysis* anal = new OptoScanAnalysis(iter->first);
0074     OptoScanAlgorithm algo(this->pset(), anal);
0075     algo.analysis(profs);
0076     data()[iter->first] = anal;
0077     if (anal->isValid()) {
0078       valid++;
0079     }
0080     if (!anal->getErrorCodes().empty()) {
0081       errors[anal->getErrorCodes()[0]]++;
0082     }
0083   }
0084 
0085   if (!histos().empty()) {
0086     edm::LogVerbatim(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]"
0087                                    << " Analyzed histograms for " << histos().size() << " FED channels, of which "
0088                                    << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
0089   } else {
0090     edm::LogWarning(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]"
0091                                   << " No histograms to analyze!";
0092   }
0093 
0094   if (!histos().empty()) {
0095     edm::LogVerbatim(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]"
0096                                    << " Analyzed histograms for " << histos().size() << " FED channels, of which "
0097                                    << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
0098     if (!errors.empty()) {
0099       uint16_t count = 0;
0100       std::stringstream ss;
0101       ss << std::endl;
0102       std::map<std::string, uint16_t>::const_iterator ii;
0103       for (ii = errors.begin(); ii != errors.end(); ++ii) {
0104         ss << " " << ii->first << ": " << ii->second << std::endl;
0105         count += ii->second;
0106       }
0107       edm::LogWarning(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]"
0108                                     << " Found " << count << " errors (" << 100 * count / histos().size()
0109                                     << "%): " << ss.str();
0110     }
0111   } else {
0112     edm::LogWarning(mlDqmClient_) << "[OptoScanHistograms::" << __func__ << "]"
0113                                   << " No histograms to analyze!";
0114   }
0115 }
0116 
0117 // -----------------------------------------------------------------------------
0118 /** */
0119 void OptoScanHistograms::printAnalyses() {
0120   Analyses::iterator ianal = data().begin();
0121   Analyses::iterator janal = data().end();
0122   for (; ianal != janal; ++ianal) {
0123     if (ianal->second) {
0124       std::stringstream ss;
0125       if (ianal->second->isValid()) {
0126         ianal->second->print(ss);
0127         LogTrace(mlDqmClient_) << ss.str();
0128       } else {
0129         ianal->second->print(ss, 0);
0130         ianal->second->print(ss, 1);
0131         ianal->second->print(ss, 2);
0132         ianal->second->print(ss, 3);
0133         edm::LogWarning(mlDqmClient_) << ss.str();
0134       }
0135     }
0136   }
0137 }