CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/DQM/SiStripCommissioningSummary/src/SummaryHistogramFactory.cc

Go to the documentation of this file.
00001 #include "DQM/SiStripCommissioningSummary/interface/SummaryHistogramFactory.h"
00002 #include "DQM/SiStripCommissioningSummary/interface/SummaryGenerator.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include <iostream>
00005 #include <sstream>
00006 
00007 using namespace sistrip;
00008 
00009 // -----------------------------------------------------------------------------
00010 //
00011 template<class T> 
00012 SummaryHistogramFactory<T>::SummaryHistogramFactory() :
00013   mon_(sistrip::UNKNOWN_MONITORABLE),
00014   pres_(sistrip::UNKNOWN_PRESENTATION),
00015   view_(sistrip::UNKNOWN_VIEW),
00016   level_(sistrip::root_),
00017   gran_(sistrip::UNKNOWN_GRAN),
00018   generator_(0) 
00019 {
00020   LogTrace(mlSummaryPlots_) 
00021     << "[SummaryHistogramFactory::" << __func__ << "]";
00022 } 
00023 
00024 // -----------------------------------------------------------------------------
00025 //
00026 template<class T> 
00027 SummaryHistogramFactory<T>::~SummaryHistogramFactory() {
00028   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
00029   if ( generator_ ) { delete generator_; }
00030 }
00031 
00032 // -----------------------------------------------------------------------------
00033 //
00034 template<class T> 
00035 void SummaryHistogramFactory<T>::init( const sistrip::Monitorable& mon, 
00036                                        const sistrip::Presentation& pres,
00037                                        const sistrip::View& view, 
00038                                        const std::string& top_level_dir, 
00039                                        const sistrip::Granularity& gran ) {
00040   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
00041   mon_ = mon;
00042   pres_ = pres;
00043   view_ = view;
00044   level_ = top_level_dir;
00045   gran_ = gran;
00046 
00047   // Retrieve utility class used to generate summary histograms
00048   if ( generator_ ) { 
00049     delete generator_;
00050     generator_ = 0;
00051     generator_ = SummaryGenerator::instance( view );
00052   }
00053   
00054 }
00055 
00056 // -----------------------------------------------------------------------------
00057 //
00058 template<class T> 
00059 uint32_t SummaryHistogramFactory<T>::extract( const std::map<uint32_t,T>& data ) {
00060   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
00061   
00062   // Check if data are present
00063   if ( data.empty() ) { 
00064     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]" 
00065                                      << " No data in monitorables std::map!";
00066     return 0; 
00067   }
00068   
00069   // Check if instance of generator class exists
00070   if ( !generator_ ) { 
00071     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]" 
00072          << " NULL pointer to SummaryGenerator object!";
00073     return 0;
00074   }
00075   
00076   // Transfer appropriate monitorables info to generator object
00077   generator_->clearMap();
00078   typename std::map<uint32_t,T>::const_iterator iter = data.begin();
00079   for ( ; iter != data.end(); iter++ ) {
00080     generator_->fillMap( level_,                             // top-level directory
00081                          gran_,                              // granularity
00082                          iter->first,                        // device key
00083                          static_cast<float>(iter->second) ); // value
00084   }
00085   
00086   return generator_->size();
00087 }
00088 
00089 // -----------------------------------------------------------------------------
00090 //
00091 template<class T> 
00092 void SummaryHistogramFactory<T>::fill( TH1& summary_histo ) {
00093   LogTrace(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]";
00094   
00095   // Check if instance of generator class exists
00096   if ( !generator_ ) { 
00097     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]" 
00098          << " NULL pointer to SummaryGenerator object!";
00099     return;
00100   }
00101 
00102   // Check if instance of generator class exists
00103   if ( !(&summary_histo) ) { 
00104     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]" 
00105          << " NULL pointer to SummaryGenerator object!";
00106     return;
00107   }
00108 
00109   // Check if std::map is filled
00110   if ( !generator_->size() ) { 
00111     edm::LogWarning(mlSummaryPlots_) << "[SummaryHistogramFactory::" << __func__ << "]" 
00112          << " No data in the monitorables std::map!";
00113     return; 
00114   } 
00115   
00116   // Generate appropriate summary histogram 
00117   if ( pres_ == sistrip::HISTO_1D ) {
00118     generator_->histo1D( summary_histo );
00119   } else if ( pres_ == sistrip::HISTO_2D_SUM ) {
00120     generator_->histo2DSum( summary_histo );
00121   } else if ( pres_ == sistrip::HISTO_2D_SCATTER ) {
00122     generator_->histo2DScatter( summary_histo );
00123   } else if ( pres_ == sistrip::PROFILE_1D ) {
00124     generator_->profile1D( summary_histo );
00125   } else { return; }
00126   
00127   // Histogram formatting
00128   generator_->format( sistrip::UNKNOWN_RUN_TYPE, mon_, pres_, view_, level_, gran_, summary_histo );
00129   
00130 }
00131 
00132 // -----------------------------------------------------------------------------
00133 //
00134 template class SummaryHistogramFactory<uint32_t>;
00135 template class SummaryHistogramFactory<uint16_t>;
00136 template class SummaryHistogramFactory<float>;
00137