CMS 3D CMS Logo

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