CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Attributes
lhef::LHEReader Class Reference

#include <LHEReader.h>

Classes

class  FileSource
 
class  Source
 
class  StringSource
 
class  XMLHandler
 

Public Member Functions

 LHEReader (const edm::ParameterSet &params)
 
 LHEReader (const std::vector< std::string > &fileNames, unsigned int skip=0)
 
 LHEReader (const std::string &inputs, unsigned int skip=0)
 
std::shared_ptr< LHEEventnext (bool *newFileOpened=nullptr)
 
 ~LHEReader ()
 

Private Attributes

std::unique_ptr< XMLDocumentcurDoc
 
unsigned int curIndex
 
std::shared_ptr< LHERunInfocurRunInfo
 
std::unique_ptr< SourcecurSource
 
const std::vector< std::string > fileURLs
 
unsigned int firstEvent
 
std::unique_ptr< XMLHandlerhandler
 
int maxEvents
 
std::shared_ptr< void > platform
 
const std::string strName
 
std::vector< std::string > weightsinconfig
 

Detailed Description

Definition at line 16 of file LHEReader.h.

Constructor & Destructor Documentation

◆ LHEReader() [1/3]

lhef::LHEReader::LHEReader ( const edm::ParameterSet params)

Definition at line 419 of file LHEReader.cc.

420  : fileURLs(params.getUntrackedParameter<std::vector<std::string> >("fileNames")),
421  strName(""),
422  firstEvent(params.getUntrackedParameter<unsigned int>("skipEvents", 0)),
423  maxEvents(params.getUntrackedParameter<int>("limitEvents", -1)),
424  curIndex(0),
425  handler(new XMLHandler()) {}
const std::vector< std::string > fileURLs
Definition: LHEReader.h:29
const std::string strName
Definition: LHEReader.h:32
unsigned int firstEvent
Definition: LHEReader.h:33
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:41
unsigned int curIndex
Definition: LHEReader.h:35

◆ LHEReader() [2/3]

lhef::LHEReader::LHEReader ( const std::vector< std::string > &  fileNames,
unsigned int  skip = 0 
)

Definition at line 427 of file LHEReader.cc.

428  : fileURLs(fileNames),
429  strName(""),
431  maxEvents(-1),
432  curIndex(0),
433  handler(new XMLHandler()) {}
const std::vector< std::string > fileURLs
Definition: LHEReader.h:29
const std::string strName
Definition: LHEReader.h:32
unsigned int firstEvent
Definition: LHEReader.h:33
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:41
unsigned int curIndex
Definition: LHEReader.h:35

◆ LHEReader() [3/3]

lhef::LHEReader::LHEReader ( const std::string &  inputs,
unsigned int  skip = 0 
)

Definition at line 435 of file LHEReader.cc.

436  : strName(inputs), firstEvent(firstEvent), maxEvents(-1), curIndex(0), handler(new XMLHandler()) {}
const std::string strName
Definition: LHEReader.h:32
unsigned int firstEvent
Definition: LHEReader.h:33
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:41
unsigned int curIndex
Definition: LHEReader.h:35

◆ ~LHEReader()

lhef::LHEReader::~LHEReader ( )

Definition at line 438 of file LHEReader.cc.

References curDoc, curSource, and handler.

438  {
439  // Explicitly release "orphaned" resources
440  // that were created through DOM implementation
441  // createXXXX factory method *before* last
442  // XMLPlatformUtils::Terminate is called.
443  handler.release();
444  curDoc.release();
445  curSource.release();
446  }
std::unique_ptr< XMLDocument > curDoc
Definition: LHEReader.h:39
std::unique_ptr< Source > curSource
Definition: LHEReader.h:38
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:41

Member Function Documentation

◆ next()

std::shared_ptr< LHEEvent > lhef::LHEReader::next ( bool *  newFileOpened = nullptr)

Definition at line 448 of file LHEReader.cc.

References lhef::LHERunInfo::addHeader(), curDoc, curIndex, curRunInfo, curSource, data, fileURLs, dqmdumpme::first, firstEvent, handler, mps_fire::i, info(), lhef::LHEReader::XMLHandler::kComment, lhef::LHEReader::XMLHandler::kEvent, lhef::LHEReader::XMLHandler::kHeader, lhef::LHEReader::XMLHandler::kInit, lhef::LHEReader::XMLHandler::kNone, particlelevel_cff::LHERunInfo, lhef::logFileAction(), maxEvents, EgammaValidation_cff::num, platform, lhef::XMLDocument::platformHandle(), edm::second(), and strName.

