Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/SiStripCommissioningClients/interface/SummaryPlotXmlParser.h"
0002 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include <stdexcept>
0005 
0006 using namespace sistrip;
0007 
0008 // -----------------------------------------------------------------------------
0009 //
0010 const std::string SummaryPlotXmlParser::rootTag_ = "root";
0011 const std::string SummaryPlotXmlParser::runTypeTag_ = "RunType";
0012 const std::string SummaryPlotXmlParser::runTypeAttr_ = "name";
0013 const std::string SummaryPlotXmlParser::summaryPlotTag_ = "SummaryPlot";
0014 const std::string SummaryPlotXmlParser::monitorableAttr_ = "monitorable";
0015 const std::string SummaryPlotXmlParser::presentationAttr_ = "presentation";
0016 const std::string SummaryPlotXmlParser::viewAttr_ = "view";
0017 const std::string SummaryPlotXmlParser::levelAttr_ = "level";
0018 const std::string SummaryPlotXmlParser::granularityAttr_ = "granularity";
0019 
0020 // -----------------------------------------------------------------------------
0021 //
0022 SummaryPlotXmlParser::SummaryPlotXmlParser() { plots_.clear(); }
0023 
0024 // -----------------------------------------------------------------------------
0025 //
0026 std::vector<SummaryPlot> SummaryPlotXmlParser::summaryPlots(const sistrip::RunType& run_type) {
0027   if (plots_.empty()) {
0028     edm::LogWarning(mlDqmClient_) << "[SummaryPlotXmlParser" << __func__ << "]"
0029                                   << " You have not called the parseXML function,"
0030                                   << " or your XML file is erronious" << std::endl;
0031   }
0032   if (plots_.find(run_type) != plots_.end()) {
0033     return plots_[run_type];
0034   } else {
0035     return std::vector<SummaryPlot>();
0036   }
0037 }
0038 
0039 // -----------------------------------------------------------------------------
0040 //
0041 void SummaryPlotXmlParser::parseXML(const std::string& filename) {
0042   plots_.clear();
0043 
0044   boost::property_tree::ptree xmltree;
0045   boost::property_tree::read_xml(filename, xmltree);
0046 
0047   auto runs = xmltree.find(rootTag_);
0048   if (runs == xmltree.not_found()) {
0049   }
0050 
0051   // Iterate through nodes
0052   for (auto& xml : xmltree) {
0053     if (xml.first == rootTag_) {  // find main root
0054       for (auto& runtype : xml.second) {
0055         if (runtype.first == runTypeTag_) {  // enter in the run type
0056           sistrip::RunType run_type =
0057               SiStripEnumsAndStrings::runType(runtype.second.get<std::string>("<xmlattr>." + runTypeAttr_));
0058           for (auto& sumplot : runtype.second) {
0059             if (sumplot.first == summaryPlotTag_) {
0060               std::string mon = sumplot.second.get<std::string>("<xmlattr>." + monitorableAttr_);
0061               std::string pres = sumplot.second.get<std::string>("<xmlattr>." + presentationAttr_);
0062               std::string level = sumplot.second.get<std::string>("<xmlattr>." + levelAttr_);
0063               std::string gran = sumplot.second.get<std::string>("<xmlattr>." + granularityAttr_);
0064               SummaryPlot plot(mon, pres, gran, level);
0065               plots_[run_type].push_back(plot);
0066             }
0067           }
0068           if (plots_[run_type].empty()) {
0069             std::stringstream ss;
0070             ss << "[SummaryPlotXmlParser::" << __func__ << "]"
0071                << " Unable to find any summary plot for " << runTypeTag_ << " nodes!"
0072                << " Empty xml summary histo block?";
0073             throw(std::runtime_error(ss.str()));
0074             return;
0075           }
0076         } else {
0077           std::stringstream ss;
0078           ss << "[SummaryPlotXmlParser::" << __func__ << "]"
0079              << " Unable to find any " << runTypeTag_ << " nodes!"
0080              << " Empty xml run-type block?";
0081           throw(std::runtime_error(ss.str()));
0082           return;
0083         }
0084       }
0085     } else {
0086       std::stringstream ss;
0087       ss << "[SummaryPlotXmlParser::" << __func__ << "]"
0088          << " Did not find \"" << rootTag_ << "\" tag! "
0089          << " Tag name is " << rootTag_;
0090       throw(std::runtime_error(ss.str()));
0091       return;
0092     }
0093   }
0094 }
0095 
0096 // -----------------------------------------------------------------------------
0097 //
0098 std::ostream& operator<<(std::ostream& os, const SummaryPlotXmlParser& parser) {
0099   std::stringstream ss;
0100   parser.print(ss);
0101   os << ss.str();
0102   return os;
0103 }
0104 
0105 // -----------------------------------------------------------------------------
0106 //
0107 void SummaryPlotXmlParser::print(std::stringstream& ss) const {
0108   ss << "[SummaryPlotXmlParser::SummaryPlot::" << __func__ << "]"
0109      << " Dumping contents of parsed XML file: " << std::endl;
0110   using namespace sistrip;
0111   typedef std::vector<SummaryPlot> Plots;
0112   std::map<RunType, Plots>::const_iterator irun = plots_.begin();
0113   for (; irun != plots_.end(); irun++) {
0114     ss << " RunType=\"" << SiStripEnumsAndStrings::runType(irun->first) << "\"" << std::endl;
0115     if (irun->second.empty()) {
0116       ss << " No summary plots for this RunType!";
0117     } else {
0118       Plots::const_iterator iplot = irun->second.begin();
0119       for (; iplot != irun->second.end(); iplot++) {
0120         ss << *iplot << std::endl;
0121       }
0122     }
0123   }
0124 }