CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Friends
lhef::LHEReader::XMLHandler Class Reference
Inheritance diagram for lhef::LHEReader::XMLHandler:
lhef::XMLDocument::Handler

Public Types

enum  Object {
  kNone = 0, kHeader, kInit, kComment,
  kEvent
}
 
typedef std::vector< std::pair
< std::string, std::string > > 
wgt_info
 

Public Member Functions

void reset ()
 
const wgt_infoweightInfo () const
 
 XMLHandler ()
 
 ~XMLHandler ()
 

Protected Member Functions

void characters (const XMLCh *const data, const unsigned int length) override
 
void comment (const XMLCh *const data, const unsigned int length) override
 
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname) override
 
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attributes) override
 

Private Attributes

std::string buffer
 
Object gotObject
 
bool headerOk
 
std::vector< LHERunInfo::Headerheaders
 
DOMImplementation * impl
 
Object mode
 
int npLO
 
int npNLO
 
std::vector< float > scales
 
wgt_info weightsinevent
 
DOMDocument * xmlEvent
 
std::vector< DOMElement * > xmlEventNodes
 
DOMDocument * xmlHeader
 
std::vector< DOMElement * > xmlNodes
 

Friends

class LHEReader
 

Detailed Description

Definition at line 98 of file LHEReader.cc.

Member Typedef Documentation

typedef std::vector<std::pair<std::string,std::string> > lhef::LHEReader::XMLHandler::wgt_info

Definition at line 100 of file LHEReader.cc.

Member Enumeration Documentation

Enumerator
kNone 
kHeader 
kInit 
kComment 
kEvent 

Definition at line 108 of file LHEReader.cc.

Constructor & Destructor Documentation

lhef::LHEReader::XMLHandler::XMLHandler ( )
inline
lhef::LHEReader::XMLHandler::~XMLHandler ( )
inline

Definition at line 104 of file LHEReader.cc.

References xmlEvent, and xmlHeader.

105  { if (xmlHeader) xmlHeader->release();
106  if (xmlEvent) xmlEvent->release(); }

Member Function Documentation

void lhef::LHEReader::XMLHandler::characters ( const XMLCh *const  data,
const unsigned int  length 
)
overrideprotected

Definition at line 386 of file LHEReader.cc.

References AlCaHLTBitMon_QueryRunRegistry::data, edm::hlt::Exception, lhef::XMLSimpleStr::isAllSpaces(), lhef::XMLSimpleStr::isSpace(), WDecay::kNone, alignBH_cfg::mode, unpackBuffers-CaloStage2::offset, and runonSM::text.

388 {
389  if (mode == kHeader) {
390  DOMText *text = xmlHeader->createTextNode(data_);
391  xmlNodes.back()->appendChild(text);
392  return;
393  }
394 
395  if (XMLSimpleStr::isAllSpaces(data_, length))
396  return;
397 
398  unsigned int offset = 0;
399  while(offset < length && XMLSimpleStr::isSpace(data_[offset]))
400  offset++;
401 
402  if( mode == kEvent ) {
403  DOMText *text = xmlEvent->createTextNode(data_+offset);
404  xmlEventNodes.back()->appendChild(text);
405  return;
406  }
407 
408  if (mode == kNone)
409  throw cms::Exception("InvalidFormat")
410  << "LHE file has invalid format" << std::endl;
411 
412  XMLSimpleStr data(data_ + offset);
413  buffer.append(data);
414 }
static bool isSpace(XMLCh ch)
Definition: XMLUtils.h:86
std::vector< DOMElement * > xmlEventNodes
Definition: LHEReader.cc:142
static bool isAllSpaces(const XMLCh *str, unsigned int length)
Definition: XMLUtils.h:82
tuple text
Definition: runonSM.py:42
std::vector< DOMElement * > xmlNodes
Definition: LHEReader.cc:142
void lhef::LHEReader::XMLHandler::comment ( const XMLCh *const  data,
const unsigned int  length 
)
overrideprotected

Definition at line 416 of file LHEReader.cc.

References comment, AlCaHLTBitMon_QueryRunRegistry::data, lhef::fillHeader(), getRunAppsInfo::headers, and alignBH_cfg::mode.