448  {
449  while (curDoc.get() || curIndex < fileURLs.size() || (fileURLs.empty() && !strName.empty())) {
450  if (!curDoc.get()) {
451  if (!platform) {
452  //If we read multiple files, the XercesPlatform must live longer than any one
453  // XMLDocument.
455  }
456  if (!fileURLs.empty()) {
457  logFileAction(" Initiating request to open LHE file ", fileURLs[curIndex]);
458  curSource = std::make_unique<FileSource>(fileURLs[curIndex]);
459  logFileAction(" Successfully opened LHE file ", fileURLs[curIndex]);
460  if (newFileOpened != nullptr)
461  *newFileOpened = true;
462  ++curIndex;
463  } else if (!strName.empty()) {
464  curSource = std::make_unique<StringSource>(strName);
465  }
466  handler->reset();
467  curDoc.reset(curSource->createReader(*handler));
468  curRunInfo.reset();
469  }
470  handler->skipEvent = firstEvent > 0;
471 
472  XMLHandler::Object event = handler->gotObject;
473  handler->gotObject = XMLHandler::kNone;
474 
475  switch (event) {
476  case XMLHandler::kNone:
477  if (!curDoc->parse()) {
478  curDoc.reset();
479  logFileAction(" Closed LHE file ", fileURLs[curIndex - 1]);
480  return std::shared_ptr<LHEEvent>();
481  }
482  break;
483 
484  case XMLHandler::kHeader:
485  break;
486 
487  case XMLHandler::kInit: {
488  std::istringstream data;
489  data.str(handler->buffer);
490  handler->buffer.clear();
491 
492  curRunInfo.reset(new LHERunInfo(data));
493 
494  std::for_each(handler->headers.begin(),
495  handler->headers.end(),
496  std::bind(&LHERunInfo::addHeader, curRunInfo.get(), std::placeholders::_1));
497  handler->headers.clear();
498  } break;
499 
501  break;
502 
503  case XMLHandler::kEvent: {
504  if (!curRunInfo.get())
505  throw cms::Exception("InvalidState") << "Got LHE event without"
506  " initialization."
507  << std::endl;
508 
509  if (firstEvent > 0) {
510  firstEvent--;
511  continue;
512  }
513 
514  if (maxEvents == 0)
515  return std::shared_ptr<LHEEvent>();
516  else if (maxEvents > 0)
517  maxEvents--;
518 
519  std::istringstream data;
520  data.str(handler->buffer);
521  handler->buffer.clear();
522 
523  std::shared_ptr<LHEEvent> lheevent;
524  lheevent.reset(new LHEEvent(curRunInfo, data));
525  const XMLHandler::wgt_info &info = handler->weightsinevent;
526  for (size_t i = 0; i < info.size(); ++i) {
527  double num = -1.0;
528  sscanf(info[i].second.c_str(), "%le", &num);
529  lheevent->addWeight(gen::WeightsInfo(info[i].first, num));
530  }
531  lheevent->setNpLO(handler->npLO);
532  lheevent->setNpNLO(handler->npNLO);
533  lheevent->setEvtNum(handler->evtnum);
534  handler->evtnum = -1;
535  //fill scales
536  if (!handler->scales.empty()) {
537  lheevent->setScales(handler->scales);
538  }
539  return lheevent;
540  }
541  }
542  }
543 
544  return std::shared_ptr<LHEEvent>();
545  }
std::shared_ptr< void > platform
Definition: LHEReader.h:42
static const TGPicture * info(bool iBackgroundIsBlack)
static void logFileAction(char const *msg, std::string const &fileName)
Definition: LH5Reader.cc:31
std::vector< std::pair< std::string, std::string > > wgt_info
Definition: LHEReader.cc:88
const std::vector< std::string > fileURLs
Definition: LHEReader.h:29
U second(std::pair< T, U > const &p)
void addHeader(const Header &header)
Definition: LHERunInfo.h:61
const std::string strName
Definition: LHEReader.h:32
static std::shared_ptr< void > platformHandle()
Definition: XMLUtils.h:49
std::unique_ptr< XMLDocument > curDoc
Definition: LHEReader.h:39
std::unique_ptr< Source > curSource
Definition: LHEReader.h:38
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
unsigned int firstEvent
Definition: LHEReader.h:33
std::shared_ptr< LHERunInfo > curRunInfo
Definition: LHEReader.h:40
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:41
unsigned int curIndex
Definition: LHEReader.h:35
Definition: event.py:1

Member Data Documentation

◆ curDoc

std::unique_ptr<XMLDocument> lhef::LHEReader::curDoc
private

Definition at line 39 of file LHEReader.h.

Referenced by next(), and ~LHEReader().

◆ curIndex

unsigned int lhef::LHEReader::curIndex
private

Definition at line 35 of file LHEReader.h.

Referenced by next().

◆ curRunInfo

std::shared_ptr<LHERunInfo> lhef::LHEReader::curRunInfo
private

Definition at line 40 of file LHEReader.h.

Referenced by next().

◆ curSource

std::unique_ptr<Source> lhef::LHEReader::curSource
private

Definition at line 38 of file LHEReader.h.

Referenced by next(), and ~LHEReader().

◆ fileURLs

const std::vector<std::string> lhef::LHEReader::fileURLs
private

Definition at line 29 of file LHEReader.h.

Referenced by next().

◆ firstEvent

unsigned int lhef::LHEReader::firstEvent
private

Definition at line 33 of file LHEReader.h.

Referenced by looper.Looper::loop(), next(), and Printer.Printer::process().

◆ handler

std::unique_ptr<XMLHandler> lhef::LHEReader::handler
private

◆ maxEvents

int lhef::LHEReader::maxEvents
private

Definition at line 34 of file LHEReader.h.

Referenced by next().

◆ platform

std::shared_ptr<void> lhef::LHEReader::platform
private

Definition at line 42 of file LHEReader.h.

Referenced by next().

◆ strName

const std::string lhef::LHEReader::strName
private

Definition at line 32 of file LHEReader.h.

Referenced by next().

◆ weightsinconfig

std::vector<std::string> lhef::LHEReader::weightsinconfig
private

Definition at line 36 of file LHEReader.h.