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)
 
void comment (const XMLCh *const data, const unsigned int length)
 
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
 
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attributes)
 

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 99 of file LHEReader.cc.

Member Typedef Documentation

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

Definition at line 101 of file LHEReader.cc.

Member Enumeration Documentation

Enumerator
kNone 
kHeader 
kInit 
kComment 
kEvent 

Definition at line 109 of file LHEReader.cc.

Constructor & Destructor Documentation

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

Definition at line 105 of file LHEReader.cc.

References xmlEvent, and xmlHeader.

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

Member Function Documentation

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

Definition at line 387 of file LHEReader.cc.

References data, edm::hlt::Exception, lhef::XMLSimpleStr::isAllSpaces(), lhef::XMLSimpleStr::isSpace(), WDecay::kNone, alignBH_cfg::mode, evf::evtn::offset(), and runonSM::text.

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

Definition at line 417 of file LHEReader.cc.

References comment, data, lhef::fillHeader(), errorMatrix2Lands::header, and alignBH_cfg::mode.

419 {
420  if (mode == kHeader) {
421  DOMComment *comment = xmlHeader->createComment(data_);
422  xmlNodes.back()->appendChild(comment);
423  return;
424  }
425 
426  XMLSimpleStr data(data_);
427 
428  LHERunInfo::Header header;
429  fillHeader(header, data);
430  headers.push_back(header);
431 }
static void fillHeader(LHERunInfo::Header &header, const char *data, int len=-1)
Definition: LHEReader.cc:162
std::vector< LHERunInfo::Header > headers
Definition: LHEReader.cc:145
std::vector< DOMElement * > xmlNodes
Definition: LHEReader.cc:143
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void comment(const XMLCh *const data, const unsigned int length)
Definition: LHEReader.cc:417
void lhef::LHEReader::XMLHandler::endElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname 
)
protected

Definition at line 283 of file LHEReader.cc.

References asciidump::attr, data, HTMLExport::elem(), edm::hlt::Exception, lhef::fillHeader(), errorMatrix2Lands::header, WDecay::kNone, alignBH_cfg::mode, mergeVDriftHistosByStation::name, python.Node::node, AlCaHLTBitMon_ParallelJobs::p, lumiQueryAPI::q, and CommonMethods::weight().

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

Definition at line 117 of file LHEReader.cc.

References headerOk, and weightsinevent.

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

Definition at line 179 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, weightsinevent, xmlEvent, xmlEventNodes, xmlHeader, and xmlNodes.

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

Definition at line 119 of file LHEReader.cc.

References weightsinevent.

119 {return weightsinevent;}

Friends And Related Function Documentation

friend class LHEReader
friend

Definition at line 135 of file LHEReader.cc.

Member Data Documentation

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

Definition at line 138 of file LHEReader.cc.

Referenced by startElement().

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

Definition at line 139 of file LHEReader.cc.

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

Definition at line 144 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 137 of file LHEReader.cc.

Referenced by startElement().

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

Definition at line 140 of file LHEReader.cc.

Referenced by startElement().

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

Definition at line 147 of file LHEReader.cc.

Referenced by startElement().

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

Definition at line 148 of file LHEReader.cc.

Referenced by startElement().

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

Definition at line 149 of file LHEReader.cc.

Referenced by startElement().

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

Definition at line 146 of file LHEReader.cc.

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

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

Definition at line 142 of file LHEReader.cc.

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

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

Definition at line 143 of file LHEReader.cc.

Referenced by startElement().

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

Definition at line 141 of file LHEReader.cc.

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

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

Definition at line 143 of file LHEReader.cc.

Referenced by startElement().