418 {
419  if (mode == kHeader) {
420  DOMComment *comment = xmlHeader->createComment(data_);
421  xmlNodes.back()->appendChild(comment);
422  return;
423  }
424 
425  XMLSimpleStr data(data_);
426 
427  LHERunInfo::Header header;
428  fillHeader(header, data);
429  headers.push_back(header);
430 }
static void fillHeader(LHERunInfo::Header &header, const char *data, int len=-1)
Definition: LHEReader.cc:161
void comment(const XMLCh *const data, const unsigned int length) override
Definition: LHEReader.cc:416
std::vector< LHERunInfo::Header > headers
Definition: LHEReader.cc:144
std::vector< DOMElement * > xmlNodes
Definition: LHEReader.cc:142
void lhef::LHEReader::XMLHandler::endElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname 
)
overrideprotected

Definition at line 282 of file LHEReader.cc.

References asciidump::attr, AlCaHLTBitMon_QueryRunRegistry::data, HTMLExport::elem(), edm::hlt::Exception, lhef::fillHeader(), getRunAppsInfo::headers, WDecay::kNone, alignBH_cfg::mode, mergeVDriftHistosByStation::name, python.Node::node, AlCaHLTBitMon_ParallelJobs::p, lumiQueryAPI::q, AlCaHLTBitMon_QueryRunRegistry::string, and histoStyle::weight.

285 {
286  std::string name((const char*)XMLSimpleStr(qname));
287 
288  if (mode) {
289 
290  if (mode == kHeader && xmlNodes.size() > 1) {
291  xmlNodes.resize(xmlNodes.size() - 1);
292  return;
293  } else if (mode == kHeader) {
294  std::auto_ptr<DOMWriter> writer(
295  static_cast<DOMImplementationLS*>(
296  impl)->createDOMWriter());
297  writer->setEncoding(XMLUniStr("UTF-8"));
298 
299  for(DOMNode *node = xmlNodes[0]->getFirstChild();
300  node; node = node->getNextSibling()) {
301  XMLSimpleStr buffer(writer->writeToString(*node));
302 
304  const char *p, *q;
305  DOMElement *elem;
306 
307  switch(node->getNodeType()) {
308  case DOMNode::ELEMENT_NODE:
309  elem = static_cast<DOMElement*>(node);
310  type = (const char*)XMLSimpleStr(
311  elem->getTagName());
312  p = std::strchr((const char*)buffer,
313  '>') + 1;
314  q = std::strrchr(p, '<');
315  break;
316  case DOMNode::COMMENT_NODE:
317  type = "";
318  p = buffer + 4;
319  q = buffer + strlen(buffer) - 3;
320  break;
321  default:
322  type = "<>";
323  p = buffer +
324  std::strspn(buffer, " \t\r\n");
325  if (!*p)
326  continue;
327  q = p + strlen(p);
328  }
329  LHERunInfo::Header header(type);
330  fillHeader(header, p, q - p);
331  headers.push_back(header);
332  }
333 
334  xmlHeader->release();
335  xmlHeader = 0;
336  }
337  else if (name == "event" &&
338  mode == kEvent &&
339  xmlEventNodes.size() >= 1) { // handling of weights in LHE file
340  for(DOMNode *node = xmlEventNodes[0]->getFirstChild();
341  node; node = node->getNextSibling()) {
342  switch( node->getNodeType() ) {
343  case DOMNode::ELEMENT_NODE: // rwgt
344  for(DOMNode *rwgt = xmlEventNodes[1]->getFirstChild();
345  rwgt; rwgt = rwgt->getNextSibling()) {
346  DOMNode* attr = rwgt->getAttributes()->item(0);
347  XMLSimpleStr atname(attr->getNodeValue());
348  XMLSimpleStr weight(rwgt->getFirstChild()->getNodeValue());
349  switch( rwgt->getNodeType() ) {
350  case DOMNode::ELEMENT_NODE:
351  weightsinevent.push_back(std::make_pair((const char*)atname,
352  (const char*)weight));
353  break;
354  default:
355  break;
356  }
357  }
358  break;
359  case DOMNode::TEXT_NODE: // event information
360  {
361  XMLSimpleStr data(node->getNodeValue());
362  buffer.append(data);
363  }
364  break;
365  default:
366  break;
367  }
368  }
369  }
370  else if (mode == kEvent) {
371  //skip unknown tags
372  return;
373  }
374 
375  if (gotObject != kNone)
376  throw cms::Exception("InvalidState")
377  << "Unexpected pileup in"
378  " LHEReader::XMLHandler::endElement"
379  << std::endl;
380 
381  gotObject = mode;
382  mode = kNone;
383  }
384 }
type
Definition: HCALResponse.h:21
static void fillHeader(LHERunInfo::Header &header, const char *data, int len=-1)
Definition: LHEReader.cc:161
tuple node
Definition: Node.py:50
std::vector< LHERunInfo::Header > headers
Definition: LHEReader.cc:144
std::vector< DOMElement * > xmlEventNodes
Definition: LHEReader.cc:142
std::vector< DOMElement * > xmlNodes
Definition: LHEReader.cc:142
DOMImplementation * impl
Definition: LHEReader.cc:136
tuple attr
Definition: asciidump.py:432
def qname
Definition: asciidump.py:315
int weight
Definition: histoStyle.py:50
void lhef::LHEReader::XMLHandler::reset ( void  )
inline

