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

456  :
457  fileURLs(params.getUntrackedParameter< std::vector<std::string> >("fileNames")),
458  strName(""),
459  firstEvent(params.getUntrackedParameter<unsigned int>("skipEvents", 0)),
460  maxEvents(params.getUntrackedParameter<int>("limitEvents", -1)),
461  curIndex(0), handler(new XMLHandler())
462 {
463 }
T getUntrackedParameter(std::string const &, T const &) const
const std::vector< std::string > fileURLs
Definition: LHEReader.h:31
const std::string strName
Definition: LHEReader.h:34
unsigned int firstEvent
Definition: LHEReader.h:35
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:43
unsigned int curIndex
Definition: LHEReader.h:37
lhef::LHEReader::LHEReader ( const std::vector< std::string > &  fileNames,
unsigned int  skip = 0 
)

Definition at line 465 of file LHEReader.cc.

466  :
468  curIndex(0), handler(new XMLHandler())
469 {
470 }
const std::vector< std::string > fileURLs
Definition: LHEReader.h:31
const std::string strName
Definition: LHEReader.h:34
unsigned int firstEvent
Definition: LHEReader.h:35
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:43
unsigned int curIndex
Definition: LHEReader.h:37
lhef::LHEReader::LHEReader ( const std::string &  inputs,
unsigned int  skip = 0 
)

Definition at line 472 of file LHEReader.cc.

473  :
475  curIndex(0), handler(new XMLHandler())
476 {
477 }
const std::string strName
Definition: LHEReader.h:34
unsigned int firstEvent
Definition: LHEReader.h:35
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:43
unsigned int curIndex
Definition: LHEReader.h:37
lhef::LHEReader::~LHEReader ( )

Definition at line 479 of file LHEReader.cc.

References curDoc, curSource, and handler.

480 {
481  // Explicitly release "orphaned" resources
482  // that were created through DOM implementation
483  // createXXXX factory method *before* last
484  // XMLPlatformUtils::Terminate is called.
485  handler.release();
486  curDoc.release();
487  curSource.release();
488 }
std::unique_ptr< XMLDocument > curDoc
Definition: LHEReader.h:41
std::unique_ptr< Source > curSource
Definition: LHEReader.h:40
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:43

Member Function Documentation

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

Definition at line 490 of file LHEReader.cc.

References lhef::LHERunInfo::addHeader(), curDoc, curIndex, curRunInfo, curSource, data, fileURLs, plotBeamSpotDB::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, pileupDistInMC::num, platform, lhef::XMLDocument::platformHandle(), edm::second(), and strName.

