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::string &inputs, unsigned int skip=0)
 
 LHEReader (const std::vector< std::string > &fileNames, 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 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()) {}

◆ LHEReader() [2/3]

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()) {}

◆ LHEReader() [3/3]

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()) {}

◆ ~LHEReader()

lhef::LHEReader::~LHEReader ( )

Definition at line 435 of file LHEReader.cc.

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  }

References curDoc, curSource, and handler.

Member Function Documentation

◆ next()

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

Definition at line 445 of file LHEReader.cc.

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  }

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.

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.

lhef::XMLDocument::platformHandle
static std::shared_ptr< void > platformHandle()
Definition: XMLUtils.h:45
mps_fire.i
i
Definition: mps_fire.py:355
lhef::LHEReader::strName
const std::string strName
Definition: LHEReader.h:32
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
lhef::LHEReader::curDoc
std::unique_ptr< XMLDocument > curDoc
Definition: LHEReader.h:39
gen::WeightsInfo
Definition: WeightsInfo.h:10
lhef::LHEReader::fileURLs
const std::vector< std::string > fileURLs
Definition: LHEReader.h:29
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:152
particlelevel_cff.LHERunInfo
LHERunInfo
Definition: particlelevel_cff.py:56
dqmdumpme.first
first
Definition: dqmdumpme.py:55
lhef::LHEReader::XMLHandler::kComment
Definition: LHEReader.cc:106
lhef::LHEReader::XMLHandler::kInit
Definition: LHEReader.cc:106
lhef::logFileAction
static void logFileAction(char const *msg, std::string const &fileName)
Definition: LHEReader.cc:37
lhef::LHEReader::curIndex
unsigned int curIndex
Definition: LHEReader.h:35
lhef::LHERunInfo::addHeader
void addHeader(const Header &header)
Definition: LHERunInfo.h:61
lhef::LHEReader::platform
std::shared_ptr< void > platform
Definition: LHEReader.h:42
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
lhef::LHEReader::XMLHandler::kNone
Definition: LHEReader.cc:106
lhef::LHEReader::curSource
std::unique_ptr< Source > curSource
Definition: LHEReader.h:38
lhef::LHEReader::firstEvent
unsigned int firstEvent
Definition: LHEReader.h:33
lhef::LHEReader::XMLHandler::Object
Object
Definition: LHEReader.cc:106
lhef::LHEReader::maxEvents
int maxEvents
Definition: LHEReader.h:34
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
lhef::LHEReader::XMLHandler::kHeader
Definition: LHEReader.cc:106
lhef::LHEReader::curRunInfo
std::shared_ptr< LHERunInfo > curRunInfo
Definition: LHEReader.h:40
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
LaserTracksInput_cfi.fileNames
fileNames
Definition: LaserTracksInput_cfi.py:8
cms::Exception
Definition: Exception.h:70
lhef::LHEReader::handler
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:41
lhef::LHEReader::XMLHandler::kEvent
Definition: LHEReader.cc:106
event
Definition: event.py:1
lhef::LHEReader::XMLHandler::wgt_info
std::vector< std::pair< std::string, std::string > > wgt_info
Definition: LHEReader.cc:89