CMS 3D CMS Logo

SummaryPlotXmlParser.cc
Go to the documentation of this file.
4 #include <stdexcept>
5 
6 using namespace sistrip;
7 
8 // -----------------------------------------------------------------------------
9 //
19 
20 // -----------------------------------------------------------------------------
21 //
23 
24 // -----------------------------------------------------------------------------
25 //
26 std::vector<SummaryPlot> SummaryPlotXmlParser::summaryPlots(const sistrip::RunType& run_type) {
27  if (plots_.empty()) {
28  edm::LogWarning(mlDqmClient_) << "[SummaryPlotXmlParser" << __func__ << "]"
29  << " You have not called the parseXML function,"
30  << " or your XML file is erronious" << std::endl;
31  }
32  if (plots_.find(run_type) != plots_.end()) {
33  return plots_[run_type];
34  } else {
35  return std::vector<SummaryPlot>();
36  }
37 }
38 
39 // -----------------------------------------------------------------------------
40 //
42  plots_.clear();
43 
44  boost::property_tree::ptree xmltree;
45  boost::property_tree::read_xml(filename, xmltree);
46 
47  auto runs = xmltree.find(rootTag_);
48  if (runs == xmltree.not_found()) {
49  }
50 
51  // Iterate through nodes
52  for (auto& xml : xmltree) {
53  if (xml.first == rootTag_) { // find main root
54  for (auto& runtype : xml.second) {
55  if (runtype.first == runTypeTag_) { // enter in the run type
56  sistrip::RunType run_type =
57  SiStripEnumsAndStrings::runType(runtype.second.get<std::string>("<xmlattr>." + runTypeAttr_));
58  for (auto& sumplot : runtype.second) {
59  if (sumplot.first == summaryPlotTag_) {
60  std::string mon = sumplot.second.get<std::string>("<xmlattr>." + monitorableAttr_);
61  std::string pres = sumplot.second.get<std::string>("<xmlattr>." + presentationAttr_);
62  std::string level = sumplot.second.get<std::string>("<xmlattr>." + levelAttr_);
63  std::string gran = sumplot.second.get<std::string>("<xmlattr>." + granularityAttr_);
64  SummaryPlot plot(mon, pres, gran, level);
65  plots_[run_type].push_back(plot);
66  }
67  }
68  if (plots_[run_type].empty()) {
69  std::stringstream ss;
70  ss << "[SummaryPlotXmlParser::" << __func__ << "]"
71  << " Unable to find any summary plot for " << runTypeTag_ << " nodes!"
72  << " Empty xml summary histo block?";
73  throw(std::runtime_error(ss.str()));
74  return;
75  }
76  } else {
77  std::stringstream ss;
78  ss << "[SummaryPlotXmlParser::" << __func__ << "]"
79  << " Unable to find any " << runTypeTag_ << " nodes!"
80  << " Empty xml run-type block?";
81  throw(std::runtime_error(ss.str()));
82  return;
83  }
84  }
85  } else {
86  std::stringstream ss;
87  ss << "[SummaryPlotXmlParser::" << __func__ << "]"
88  << " Did not find \"" << rootTag_ << "\" tag! "
89  << " Tag name is " << rootTag_;
90  throw(std::runtime_error(ss.str()));
91  return;
92  }
93  }
94 }
95 
96 // -----------------------------------------------------------------------------
97 //
98 std::ostream& operator<<(std::ostream& os, const SummaryPlotXmlParser& parser) {
99  std::stringstream ss;
100  parser.print(ss);
101  os << ss.str();
102  return os;
103 }
104 
105 // -----------------------------------------------------------------------------
106 //
107 void SummaryPlotXmlParser::print(std::stringstream& ss) const {
108  ss << "[SummaryPlotXmlParser::SummaryPlot::" << __func__ << "]"
109  << " Dumping contents of parsed XML file: " << std::endl;
110  using namespace sistrip;
111  typedef std::vector<SummaryPlot> Plots;
112  std::map<RunType, Plots>::const_iterator irun = plots_.begin();
113  for (; irun != plots_.end(); irun++) {
114  ss << " RunType=\"" << SiStripEnumsAndStrings::runType(irun->first) << "\"" << std::endl;
115  if (irun->second.empty()) {
116  ss << " No summary plots for this RunType!";
117  } else {
118  Plots::const_iterator iplot = irun->second.begin();
119  for (; iplot != irun->second.end(); iplot++) {
120  ss << *iplot << std::endl;
121  }
122  }
123  }
124 }
static const std::string monitorableAttr_
static const std::string rootTag_
static const std::string runTypeTag_
static const std::string presentationAttr_
static const std::string runTypeAttr_
void parseXML(const std::string &xml_file)
static const std::string granularityAttr_
static const char mlDqmClient_[]
std::ostream & operator<<(std::ostream &os, const FEDBufferFormat &value)
sistrip classes
static std::string runType(const sistrip::RunType &)
Parses the "summary plot" xml configuration file.
static const std::string viewAttr_
Class holding info that defines a summary plot.
Definition: SummaryPlot.h:19
static const std::string summaryPlotTag_
std::vector< SummaryPlot > summaryPlots(const sistrip::RunType &)
static const std::string levelAttr_
Log< level::Warning, false > LogWarning
void print(std::stringstream &) const