491  {
492  while(curDoc.get() || curIndex < fileURLs.size() || (fileURLs.empty() && !strName.empty() ) ) {
493  if (!curDoc.get()) {
494  if(!platform) {
495  //If we read multiple files, the XercesPlatform must live longer than any one
496  // XMLDocument.
498  }
499  if ( !fileURLs.empty() ) {
500  logFileAction(" Initiating request to open LHE file ", fileURLs[curIndex]);
501  curSource.reset(new FileSource(fileURLs[curIndex]));
502  logFileAction(" Successfully opened LHE file ", fileURLs[curIndex]);
503  if ( newFileOpened != nullptr ) *newFileOpened = true;
504  ++curIndex;
505  } else if ( !strName.empty() ) {
506  curSource.reset(new StringSource(strName));
507  }
508  handler->reset();
509  curDoc.reset(curSource->createReader(*handler));
510  curRunInfo.reset();
511  }
512  handler->skipEvent = firstEvent > 0;
513 
514  XMLHandler::Object event = handler->gotObject;
515  handler->gotObject = XMLHandler::kNone;
516 
517 
518  switch(event) {
519  case XMLHandler::kNone:
520  if (!curDoc->parse()) {
521  curDoc.reset();
522  logFileAction(" Closed LHE file ", fileURLs[curIndex - 1]);
523  return std::shared_ptr<LHEEvent>();
524  }
525  break;
526 
527  case XMLHandler::kHeader:
528  break;
529 
530  case XMLHandler::kInit:
531  {
532  std::istringstream data;
533  data.str(handler->buffer);
534  handler->buffer.clear();
535 
536  curRunInfo.reset(new LHERunInfo(data));
537 
538  std::for_each(handler->headers.begin(),
539  handler->headers.end(),
540  boost::bind(&LHERunInfo::addHeader,
541  curRunInfo.get(), _1));
542  handler->headers.clear();
543  }
544  break;
545 
547  break;
548 
549  case XMLHandler::kEvent:
550  {
551  if (!curRunInfo.get())
552  throw cms::Exception("InvalidState")
553  << "Got LHE event without"
554  " initialization." << std::endl;
555 
556  if (firstEvent > 0) {
557  firstEvent--;
558  continue;
559  }
560 
561  if (maxEvents == 0)
562  return std::shared_ptr<LHEEvent>();
563  else if (maxEvents > 0)
564  maxEvents--;
565 
566  std::istringstream data;
567  data.str(handler->buffer);
568  handler->buffer.clear();
569 
570  std::shared_ptr<LHEEvent> lheevent;
571  lheevent.reset(new LHEEvent(curRunInfo, data));
572  const XMLHandler::wgt_info& info = handler->weightsinevent;
573  for( size_t i=0; i< info.size(); ++i ) {
574  double num = -1.0;
575  sscanf(info[i].second.c_str(),"%le",&num);
576  lheevent->addWeight(gen::WeightsInfo(info[i].first,num));
577  }
578  lheevent->setNpLO(handler->npLO);
579  lheevent->setNpNLO(handler->npNLO);
580  //fill scales
581  if (!handler->scales.empty()) {
582  lheevent->setScales(handler->scales);
583  }
584  return lheevent;
585  }
586  }
587  }
588 
589  return std::shared_ptr<LHEEvent>();
590  }
std::shared_ptr< void > platform
Definition: LHEReader.h:44
static const TGPicture * info(bool iBackgroundIsBlack)
static void logFileAction(char const *msg, std::string const &fileName)
Definition: LHEReader.cc:37
const std::vector< std::string > fileURLs
Definition: LHEReader.h:31
U second(std::pair< T, U > const &p)
void addHeader(const Header &header)
Definition: LHERunInfo.h:63
const std::string strName
Definition: LHEReader.h:34
std::vector< std::pair< std::string, std::string > > wgt_info
Definition: LHEReader.cc:100
static std::shared_ptr< void > platformHandle()
Definition: XMLUtils.h:46
std::unique_ptr< XMLDocument > curDoc
Definition: LHEReader.h:41
std::unique_ptr< Source > curSource
Definition: LHEReader.h:40
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int firstEvent
Definition: LHEReader.h:35
std::shared_ptr< LHERunInfo > curRunInfo
Definition: LHEReader.h:42
std::unique_ptr< XMLHandler > handler
Definition: LHEReader.h:43
unsigned int curIndex
Definition: LHEReader.h:37
Definition: event.py:1

Member Data Documentation

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

Definition at line 41 of file LHEReader.h.

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

unsigned int lhef::LHEReader::curIndex
private

Definition at line 37 of file LHEReader.h.

Referenced by next().

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

Definition at line 42 of file LHEReader.h.

Referenced by next().

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

Definition at line 40 of file LHEReader.h.

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

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

Definition at line 31 of file LHEReader.h.

Referenced by next().

unsigned int lhef::LHEReader::firstEvent
private

Definition at line 35 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 43 of file LHEReader.h.

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

int lhef::LHEReader::maxEvents
private

Definition at line 36 of file LHEReader.h.

Referenced by next().

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

Definition at line 44 of file LHEReader.h.

Referenced by next().

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

Definition at line 34 of file LHEReader.h.

Referenced by next().

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

Definition at line 38 of file LHEReader.h.