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

461  :
462  fileURLs(params.getUntrackedParameter< std::vector<std::string> >("fileNames")),
463  strName(""),
464  firstEvent(params.getUntrackedParameter<unsigned int>("skipEvents", 0)),
465  maxEvents(params.getUntrackedParameter<int>("limitEvents", -1)),
466  curIndex(0), handler(new XMLHandler())
467 {
468 }
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 470 of file LHEReader.cc.

471  :
473  curIndex(0), handler(new XMLHandler())
474 {
475 }
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 477 of file LHEReader.cc.

478  :
480  curIndex(0), handler(new XMLHandler())
481 {
482 }
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 484 of file LHEReader.cc.

References curDoc, curSource, and handler.

485 {
486  // Explicitly release "orphaned" resources
487  // that were created through DOM implementation
488  // createXXXX factory method *before* last
489  // XMLPlatformUtils::Terminate is called.
490  handler.release();
491  curDoc.release();
492  curSource.release();
493 }
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 495 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.

496  {
497  while(curDoc.get() || curIndex < fileURLs.size() || (fileURLs.empty() && !strName.empty() ) ) {
498  if (!curDoc.get()) {
499  if(!platform) {
500  //If we read multiple files, the XercesPlatform must live longer than any one
501  // XMLDocument.
503  }
504  if ( !fileURLs.empty() ) {
505  logFileAction(" Initiating request to open LHE file ", fileURLs[curIndex]);
506  curSource.reset(new FileSource(fileURLs[curIndex]));
507  logFileAction(" Successfully opened LHE file ", fileURLs[curIndex]);
508  if ( newFileOpened != nullptr ) *newFileOpened = true;
509  ++curIndex;
510  } else if ( !strName.empty() ) {
511  curSource.reset(new StringSource(strName));
512  }
513  handler->reset();
514  curDoc.reset(curSource->createReader(*handler));
515  curRunInfo.reset();
516  }
517  handler->skipEvent = firstEvent > 0;
518 
519  XMLHandler::Object event = handler->gotObject;
520  handler->gotObject = XMLHandler::kNone;
521 
522 
523  switch(event) {
524  case XMLHandler::kNone:
525  if (!curDoc->parse()) {
526  curDoc.reset();
527  logFileAction(" Closed LHE file ", fileURLs[curIndex - 1]);
528  return std::shared_ptr<LHEEvent>();
529  }
530  break;
531 
532  case XMLHandler::kHeader:
533  break;
534 
535  case XMLHandler::kInit:
536  {
537  std::istringstream data;
538  data.str(handler->buffer);
539  handler->buffer.clear();
540 
541  curRunInfo.reset(new LHERunInfo(data));
542 
543  std::for_each(handler->headers.begin(),
544  handler->headers.end(),
545  boost::bind(&LHERunInfo::addHeader,
546  curRunInfo.get(), _1));
547  handler->headers.clear();
548  }
549  break;
550 
552  break;
553 
554  case XMLHandler::kEvent:
555  {
556  if (!curRunInfo.get())
557  throw cms::Exception("InvalidState")
558  << "Got LHE event without"
559  " initialization." << std::endl;
560 
561  if (firstEvent > 0) {
562  firstEvent--;
563  continue;
564  }
565 
566  if (maxEvents == 0)
567  return std::shared_ptr<LHEEvent>();
568  else if (maxEvents > 0)
569  maxEvents--;
570 
571  std::istringstream data;
572  data.str(handler->buffer);
573  handler->buffer.clear();
574 
575  std::shared_ptr<LHEEvent> lheevent;
576  lheevent.reset(new LHEEvent(curRunInfo, data));
577  const XMLHandler::wgt_info& info = handler->weightsinevent;
578  for( size_t i=0; i< info.size(); ++i ) {
579  double num = -1.0;
580  sscanf(info[i].second.c_str(),"%le",&num);
581  lheevent->addWeight(gen::WeightsInfo(info[i].first,num));
582  }
583  lheevent->setNpLO(handler->npLO);
584  lheevent->setNpNLO(handler->npNLO);
585  lheevent->setEvtNum(handler->evtnum);
586  handler->evtnum = -1;
587  //fill scales
588  if (!handler->scales.empty()) {
589  lheevent->setScales(handler->scales);
590  }
591  return lheevent;
592  }
593  }
594  }
595 
596  return std::shared_ptr<LHEEvent>();
597  }
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.