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::map< int, float > scalesmap
 
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 380 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.

382 {
383  if (mode == kHeader) {
384  DOMText *text = xmlHeader->createTextNode(data_);
385  xmlNodes.back()->appendChild(text);
386  return;
387  }
388 
389  if (XMLSimpleStr::isAllSpaces(data_, length))
390  return;
391 
392  unsigned int offset = 0;
393  while(offset < length && XMLSimpleStr::isSpace(data_[offset]))
394  offset++;
395 
396  if( mode == kEvent ) {
397  DOMText *text = xmlEvent->createTextNode(data_+offset);
398  xmlEventNodes.back()->appendChild(text);
399  return;
400  }
401 
402  if (mode == kNone)
403  throw cms::Exception("InvalidFormat")
404  << "LHE file has invalid format" << std::endl;
405 
406  XMLSimpleStr data(data_ + offset);
407  buffer.append(data);
408 }
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
unsigned int offset(bool)
std::vector< DOMElement * > xmlNodes
Definition: LHEReader.cc:142
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void lhef::LHEReader::XMLHandler::comment ( const XMLCh *const  data,
const unsigned int  length 
)
overrideprotected

Definition at line 410 of file LHEReader.cc.

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

412 {
413  if (mode == kHeader) {
414  DOMComment *comment = xmlHeader->createComment(data_);
415  xmlNodes.back()->appendChild(comment);
416  return;
417  }
418 
419  XMLSimpleStr data(data_);
420 
421  LHERunInfo::Header header;
422  fillHeader(header, data);
423  headers.push_back(header);
424 }
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:410
std::vector< LHERunInfo::Header > headers
Definition: LHEReader.cc:144
std::vector< DOMElement * > xmlNodes
Definition: LHEReader.cc:142
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void lhef::LHEReader::XMLHandler::endElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname 
)
overrideprotected

Definition at line 276 of file LHEReader.cc.

References asciidump::attr, 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.

