Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/SiStripCommissioningSummary/interface/SummaryPlot.h"
0002 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 using namespace sistrip;
0006 
0007 // -----------------------------------------------------------------------------
0008 //
0009 SummaryPlot::SummaryPlot(const std::string& monitorable,
0010                          const std::string& presentation,
0011                          const std::string& granularity,
0012                          const std::string& level)
0013     : mon_(sistrip::UNKNOWN_MONITORABLE),
0014       pres_(sistrip::UNKNOWN_PRESENTATION),
0015       view_(sistrip::UNKNOWN_VIEW),
0016       gran_(sistrip::UNKNOWN_GRAN),
0017       level_(""),
0018       isValid_(false) {
0019   // Extract enums from strings
0020   mon_ = SiStripEnumsAndStrings::monitorable(monitorable);
0021   pres_ = SiStripEnumsAndStrings::presentation(presentation);
0022   gran_ = SiStripEnumsAndStrings::granularity(granularity);
0023   level_ = level;
0024 
0025   // Extract view and perform checks
0026   check();
0027   isValid_ = true;
0028 
0029   // Checks on member data
0030   if (mon_ == sistrip::UNKNOWN_MONITORABLE || mon_ == sistrip::UNDEFINED_MONITORABLE) {
0031     edm::LogWarning(mlSummaryPlots_) << "[SummaryPlot::" << __func__ << "]"
0032                                      << " Unexpected monitorable \"" << SiStripEnumsAndStrings::monitorable(mon_)
0033                                      << "\" based on input string \"" << monitorable << "\"";
0034     isValid_ = false;
0035   }
0036 
0037   if (pres_ == sistrip::UNKNOWN_PRESENTATION || pres_ == sistrip::UNDEFINED_PRESENTATION) {
0038     edm::LogWarning(mlSummaryPlots_) << "[SummaryPlot::" << __func__ << "]"
0039                                      << " Unexpected presentation \"" << SiStripEnumsAndStrings::presentation(pres_)
0040                                      << "\" based on input string \"" << presentation << "\"";
0041     isValid_ = false;
0042   }
0043 
0044   if (view_ == sistrip::UNKNOWN_VIEW || view_ == sistrip::UNDEFINED_VIEW) {
0045     edm::LogWarning(mlSummaryPlots_) << "[SummaryPlot::" << __func__ << "]"
0046                                      << " Unexpected view \"" << SiStripEnumsAndStrings::view(level_)
0047                                      << "\" based on input string \"" << level << "\"";
0048     isValid_ = false;
0049   }
0050 
0051   if (level_.empty() || level_.find(sistrip::unknownView_) != std::string::npos ||
0052       level_.find(sistrip::undefinedView_) != std::string::npos) {
0053     edm::LogWarning(mlSummaryPlots_) << "[SummaryPlot::" << __func__ << "]"
0054                                      << " Unexpected top-level directory: \"" << level_ << "\"";
0055     isValid_ = false;
0056   }
0057 
0058   if (gran_ == sistrip::UNKNOWN_GRAN || (gran_ == sistrip::UNDEFINED_GRAN && pres_ != sistrip::HISTO_1D)) {
0059     edm::LogWarning(mlSummaryPlots_) << "[SummaryPlot::" << __func__ << "]"
0060                                      << " Unexpected granularity: \"" << SiStripEnumsAndStrings::granularity(gran_)
0061                                      << "\" based on input string \"" << granularity << "\"";
0062     isValid_ = false;
0063   }
0064 }
0065 
0066 // -----------------------------------------------------------------------------
0067 //
0068 SummaryPlot::SummaryPlot(const SummaryPlot& input)
0069     : mon_(input.monitorable()),
0070       pres_(input.presentation()),
0071       view_(input.view()),
0072       gran_(input.granularity()),
0073       level_(input.level()),
0074       isValid_(input.isValid()) {
0075   ;
0076 }
0077 
0078 // -----------------------------------------------------------------------------
0079 //
0080 SummaryPlot::SummaryPlot()
0081     : mon_(sistrip::UNKNOWN_MONITORABLE),
0082       pres_(sistrip::UNKNOWN_PRESENTATION),
0083       view_(sistrip::UNKNOWN_VIEW),
0084       gran_(sistrip::UNKNOWN_GRAN),
0085       level_(""),
0086       isValid_(false) {
0087   ;
0088 }
0089 
0090 // -----------------------------------------------------------------------------
0091 //
0092 void SummaryPlot::reset() {
0093   mon_ = sistrip::UNKNOWN_MONITORABLE;
0094   pres_ = sistrip::UNKNOWN_PRESENTATION;
0095   view_ = sistrip::UNKNOWN_VIEW;
0096   gran_ = sistrip::UNKNOWN_GRAN;
0097   level_ = "";
0098   isValid_ = false;
0099 }
0100 
0101 // -----------------------------------------------------------------------------
0102 //
0103 void SummaryPlot::check() {
0104   // Remove end "/" from level_ if it exists
0105   if (!level_.empty()) {
0106     std::string slash = level_.substr(level_.size() - 1, 1);
0107     if (slash == sistrip::dir_) {
0108       level_ = level_.substr(0, level_.size() - 1);
0109     }
0110   }
0111 
0112   // Extract and check view
0113   sistrip::View check = SiStripEnumsAndStrings::view(level_);
0114   view_ = check;
0115   if (check == sistrip::UNKNOWN_VIEW || check == sistrip::UNDEFINED_VIEW) {
0116     edm::LogWarning(mlSummaryPlots_) << "[SummaryPlot::" << __func__ << "]"
0117                                      << " Unexpected view \"" << SiStripEnumsAndStrings::view(check) << "\"";
0118   }
0119 
0120   // Prepend sistrip::root_ to level_ if not found
0121   if (level_.find(sistrip::root_) == std::string::npos) {
0122     if (check == sistrip::UNKNOWN_VIEW) {
0123       level_ = std::string(sistrip::root_) + sistrip::dir_ + sistrip::unknownView_ + sistrip::dir_ + level_;
0124     } else if (check == sistrip::UNDEFINED_VIEW) {
0125       level_ = std::string(sistrip::root_) + sistrip::dir_ + sistrip::undefinedView_ + sistrip::dir_ + level_;
0126     } else {
0127       level_ = std::string(sistrip::root_) + sistrip::dir_ + level_;
0128     }
0129   }
0130 }
0131 
0132 // -----------------------------------------------------------------------------
0133 //
0134 void SummaryPlot::print(std::stringstream& ss) const {
0135   ss << "[SummaryPlot::" << __func__ << "]" << std::endl
0136      << " Monitorable:  " << SiStripEnumsAndStrings::monitorable(mon_) << std::endl
0137      << " Presentation: " << SiStripEnumsAndStrings::presentation(pres_) << std::endl
0138      << " View:         " << SiStripEnumsAndStrings::view(view_) << std::endl
0139      << " TopLevelDir:  " << level_ << std::endl
0140      << " Granularity:  " << SiStripEnumsAndStrings::granularity(gran_) << std::endl;
0141 }
0142 
0143 // -----------------------------------------------------------------------------
0144 //
0145 std::ostream& operator<<(std::ostream& os, const SummaryPlot& summary) {
0146   std::stringstream ss;
0147   summary.print(ss);
0148   os << ss.str();
0149   return os;
0150 }