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
 
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 345 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.

347 {
348  if (mode == kHeader) {
349  DOMText *text = xmlHeader->createTextNode(data_);
350  xmlNodes.back()->appendChild(text);
351  return;
352  }
353 
354  if (XMLSimpleStr::isAllSpaces(data_, length))
355  return;
356 
357  unsigned int offset = 0;
358  while(offset < length && XMLSimpleStr::isSpace(data_[offset]))
359  offset++;
360 
361  if( mode == kEvent ) {
362  DOMText *text = xmlEvent->createTextNode(data_+offset);
363  xmlEventNodes.back()->appendChild(text);
364  return;
365  }
366 
367  if (mode == kNone)
368  throw cms::Exception("InvalidFormat")
369  << "LHE file has invalid format" << std::endl;
370 
371  XMLSimpleStr data(data_ + offset);
372  buffer.append(data);
373 }
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 375 of file LHEReader.cc.

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

377 {
378  if (mode == kHeader) {
379  DOMComment *comment = xmlHeader->createComment(data_);
380  xmlNodes.back()->appendChild(comment);
381  return;
382  }
383 
384  XMLSimpleStr data(data_);
385 
386  LHERunInfo::Header header;
387  fillHeader(header, data);
388  headers.push_back(header);
389 }
static void fillHeader(LHERunInfo::Header &header, const char *data, int len=-1)
Definition: LHEReader.cc:158
void comment(const XMLCh *const data, const unsigned int length) override
Definition: LHEReader.cc:375
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 241 of file LHEReader.cc.

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

244 {
245  std::string name((const char*)XMLSimpleStr(qname));
246 
247  if (mode) {
248 
249  if (mode == kHeader && xmlNodes.size() > 1) {
250  xmlNodes.resize(xmlNodes.size() - 1);
251  return;
252  } else if (mode == kHeader) {
253  std::auto_ptr<DOMWriter> writer(
254  static_cast<DOMImplementationLS*>(
255  impl)->createDOMWriter());
256  writer->setEncoding(XMLUniStr("UTF-8"));
257 
258  for(DOMNode *node = xmlNodes[0]->getFirstChild();
259  node; node = node->getNextSibling()) {
260  XMLSimpleStr buffer(writer->writeToString(*node));
261 
263  const char *p, *q;
264  DOMElement *elem;
265 
266  switch(node->getNodeType()) {
267  case DOMNode::ELEMENT_NODE:
268  elem = static_cast<DOMElement*>(node);
269  type = (const char*)XMLSimpleStr(
270  elem->getTagName());
271  p = std::strchr((const char*)buffer,
272  '>') + 1;
273  q = std::strrchr(p, '<');
274  break;
275  case DOMNode::COMMENT_NODE:
276  type = "";
277  p = buffer + 4;
278  q = buffer + strlen(buffer) - 3;
279  break;
280  default:
281  type = "<>";
282  p = buffer +
283  std::strspn(buffer, " \t\r\n");
284  if (!*p)
285  continue;
286  q = p + strlen(p);
287  }
288  LHERunInfo::Header header(type);
289  fillHeader(header, p, q - p);
290  headers.push_back(header);
291  }
292 
293  xmlHeader->release();
294  xmlHeader = 0;
295  }
296 
297  if( name == "rwgt" && mode == kEvent ) return;
298  if( name == "wgt" && mode == kEvent ) return;
299 
300  if (name == "event" &&
301  mode == kEvent &&
302  xmlEventNodes.size() >= 1) { // handling of weights in LHE file
303  for(DOMNode *node = xmlEventNodes[0]->getFirstChild();
304  node; node = node->getNextSibling()) {
305  switch( node->getNodeType() ) {
306  case DOMNode::ELEMENT_NODE: // rwgt
307  for(DOMNode *rwgt = xmlEventNodes[1]->getFirstChild();
308  rwgt; rwgt = rwgt->getNextSibling()) {
309  DOMNode* attr = rwgt->getAttributes()->item(0);
310  XMLSimpleStr atname(attr->getNodeValue());
311  XMLSimpleStr weight(rwgt->getFirstChild()->getNodeValue());
312  switch( rwgt->getNodeType() ) {
313  case DOMNode::ELEMENT_NODE:
314  weightsinevent.push_back(std::make_pair((const char*)atname,
315  (const char*)weight));
316  break;
317  default:
318  break;
319  }
320  }
321  break;
322  case DOMNode::TEXT_NODE: // event information
323  {
324  XMLSimpleStr data(node->getNodeValue());
325  buffer.append(data);
326  }
327  break;
328  default:
329  break;
330  }
331  }
332  }
333 
334  if (gotObject != kNone)
335  throw cms::Exception("InvalidState")
336  << "Unexpected pileup in"
337  " LHEReader::XMLHandler::endElement"
338  << std::endl;
339 
340  gotObject = mode;
341  mode = kNone;
342  }
343 }
type
Definition: HCALResponse.h:21
static void fillHeader(LHERunInfo::Header &header, const char *data, int len=-1)
Definition: LHEReader.cc:158
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 175 of file LHEReader.cc.

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

179 {
180  std::string name((const char*)XMLSimpleStr(qname));
181 
182  if (!headerOk) {
183  if (name != "LesHouchesEvents")
184  throw cms::Exception("InvalidFormat")
185  << "LHE file has invalid header" << std::endl;
186  headerOk = true;
187  return;
188  }
189 
190  if (mode == kHeader) {
191  DOMElement *elem = xmlHeader->createElement(qname);
193  xmlNodes.back()->appendChild(elem);
194  xmlNodes.push_back(elem);
195  return;
196  } else if ( mode == kEvent ) {
197  DOMElement *elem = xmlEvent->createElement(qname);
199 
200  if( name == "rwgt" ) {
201  xmlEventNodes[0]->appendChild(elem);
202  } else if (name == "wgt") {
203  xmlEventNodes[1]->appendChild(elem);
204  }
205  xmlEventNodes.push_back(elem);
206  return;
207  } else if (mode != kNone) {
208  throw cms::Exception("InvalidFormat")
209  << "LHE file has invalid format" << std::endl;
210  }
211 
212  if (name == "header") {
213  if (!impl)
214  impl = DOMImplementationRegistry::getDOMImplementation(
215  XMLUniStr("Core"));
216  xmlHeader = impl->createDocument(0, qname, 0);
217  xmlNodes.resize(1);
218  xmlNodes[0] = xmlHeader->getDocumentElement();
219  mode = kHeader;
220  } if (name == "init") {
221  mode = kInit;
222  } else if (name == "event") {
223  if (!impl)
224  impl = DOMImplementationRegistry::getDOMImplementation(
225  XMLUniStr("Core"));
226  if(xmlEvent) xmlEvent->release();
227  xmlEvent = impl->createDocument(0, qname, 0);
228  weightsinevent.resize(0);
229  xmlEventNodes.resize(1);
230  xmlEventNodes[0] = xmlEvent->getDocumentElement();
231  mode = kEvent;
232  }
233 
234  if (mode == kNone)
235  throw cms::Exception("InvalidFormat")
236  << "LHE file has invalid format" << std::endl;
237 
238  buffer.clear();
239 }
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:148
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().

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().