Definition at line 116 of file LHEReader.cc.

References headerOk, and weightsinevent.

116 { headerOk = false; weightsinevent.clear();}
void lhef::LHEReader::XMLHandler::startElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname,
const Attributes &  attributes 
)
overrideprotected

Definition at line 178 of file LHEReader.cc.

References lhef::attributesToDom(), buffer, HTMLExport::elem(), edm::hlt::Exception, headerOk, impl, kEvent, kHeader, kInit, kNone, mode, mergeVDriftHistosByStation::name, npLO, npNLO, scales, AlCaHLTBitMon_QueryRunRegistry::string, weightsinevent, xmlEvent, xmlEventNodes, xmlHeader, and xmlNodes.

182 {
183  std::string name((const char*)XMLSimpleStr(qname));
184 
185  if (!headerOk) {
186  if (name != "LesHouchesEvents")
187  throw cms::Exception("InvalidFormat")
188  << "LHE file has invalid header" << std::endl;
189  headerOk = true;
190  return;
191  }
192 
193  if (mode == kHeader) {
194  DOMElement *elem = xmlHeader->createElement(qname);
196  xmlNodes.back()->appendChild(elem);
197  xmlNodes.push_back(elem);
198  return;
199  } else if ( mode == kEvent ) {
200  DOMElement *elem = xmlEvent->createElement(qname);
202 
203  //TODO this is a hack (even more than the rest of this class)
204  if( name == "rwgt" ) {
205  xmlEventNodes[0]->appendChild(elem);
206  } else if (name == "wgt") {
207  xmlEventNodes[1]->appendChild(elem);
208  }
209  else if (name == "scales") {
210  for (XMLSize_t iscale=0; iscale<attributes.getLength(); ++iscale) {
211  int ipart = 0;
212  const char *scalename = XMLSimpleStr(attributes.getQName(iscale));
213  int nmatch = sscanf(scalename,"pt_clust_%d",&ipart);
214 
215  if (nmatch!=1) {
216  edm::LogError("Generator|LHEInterface")
217  << "invalid attribute in <scales> tag"
218  << std::endl;
219  }
220 
221  float scaleval;
222  const char *scalevalstr = XMLSimpleStr(attributes.getValue(iscale));
223  sscanf(scalevalstr,"%e",&scaleval);
224 
225  scales.push_back(scaleval);
226  }
227  }
228  xmlEventNodes.push_back(elem);
229  return;
230  } else if (mode == kInit) {
231  //skip unknown tags in init block as well
232  return;
233  } else if (mode != kNone) {
234  throw cms::Exception("InvalidFormat")
235  << "LHE file has invalid format" << std::endl;
236  }
237 
238  if (name == "header") {
239  if (!impl)
240  impl = DOMImplementationRegistry::getDOMImplementation(
241  XMLUniStr("Core"));
242  xmlHeader = impl->createDocument(0, qname, 0);
243  xmlNodes.resize(1);
244  xmlNodes[0] = xmlHeader->getDocumentElement();
245  mode = kHeader;
246  } if (name == "init") {
247  mode = kInit;
248  } else if (name == "event") {
249  if (!impl)
250  impl = DOMImplementationRegistry::getDOMImplementation(
251  XMLUniStr("Core"));
252  if(xmlEvent) xmlEvent->release();
253  xmlEvent = impl->createDocument(0, qname, 0);
254  weightsinevent.resize(0);
255  scales.clear();
256 
257  npLO = -99;
258  npNLO = -99;
259  const XMLCh *npLOval = attributes.getValue(XMLString::transcode("npLO"));
260  if (npLOval) {
261  const char *npLOs = XMLSimpleStr(npLOval);
262  sscanf(npLOs,"%d",&npLO);
263  }
264  const XMLCh *npNLOval = attributes.getValue(XMLString::transcode("npNLO"));
265  if (npNLOval) {
266  const char *npNLOs = XMLSimpleStr(npNLOval);
267  sscanf(npNLOs,"%d",&npNLO);
268  }
269 
270  xmlEventNodes.resize(1);
271  xmlEventNodes[0] = xmlEvent->getDocumentElement();
272  mode = kEvent;
273  }
274 
275  if (mode == kNone)
276  throw cms::Exception("InvalidFormat")
277  << "LHE file has invalid format" << std::endl;
278 
279  buffer.clear();
280 }
std::vector< DOMElement * > xmlEventNodes
Definition: LHEReader.cc:142
list attributes
Definition: asciidump.py:415
std::vector< DOMElement * > xmlNodes
Definition: LHEReader.cc:142
DOMImplementation * impl
Definition: LHEReader.cc:136
def qname
Definition: asciidump.py:315
std::vector< float > scales
Definition: LHEReader.cc:148
static void attributesToDom(DOMElement *dom, const Attributes &attributes)
Definition: LHEReader.cc:151
const wgt_info& lhef::LHEReader::XMLHandler::weightInfo ( ) const
inline

