CMS 3D CMS Logo

SummaryPlotXmlParser.cc
Go to the documentation of this file.
4 #include <stdexcept>
5 
6 using namespace xercesc;
7 using namespace sistrip;
8 
9 // -----------------------------------------------------------------------------
10 //
20 
21 // -----------------------------------------------------------------------------
22 //
24  plots_.clear();
25  try {
27  } catch (const XMLException& f) {
28  throw(std::runtime_error("Standard pool exception : Fatal Error on pool::TrivialFileCatalog"));
29  }
30 }
31 
32 // -----------------------------------------------------------------------------
33 //
34 std::vector<SummaryPlot> SummaryPlotXmlParser::summaryPlots(const sistrip::RunType& run_type) {
35  if (plots_.empty()) {
36  edm::LogWarning(mlDqmClient_) << "[SummaryPlotXmlParser" << __func__ << "]"
37  << " You have not called the parseXML function,"
38  << " or your XML file is erronious" << std::endl;
39  }
40  if (plots_.find(run_type) != plots_.end()) {
41  return plots_[run_type];
42  } else {
43  return std::vector<SummaryPlot>();
44  }
45 }
46 
47 // -----------------------------------------------------------------------------
48 //
50  plots_.clear();
51 
52  try {
53  // Create parser and open XML document
54  getDocument(f);
55 
56  // Retrieve root element
57  DOMElement* root = this->doc()->getDocumentElement();
58  if (!root) {
59  std::stringstream ss;
60  ss << "[SummaryPlotXmlParser::" << __func__ << "]"
61  << " Unable to find any elements!"
62  << " Empty xml document?...";
63  throw(std::runtime_error(ss.str()));
64  }
65 
66  // Check on "root" tag
67  if (!XMLString::equals(root->getTagName(), XMLString::transcode(rootTag_.c_str()))) {
68  std::stringstream ss;
69  ss << "[SummaryPlotXmlParser::" << __func__ << "]"
70  << " Did not find \"" << rootTag_ << "\" tag! "
71  << " Tag name is " << XMLString::transcode(root->getNodeName());
72  edm::LogWarning(mlDqmClient_) << ss.str();
73  return;
74  }
75 
76  // Retrieve nodes in xml document
77  DOMNodeList* nodes = root->getChildNodes();
78  if (nodes->getLength() == 0) {
79  std::stringstream ss;
80  ss << "[SummaryPlotXmlParser::" << __func__ << "]"
81  << " Unable to find any children nodes!"
82  << " Empty xml document?...";
83  throw(std::runtime_error(ss.str()));
84  return;
85  }
86 
87  // LogTrace(mlDqmClient_)
88  // << "[SummaryPlotXmlParser::" << __func__ << "]"
89  // << " Found \"" << rootTag_ << "\" tag!";
90 
91  // LogTrace(mlDqmClient_)
92  // << "[SummaryPlotXmlParser::" << __func__ << "]"
93  // << " Found " << nodes->getLength()
94  // << " children nodes!";
95 
96  // Iterate through nodes
97  for (XMLSize_t inode = 0; inode < nodes->getLength(); ++inode) {
98  // Check on whether node is element
99  DOMNode* node = nodes->item(inode);
100  if (node->getNodeType() && node->getNodeType() == DOMNode::ELEMENT_NODE) {
101  DOMElement* element = dynamic_cast<DOMElement*>(node);
102  if (!element) {
103  continue;
104  }
105 
106  if (XMLString::equals(element->getTagName(), XMLString::transcode(runTypeTag_.c_str()))) {
107  const XMLCh* attr = element->getAttribute(XMLString::transcode(runTypeAttr_.c_str()));
108  sistrip::RunType run_type = SiStripEnumsAndStrings::runType(XMLString::transcode(attr));
109 
110  // std::stringstream ss;
111  // ss << "[SummaryPlotXmlParser::" << __func__ << "]"
112  // << " Found \"" << runTypeTag_ << "\" tag!" << std::endl
113  // << " with tag name \"" << XMLString::transcode(element->getNodeName()) << "\"" << std::endl
114  // << " and attr \"" << runTypeAttr_ << "\" with value \"" << XMLString::transcode(attr) << "\"";
115  // LogTrace(mlDqmClient_) << ss.str();
116 
117  // Retrieve nodes in xml document
118  DOMNodeList* children = node->getChildNodes();
119  if (nodes->getLength() == 0) {
120  std::stringstream ss;
121  ss << "[SummaryPlotXmlParser::" << __func__ << "]"
122  << " Unable to find any children nodes!"
123  << " Empty xml document?...";
124  throw(std::runtime_error(ss.str()));
125  return;
126  }
127 
128  // Iterate through nodes
129  for (XMLSize_t jnode = 0; jnode < children->getLength(); ++jnode) {
130  // Check on whether node is element
131  DOMNode* child = children->item(jnode);
132  if (child->getNodeType() && child->getNodeType() == DOMNode::ELEMENT_NODE) {
133  DOMElement* elem = dynamic_cast<DOMElement*>(child);
134  if (!elem) {
135  continue;
136  }
137 
138  if (XMLString::equals(elem->getTagName(), XMLString::transcode(summaryPlotTag_.c_str()))) {
139  const XMLCh* mon = elem->getAttribute(XMLString::transcode(monitorableAttr_.c_str()));
140  const XMLCh* pres = elem->getAttribute(XMLString::transcode(presentationAttr_.c_str()));
141  const XMLCh* level = elem->getAttribute(XMLString::transcode(levelAttr_.c_str()));
142  const XMLCh* gran = elem->getAttribute(XMLString::transcode(granularityAttr_.c_str()));
143 
144  SummaryPlot plot(XMLString::transcode(mon),
145  XMLString::transcode(pres),
146  XMLString::transcode(gran),
147  XMLString::transcode(level));
148  plots_[run_type].push_back(plot);
149 
150  // std::stringstream ss;
151  // ss << "[SummaryPlotXmlParser::" << __func__ << "]"
152  // << " Found \"" << summaryPlotTag_ << "\" tag!" << std::endl
153  // << " with tag name \"" << XMLString::transcode(elem->getNodeName()) << "\"" << std::endl
154  // << " and attr \"" << monitorableAttr_ << "\" with value \"" << XMLString::transcode(mon) << "\"" << std::endl
155  // << " and attr \"" << presentationAttr_ << "\" with value \"" << XMLString::transcode(pres) << "\"" << std::endl
156  // //<< " and attr \"" << viewAttr_ << "\" with value \"" << XMLString::transcode(view) << "\"" << std::endl
157  // << " and attr \"" << levelAttr_ << "\" with value \"" << XMLString::transcode(level) << "\"" << std::endl
158  // << " and attr \"" << granularityAttr_ << "\" with value \"" << XMLString::transcode(gran) << "\"";
159  // LogTrace(mlDqmClient_) << ss.str();
160 
161  // Update SummaryPlot object and push back into map
162  }
163  }
164  }
165  }
166  }
167  }
168 
169  } catch (XMLException& e) {
170  char* message = XMLString::transcode(e.getMessage());
171  std::ostringstream ss;
172  ss << "[SummaryPlotXmlParser::" << __func__ << "]"
173  << " Error parsing file: " << message << std::flush;
174  XMLString::release(&message);
175  }
176 }
177 
178 // -----------------------------------------------------------------------------
179 //
180 std::ostream& operator<<(std::ostream& os, const SummaryPlotXmlParser& parser) {
181  std::stringstream ss;
182  parser.print(ss);
183  os << ss.str();
184  return os;
185 }
186 
187 // -----------------------------------------------------------------------------
188 //
189 void SummaryPlotXmlParser::print(std::stringstream& ss) const {
190  ss << "[SummaryPlotXmlParser::SummaryPlot::" << __func__ << "]"
191  << " Dumping contents of parsed XML file: " << std::endl;
192  using namespace sistrip;
193  typedef std::vector<SummaryPlot> Plots;
194  std::map<RunType, Plots>::const_iterator irun = plots_.begin();
195  for (; irun != plots_.end(); irun++) {
196  ss << " RunType=\"" << SiStripEnumsAndStrings::runType(irun->first) << "\"" << std::endl;
197  if (irun->second.empty()) {
198  ss << " No summary plots for this RunType!";
199  } else {
200  Plots::const_iterator iplot = irun->second.begin();
201  for (; iplot != irun->second.end(); iplot++) {
202  ss << *iplot << std::endl;
203  }
204  }
205  }
206 }
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_[]
void xercesInitialize()
Definition: Xerces.cc:18
sistrip classes
static std::string runType(const sistrip::RunType &)
void print(std::stringstream &) const
Parses the "summary plot" xml configuration file.
static const std::string viewAttr_
std::ostream & operator<<(std::ostream &os, const SummaryPlotXmlParser &parser)
Class holding info that defines a summary plot.
Definition: SummaryPlot.h:19
double f[11][100]
static const std::string summaryPlotTag_
def elem(elemtype, innerHTML='', html_class='', kwargs)
Definition: HTMLExport.py:19
bool equals(const edm::RefToBase< Jet > &j1, const edm::RefToBase< Jet > &j2)
std::vector< SummaryPlot > summaryPlots(const sistrip::RunType &)
static const std::string levelAttr_