CMS 3D CMS Logo

LHESource.cc

Go to the documentation of this file.
00001 #include <algorithm>
00002 #include <functional>
00003 #include <iostream>
00004 #include <string>
00005 #include <memory>
00006 
00007 #include <boost/bind.hpp>
00008 
00009 #include "FWCore/Sources/interface/ExternalInputSource.h"
00010 #include "FWCore/Framework/interface/InputSourceMacros.h"
00011 #include "FWCore/Framework/interface/MakerMacros.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "FWCore/Framework/interface/Run.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "SimDataFormats/GeneratorProducts/interface/LesHouches.h"
00018 #include "GeneratorInterface/LHEInterface/interface/LHERunInfo.h"
00019 #include "GeneratorInterface/LHEInterface/interface/LHEEvent.h"
00020 #include "GeneratorInterface/LHEInterface/interface/LHEReader.h"
00021 #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
00022 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
00023 
00024 #include "LHESource.h"
00025 
00026 using namespace lhef;
00027 
00028 LHESource::LHESource(const edm::ParameterSet &params,
00029                      const edm::InputSourceDescription &desc) :
00030         ExternalInputSource(params, desc, false),
00031         reader(new LHEReader(fileNames(), params.getUntrackedParameter<unsigned int>("seekEvent", 0))),
00032         skipEvents(params.getUntrackedParameter<unsigned int>("skipEvents", 0))
00033 {
00034         produces<LHEEventProduct>();
00035         produces<LHERunInfoProduct, edm::InRun>();
00036 }
00037 
00038 LHESource::~LHESource()
00039 {
00040 }
00041 
00042 void LHESource::endJob()
00043 {
00044         reader.reset();
00045 }
00046 
00047 void LHESource::nextEvent()
00048 {
00049         if (partonLevel)
00050                 return;
00051 
00052         while(skipEvents > 0) {
00053                 skipEvents--;
00054                 partonLevel = reader->next();
00055                 if (!partonLevel)
00056                         return;
00057         }
00058 
00059         partonLevel = reader->next();
00060         if (!partonLevel)
00061                         return;
00062 
00063         if (!runInfo)
00064                 runInfo = partonLevel->getRunInfo();
00065 }
00066 
00067 void LHESource::beginRun(edm::Run &run)
00068 {
00069         nextEvent();
00070         if (runInfo) {
00071                 std::auto_ptr<LHERunInfoProduct> product(
00072                                 new LHERunInfoProduct(*runInfo->getHEPRUP()));
00073                 std::for_each(runInfo->getHeaders().begin(),
00074                               runInfo->getHeaders().end(),
00075                               boost::bind(
00076                                 &LHERunInfoProduct::addHeader,
00077                                 product.get(), _1));
00078                 std::for_each(runInfo->getComments().begin(),
00079                               runInfo->getComments().end(),
00080                               boost::bind(&LHERunInfoProduct::addComment,
00081                                 product.get(), _1));
00082                 run.put(product);
00083                 runInfo.reset();
00084 
00085         }
00086 }
00087 
00088 bool LHESource::produce(edm::Event &event)
00089 {
00090         nextEvent();
00091         if (!partonLevel)
00092                 return false;
00093 
00094         std::auto_ptr<LHEEventProduct> product(
00095                         new LHEEventProduct(*partonLevel->getHEPEUP()));
00096         if (partonLevel->getPDF())
00097                 product->setPDF(*partonLevel->getPDF());
00098         std::for_each(partonLevel->getComments().begin(),
00099                       partonLevel->getComments().end(),
00100                       boost::bind(&LHEEventProduct::addComment,
00101                                   product.get(), _1));
00102         event.put(product);
00103 
00104         partonLevel.reset();
00105         return true;
00106 }
00107 
00108 DEFINE_ANOTHER_FWK_INPUT_SOURCE(LHESource);

Generated on Tue Jun 9 17:37:03 2009 for CMSSW by  doxygen 1.5.4