Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/SiStripCommissioningClients/interface/VpspScanHistograms.h"
0002 #include "CondFormats/SiStripObjects/interface/VpspScanAnalysis.h"
0003 #include "DQM/SiStripCommissioningAnalysis/interface/VpspScanAlgorithm.h"
0004 #include "DQM/SiStripCommissioningSummary/interface/VpspScanSummaryFactory.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 VpspScanHistograms::VpspScanHistograms(const edm::ParameterSet& pset, DQMStore* bei)
0021     : CommissioningHistograms(pset.getParameter<edm::ParameterSet>("VpspScanParameters"), bei, sistrip::VPSP_SCAN) {
0022   factory_ = std::make_unique<VpspScanSummaryFactory>();
0023   LogTrace(mlDqmClient_) << "[VpspScanHistograms::" << __func__ << "]"
0024                          << " Constructing object...";
0025 }
0026 
0027 // -----------------------------------------------------------------------------
0028 /** */
0029 VpspScanHistograms::~VpspScanHistograms() {
0030   LogTrace(mlDqmClient_) << "[VpspScanHistograms::" << __func__ << "]"
0031                          << " Denstructing object...";
0032 }
0033 
0034 // -----------------------------------------------------------------------------
0035 /** */
0036 void VpspScanHistograms::histoAnalysis(bool debug) {
0037   LogTrace(mlDqmClient_) << "[VpspScanHistograms::" << __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_) << "[VpspScanHistograms::" << __func__ << "]"
0058                                     << " Zero histograms found!" << endl;
0059       continue;
0060     }
0061 
0062     // Retrieve pointers to profile histos for this FED channel
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     VpspScanAnalysis* anal = new VpspScanAnalysis(iter->first);
0074     VpspScanAlgorithm 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_) << "[VpspScanHistograms::" << __func__ << "]"
0087                                    << " Analyzed histograms for " << histos().size() << " FED channels, of which "
0088                                    << valid << " (" << 100 * valid / histos().size() << "%) are valid.";
0089     if (!errors.empty()) {
0090       uint16_t count = 0;
0091       std::stringstream ss;
0092       ss << std::endl;
0093       std::map<std::string, uint16_t>::const_iterator ii;
0094       for (ii = errors.begin(); ii != errors.end(); ++ii) {
0095         ss << " " << ii->first << ": " << ii->second << std::endl;
0096         count += ii->second;
0097       }
0098       edm::LogWarning(mlDqmClient_) << "[VpspScanHistograms::" << __func__ << "]"
0099                                     << " Found " << count << " errors (" << 100 * count / histos().size()
0100                                     << "%): " << ss.str();
0101     }
0102   } else {
0103     edm::LogWarning(mlDqmClient_) << "[VpspScanHistograms::" << __func__ << "]"
0104                                   << " No histograms to analyze!";
0105   }
0106 }
0107 
0108 // -----------------------------------------------------------------------------
0109 /** */
0110 void VpspScanHistograms::printAnalyses() {
0111   Analyses::iterator ianal = data().begin();
0112   Analyses::iterator janal = data().end();
0113   for (; ianal != janal; ++ianal) {
0114     if (ianal->second) {
0115       std::stringstream ss;
0116       ianal->second->print(ss, 1);
0117       ianal->second->print(ss, 2);
0118       if (ianal->second->isValid()) {
0119         LogTrace(mlDqmClient_) << ss.str();
0120       } else {
0121         edm::LogWarning(mlDqmClient_) << ss.str();
0122       }
0123     }
0124   }
0125 }