CMS 3D CMS Logo

Classes | Public Member Functions | Private Attributes

lhef::LHEReader Class Reference

#include <LHEReader.h>

List of all members.

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)
boost::shared_ptr< LHEEventnext ()
 ~LHEReader ()

Private Attributes

std::auto_ptr< XMLDocumentcurDoc
unsigned int curIndex
boost::shared_ptr< LHERunInfocurRunInfo
std::auto_ptr< SourcecurSource
const std::vector< std::string > fileURLs
unsigned int firstEvent
std::auto_ptr< XMLHandlerhandler
int maxEvents
const std::string strName

Detailed Description

Definition at line 18 of file LHEReader.h.


Constructor & Destructor Documentation

lhef::LHEReader::LHEReader ( const edm::ParameterSet params)

Definition at line 310 of file LHEReader.cc.

{
}

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

Definition at line 319 of file LHEReader.cc.

                                              :
  fileURLs(fileNames), strName(""), firstEvent(firstEvent), maxEvents(-1),
        curIndex(0), handler(new XMLHandler())
{
}

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

Definition at line 326 of file LHEReader.cc.

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

lhef::LHEReader::~LHEReader ( )

Definition at line 333 of file LHEReader.cc.

{
}


Member Function Documentation

boost::shared_ptr< LHEEvent > lhef::LHEReader::next ( void  )

Definition at line 337 of file LHEReader.cc.

References lhef::LHERunInfo::addHeader(), curDoc, curIndex, curRunInfo, curSource, runTheMatrix::data, event(), fileURLs, firstEvent, handler, lhef::LHEReader::XMLHandler::kComment, lhef::LHEReader::XMLHandler::kEvent, lhef::LHEReader::XMLHandler::kHeader, lhef::LHEReader::XMLHandler::kInit, lhef::LHEReader::XMLHandler::kNone, maxEvents, and strName.

  {

    while(curDoc.get() || curIndex < fileURLs.size() || (fileURLs.size() == 0 && strName != "" ) ) {
      if (!curDoc.get()) {
        if ( fileURLs.size() > 0 ) 
          curSource.reset(new FileSource(fileURLs[curIndex++]));
        else if ( strName != "" ) 
          curSource.reset(new StringSource(strName));
        handler->reset();
        curDoc.reset(curSource->createReader(*handler));
        curRunInfo.reset();
      }
    
      XMLHandler::Object event = handler->gotObject;
      handler->gotObject = XMLHandler::kNone;
    
      std::istringstream data;
      if (event != XMLHandler::kNone) {
        data.str(handler->buffer);
        handler->buffer.clear();
      }
      
      switch(event) {
      case XMLHandler::kNone:
        if (!curDoc->parse())
          curDoc.reset();
        break;
        
      case XMLHandler::kHeader:
        break;
        
      case XMLHandler::kInit:
        curRunInfo.reset(new LHERunInfo(data));
                
        std::for_each(handler->headers.begin(),
                      handler->headers.end(),
                      boost::bind(&LHERunInfo::addHeader,
                                  curRunInfo.get(), _1));
        handler->headers.clear();
        break;
        
      case XMLHandler::kComment:
        break;
        
      case XMLHandler::kEvent:
        if (!curRunInfo.get())
          throw cms::Exception("InvalidState")
            << "Got LHE event without"
            " initialization." << std::endl;

        if (firstEvent > 0) {
          firstEvent--;
          continue;
        }
        
        if (maxEvents == 0)
          return boost::shared_ptr<LHEEvent>();
        else if (maxEvents > 0)
          maxEvents--;
        
        return boost::shared_ptr<LHEEvent>(
                                           new LHEEvent(curRunInfo, data));
      }
        }
    
        return boost::shared_ptr<LHEEvent>();
  }
  

Member Data Documentation

std::auto_ptr<XMLDocument> lhef::LHEReader::curDoc [private]

Definition at line 42 of file LHEReader.h.

Referenced by next().

unsigned int lhef::LHEReader::curIndex [private]

Definition at line 39 of file LHEReader.h.

Referenced by next().

boost::shared_ptr<LHERunInfo> lhef::LHEReader::curRunInfo [private]

Definition at line 43 of file LHEReader.h.

Referenced by next().

std::auto_ptr<Source> lhef::LHEReader::curSource [private]

Definition at line 41 of file LHEReader.h.

Referenced by next().

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

Definition at line 33 of file LHEReader.h.

Referenced by next().

unsigned int lhef::LHEReader::firstEvent [private]

Definition at line 37 of file LHEReader.h.

Referenced by next().

std::auto_ptr<XMLHandler> lhef::LHEReader::handler [private]

Definition at line 44 of file LHEReader.h.

Referenced by next().

Definition at line 38 of file LHEReader.h.

Referenced by next().

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

Definition at line 36 of file LHEReader.h.

Referenced by next().