Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/SiStripCommissioningSummary/interface/SummaryHistogramFactory.h"
0002 #include "DQM/SiStripCommissioningSummary/interface/SummaryGenerator.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <iostream>
0005 #include <sstream>
0006 
0007 using namespace sistrip;
0008 
0009 // -----------------------------------------------------------------------------
0010 //
0011 template <class T>
0012 SummaryHistogramFactory<T>::SummaryHistogramFactory()
0013     : mon_(sistrip::UNKNOWN_MONITORABLE),
0014       pres_(sistrip::UNKNOWN_PRESENTATION),
0015       view_(sistrip::UNKNOWN_VIEW),
0016       level_(sistrip::root_),
0017       gran_(sistrip::UNKNOWN_GRAN),
0018       generator_(nullptr) {
0019   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
0020 }
0021 
0022 // -----------------------------------------------------------------------------
0023 //
0024 template <class T>
0025 SummaryHistogramFactory<T>::~SummaryHistogramFactory() {
0026   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
0027   if (generator_) {
0028     delete generator_;
0029   }
0030 }
0031 
0032 // -----------------------------------------------------------------------------
0033 //
0034 template <class T>
0035 void SummaryHistogramFactory<T>::init(const sistrip::Monitorable& mon,
0036                                       const sistrip::Presentation& pres,
0037                                       const sistrip::View& view,
0038                                       const std::string& top_level_dir,
0039                                       const sistrip::Granularity& gran) {
0040   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
0041   mon_ = mon;
0042   pres_ = pres;
0043   view_ = view;
0044   level_ = top_level_dir;
0045   gran_ = gran;
0046 
0047   // Retrieve utility class used to generate summary histograms
0048   if (generator_) {
0049     delete generator_;
0050     generator_ = nullptr;
0051     generator_ = SummaryGenerator::instance(view);
0052   }
0053 }
0054 
0055 // -----------------------------------------------------------------------------
0056 //
0057 template <class T>
0058 uint32_t SummaryHistogramFactory<T>::extract(const std::map<uint32_t, T>& data) {
0059   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
0060 
0061   // Check if data are present
0062   if (data.empty()) {
0063     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]"
0064                                      << " No data in monitorables std::map!";
0065     return 0;
0066   }
0067 
0068   // Check if instance of generator class exists
0069   if (!generator_) {
0070     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]"
0071                                      << " NULL pointer to SummaryGenerator object!";
0072     return 0;
0073   }
0074 
0075   // Transfer appropriate monitorables info to generator object
0076   generator_->clearMap();
0077   typename std::map<uint32_t, T>::const_iterator iter = data.begin();
0078   for (; iter != data.end(); iter++) {
0079     generator_->fillMap(level_,                             // top-level directory
0080                         gran_,                              // granularity
0081                         iter->first,                        // device key
0082                         static_cast<float>(iter->second));  // value
0083   }
0084 
0085   return generator_->size();
0086 }
0087 
0088 // -----------------------------------------------------------------------------
0089 //
0090 template <class T>
0091 void SummaryHistogramFactory<T>::fill(TH1& summary_histo) {
0092   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
0093 
0094   // Check if instance of generator class exists
0095   if (!generator_) {
0096     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]"
0097                                      << " NULL pointer to SummaryGenerator object!";
0098     return;
0099   }
0100 
0101   // Check if std::map is filled
0102   if (!generator_->size()) {
0103     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]"
0104                                      << " No data in the monitorables std::map!";
0105     return;
0106   }
0107 
0108   // Generate appropriate summary histogram
0109   if (pres_ == sistrip::HISTO_1D) {
0110     generator_->histo1D(summary_histo);
0111   } else if (pres_ == sistrip::HISTO_2D_SUM) {
0112     generator_->histo2DSum(summary_histo);
0113   } else if (pres_ == sistrip::HISTO_2D_SCATTER) {
0114     generator_->histo2DScatter(summary_histo);
0115   } else if (pres_ == sistrip::PROFILE_1D) {
0116     generator_->profile1D(summary_histo);
0117   } else {
0118     return;
0119   }
0120 
0121   // Histogram formatting
0122   generator_->format(sistrip::UNKNOWN_RUN_TYPE, mon_, pres_, view_, level_, gran_, summary_histo);
0123 }
0124 
0125 // -----------------------------------------------------------------------------
0126 //
0127 template class SummaryHistogramFactory<uint32_t>;
0128 template class SummaryHistogramFactory<uint16_t>;
0129 template class SummaryHistogramFactory<float>;