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

415  : fileURLs(params.getUntrackedParameter<std::vector<std::string> >("fileNames")),
416  strName(""),
417  firstEvent(params.getUntrackedParameter<unsigned int>("skipEvents", 0)),
418  maxEvents(params.getUntrackedParameter<int>("limitEvents", -1)),
419  curIndex(0),
420  handler(new XMLHandler()) {}

◆ LHEReader() [2/3]

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

Definition at line 422 of file LHEReader.cc.

423  : fileURLs(fileNames),
424  strName(""),
426  maxEvents(-1),
427  curIndex(0),
428  handler(new XMLHandler()) {}

◆ LHEReader() [3/3]

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

Definition at line 430 of file LHEReader.cc.

431  : strName(inputs), firstEvent(firstEvent), maxEvents(-1), curIndex(0), handler(new XMLHandler()) {}

◆ ~LHEReader()

lhef::LHEReader::~LHEReader ( )

Definition at line 433 of file LHEReader.cc.

433  {
434  // Explicitly release "orphaned" resources
435  // that were created through DOM implementation
436  // createXXXX factory method *before* last
437  // XMLPlatformUtils::Terminate is called.
438  handler.release();
439  curDoc.release();
440  curSource.release();
441  }

References curDoc, curSource, and handler.

Member Function Documentation

◆ next()

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

Definition at line 443 of file LHEReader.cc.

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

References lhef::LHERunInfo::addHeader(), curDoc, curIndex, curRunInfo, curSource, data, fileURLs, 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:428
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:222
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
particlelevel_cff.LHERunInfo
LHERunInfo
Definition: particlelevel_cff.py:56
lhef::LHEReader::XMLHandler::kComment
Definition: LHEReader.cc:104
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
lhef::LHEReader::XMLHandler::kInit
Definition: LHEReader.cc:104
lhef::logFileAction
static void logFileAction(char const *msg, std::string const &fileName)
Definition: LH5Reader.cc:29
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:104
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:104
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:104
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:104
event
Definition: event.py:1
lhef::LHEReader::XMLHandler::wgt_info
std::vector< std::pair< std::string, std::string > > wgt_info
Definition: LHEReader.cc:87