279 {
280  std::string name((const char*)XMLSimpleStr(qname));
281 
282  if (mode) {
283 
284  if (mode == kHeader && xmlNodes.size() > 1) {
285  xmlNodes.resize(xmlNodes.size() - 1);
286  return;
287  } else if (mode == kHeader) {
288  std::auto_ptr<DOMWriter> writer(
289  static_cast<DOMImplementationLS*>(
290  impl)->createDOMWriter());
291  writer->setEncoding(XMLUniStr("UTF-8"));
292 
293  for(DOMNode *node = xmlNodes[0]->getFirstChild();
294  node; node = node->getNextSibling()) {
295  XMLSimpleStr buffer(writer->writeToString(*node));
296 
298  const char *p, *q;
299  DOMElement *elem;
300 
301  switch(node->getNodeType()) {
302  case DOMNode::ELEMENT_NODE:
303  elem = static_cast<DOMElement*>(node);
304  type = (const char*)XMLSimpleStr(
305  elem->getTagName());
306  p = std::strchr((const char*)buffer,
307  '>') + 1;
308  q = std::strrchr(p, '<');
309  break;
310  case DOMNode::COMMENT_NODE:
311  type = "";
312  p = buffer + 4;
313  q = buffer + strlen(buffer) - 3;
314  break;
315  default:
316  type = "<>";
317  p = buffer +
318  std::strspn(buffer, " \t\r\n");
319  if (!*p)
320  continue;
321  q = p + strlen(p);
322  }
323  LHERunInfo::Header header(type);
324  fillHeader(header, p, q - p);
325  headers.push_back(header);
326  }
327 
328  xmlHeader->release();
329  xmlHeader = 0;
330  }
331  else if (name == "event" &&
332  mode == kEvent &&
333  xmlEventNodes.size() >= 1) { // handling of weights in LHE file
334  for(DOMNode *node = xmlEventNodes[0]->getFirstChild();
335  node; node = node->getNextSibling()) {
336  switch( node->getNodeType() ) {
337  case DOMNode::ELEMENT_NODE: // rwgt
338  for(DOMNode *rwgt = xmlEventNodes[1]->getFirstChild();
339  rwgt; rwgt = rwgt->getNextSibling()) {
340  DOMNode* attr = rwgt->getAttributes()->item(0);
341  XMLSimpleStr atname(attr->getNodeValue());
342  XMLSimpleStr weight(rwgt->getFirstChild()->getNodeValue());
343  switch( rwgt->getNodeType() ) {
344  case DOMNode::ELEMENT_NODE:
345  weightsinevent.push_back(std::make_pair((const char*)atname,
346  (const char*)weight));
347  break;
348  default:
349  break;
350  }
351  }
352  break;
353  case DOMNode::TEXT_NODE: // event information
354  {
355  XMLSimpleStr data(node->getNodeValue());
356  buffer.append(data);
357  }
358  break;
359  default:
360  break;
361  }
362  }
363  }
364  else if (mode == kEvent) {
365  //skip unknown tags
366  return;
367  }
368 
369  if (gotObject != kNone)
370  throw cms::Exception("InvalidState")
371  << "Unexpected pileup in"
372  " LHEReader::XMLHandler::endElement"
373  << std::endl;
374 
375  gotObject = mode;
376  mode = kNone;
377  }
378 }
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
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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, scalesmap, 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  sscanf(scalename,"pt_clust_%d",&ipart);
214 
215  float scaleval;
216  const char *scalevalstr = XMLSimpleStr(attributes.getValue(iscale));
217  sscanf(scalevalstr,"%e",&scaleval);
218 
219  scalesmap[ipart] = scaleval;
220  }
221  }
222  xmlEventNodes.push_back(elem);
223  return;
224  } else if (mode == kInit) {
225  //skip unknown tags in init block as well
226  return;
227  } else if (mode != kNone) {
228  throw cms::Exception("InvalidFormat")
229  << "LHE file has invalid format" << std::endl;
230  }
231 
232  if (name == "header") {
233  if (!impl)
234  impl = DOMImplementationRegistry::getDOMImplementation(
235  XMLUniStr("Core"));
236  xmlHeader = impl->createDocument(0, qname, 0);
237  xmlNodes.resize(1);
238  xmlNodes[0] = xmlHeader->getDocumentElement();
239  mode = kHeader;
240  } if (name == "init") {
241  mode = kInit;
242  } else if (name == "event") {
243  if (!impl)
244  impl = DOMImplementationRegistry::getDOMImplementation(
245  XMLUniStr("Core"));
246  if(xmlEvent) xmlEvent->release();
247  xmlEvent = impl->createDocument(0, qname, 0);
248  weightsinevent.resize(0);
249  scalesmap.clear();
250 
251  npLO = -99;
252  npNLO = -99;
253  const XMLCh *npLOval = attributes.getValue(XMLString::transcode("npLO"));
254  if (npLOval) {
255  const char *npLOs = XMLSimpleStr(npLOval);
256  sscanf(npLOs,"%d",&npLO);
257  }
258  const XMLCh *npNLOval = attributes.getValue(XMLString::transcode("npNLO"));
259  if (npNLOval) {
260  const char *npNLOs = XMLSimpleStr(npNLOval);
261  sscanf(npNLOs,"%d",&npNLO);
262  }
263 
264  xmlEventNodes.resize(1);
265  xmlEventNodes[0] = xmlEvent->getDocumentElement();
266  mode = kEvent;
267  }
268 
269  if (mode == kNone)
270  throw cms::Exception("InvalidFormat")
271  << "LHE file has invalid format" << std::endl;
272 
273  buffer.clear();
274 }
std::map< int, float > scalesmap
Definition: LHEReader.cc:148
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
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::map<int,float> lhef::LHEReader::XMLHandler::scalesmap
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().