Definition at line 118 of file LHEReader.cc.

References weightsinevent.

118 {return weightsinevent;}

Friends And Related Function Documentation

friend class LHEReader
friend

Definition at line 134 of file LHEReader.cc.

Member Data Documentation

std::string lhef::LHEReader::XMLHandler::buffer
private

Definition at line 137 of file LHEReader.cc.

Referenced by startElement().

Object lhef::LHEReader::XMLHandler::gotObject
private

Definition at line 138 of file LHEReader.cc.

bool lhef::LHEReader::XMLHandler::headerOk
private

Definition at line 143 of file LHEReader.cc.

Referenced by reset(), and startElement().

std::vector<LHERunInfo::Header> lhef::LHEReader::XMLHandler::headers
private
DOMImplementation* lhef::LHEReader::XMLHandler::impl
private

Definition at line 136 of file LHEReader.cc.

Referenced by startElement().

Object lhef::LHEReader::XMLHandler::mode
private

Definition at line 139 of file LHEReader.cc.

Referenced by startElement().

int lhef::LHEReader::XMLHandler::npLO
private

Definition at line 146 of file LHEReader.cc.

Referenced by startElement().

int lhef::LHEReader::XMLHandler::npNLO
private

Definition at line 147 of file LHEReader.cc.

Referenced by startElement().

std::vector<float> lhef::LHEReader::XMLHandler::scales
private

Definition at line 148 of file LHEReader.cc.

Referenced by startElement().

wgt_info lhef::LHEReader::XMLHandler::weightsinevent
private

Definition at line 145 of file LHEReader.cc.

Referenced by reset(), startElement(), and weightInfo().

DOMDocument* lhef::LHEReader::XMLHandler::xmlEvent
private

Definition at line 141 of file LHEReader.cc.

Referenced by startElement(), and ~XMLHandler().

std::vector<DOMElement*> lhef::LHEReader::XMLHandler::xmlEventNodes
private

Definition at line 142 of file LHEReader.cc.

Referenced by startElement().

DOMDocument* lhef::LHEReader::XMLHandler::xmlHeader
private

Definition at line 140 of file LHEReader.cc.

Referenced by startElement(), and ~XMLHandler().

std::vector<DOMElement*> lhef::LHEReader::XMLHandler::xmlNodes
private

Definition at line 142 of file LHEReader.cc.

Referenced by startElement().