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

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

Definition at line 416 of file LHEReader.cc.

417  : fileURLs(params.getUntrackedParameter<std::vector<std::string> >("fileNames")),
418  strName(""),
419  firstEvent(params.getUntrackedParameter<unsigned int>("skipEvents", 0)),
420  maxEvents(params.getUntrackedParameter<int>("limitEvents", -1)),
421  curIndex(0),
422  handler(new XMLHandler()) {}
T getUntrackedParameter(std::string const &, T const &) const
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
lhef::LHEReader::LHEReader ( const std::vector< std::string > &  fileNames,
unsigned int  skip = 0 
)

Definition at line 424 of file LHEReader.cc.

425  : fileURLs(fileNames),
426  strName(""),
428  maxEvents(-1),
429  curIndex(0),
430  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
lhef::LHEReader::LHEReader ( const std::string &  inputs,
unsigned int  skip = 0 
)

Definition at line 432 of file LHEReader.cc.

433  : 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
lhef::LHEReader::~LHEReader ( )

Definition at line 435 of file LHEReader.cc.

References curDoc, curSource, and handler.

435  {
436  // Explicitly release "orphaned" resources
437  // that were created through DOM implementation
438  // createXXXX factory method *before* last
439  // XMLPlatformUtils::Terminate is called.
440  handler.release();
441  curDoc.release();
442  curSource.release();
443  }
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

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

Definition at line 445 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.

445  {
446  while (curDoc.get() || curIndex < fileURLs.size() || (fileURLs.empty() && !strName.empty())) {
447  if (!curDoc.get()) {
448  if (!platform) {
449  //If we read multiple files, the XercesPlatform must live longer than any one
450  // XMLDocument.
452  }
453  if (!fileURLs.empty()) {
454  logFileAction(" Initiating request to open LHE file ", fileURLs[curIndex]);
455  curSource.reset(new FileSource(fileURLs[curIndex]));
456  logFileAction(" Successfully opened LHE file ", fileURLs[curIndex]);
457  if (newFileOpened != nullptr)
458  *newFileOpened = true;
459  ++curIndex;
460  } else if (!strName.empty()) {
461  curSource.reset(new StringSource(strName));
462  }
463  handler->reset();
464  curDoc.reset(curSource->createReader(*handler));
465  curRunInfo.reset();
466  }
467  handler->skipEvent = firstEvent > 0;
468 
469  XMLHandler::Object event = handler->gotObject;
470  handler->gotObject = XMLHandler::kNone;
471 
472  switch (event) {
473  case XMLHandler::kNone:
474  if (!curDoc->parse()) {
475  curDoc.reset();
476  logFileAction(" Closed LHE file ", fileURLs[curIndex - 1]);
477  return std::shared_ptr<LHEEvent>();
478  }
479  break;
480 
481  case XMLHandler::kHeader:
482  break;
483 
484  case XMLHandler::kInit: {
485  std::istringstream data;
486  data.str(handler->buffer);
487  handler->buffer.clear();
488 
489  curRunInfo.reset(new LHERunInfo(data));
490 
491  std::for_each(handler->headers.begin(),
492  handler->headers.end(),
493  boost::bind(&LHERunInfo::addHeader, curRunInfo.get(), _1));
494  handler->headers.clear();
495  } break;
496 
498  break;
499 
500  case XMLHandler::kEvent: {
501  if (!curRunInfo.get())
502  throw cms::Exception("InvalidState") << "Got LHE event without"
503  " initialization."
504  << std::endl;
505 
506  if (firstEvent > 0) {
507  firstEvent--;
508  continue;
509  }
510 
511  if (maxEvents == 0)
512  return std::shared_ptr<LHEEvent>();
513  else if (maxEvents > 0)
514  maxEvents--;
515 
516  std::istringstream data;
517  data.str(handler->buffer);
518  handler->buffer.clear();
519 
520  std::shared_ptr<LHEEvent> lheevent;
521  lheevent.reset(new LHEEvent(curRunInfo, data));
522  const XMLHandler::wgt_info &info = handler->weightsinevent;
523  for (size_t i = 0; i < info.size(); ++i) {
524  double num = -1.0;
525  sscanf(info[i].second.c_str(), "%le", &num);
526  lheevent->addWeight(gen::WeightsInfo(info[i].first, num));
527  }
528  lheevent->setNpLO(handler->npLO);
529  lheevent->setNpNLO(handler->npNLO);
530  //fill scales
531  if (!handler->scales.empty()) {
532  lheevent->setScales(handler->scales);
533  }
534  return lheevent;
535  }
536  }
537  }
538 
539  return std::shared_ptr<LHEEvent>();
540  }
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: LHEReader.cc:37
std::vector< std::pair< std::string, std::string > > wgt_info
Definition: LHEReader.cc:89
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:45
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:79
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

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

Definition at line 39 of file LHEReader.h.

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

unsigned int lhef::LHEReader::curIndex
private

Definition at line 35 of file LHEReader.h.

Referenced by next().

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

Definition at line 40 of file LHEReader.h.

Referenced by next().

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

Definition at line 38 of file LHEReader.h.

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

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

Definition at line 29 of file LHEReader.h.

Referenced by next().

unsigned int lhef::LHEReader::firstEvent
private

Definition at line 33 of file LHEReader.h.

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

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

Definition at line 41 of file LHEReader.h.

Referenced by next(), ~LHEReader(), and lhef::LHEReader::Source::~Source().

int lhef::LHEReader::maxEvents
private

Definition at line 34 of file LHEReader.h.

Referenced by next().

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

Definition at line 42 of file LHEReader.h.

Referenced by next().

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

Definition at line 32 of file LHEReader.h.

Referenced by next().

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

Definition at line 36 of file LHEReader.h.