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

416  : fileURLs(params.getUntrackedParameter<std::vector<std::string> >("fileNames")),
417  strName(""),
418  firstEvent(params.getUntrackedParameter<unsigned int>("skipEvents", 0)),
419  maxEvents(params.getUntrackedParameter<int>("limitEvents", -1)),
420  curIndex(0),
421  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 423 of file LHEReader.cc.

424  : fileURLs(fileNames),
425  strName(""),
427  maxEvents(-1),
428  curIndex(0),
429  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 431 of file LHEReader.cc.

432  : 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 434 of file LHEReader.cc.

References curDoc, curSource, and handler.

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

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

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