Go to the documentation of this file.00001 #include <algorithm>
00002 #include <iostream>
00003 #include <iterator>
00004 #include <fstream>
00005 #include <string>
00006 #include <memory>
00007
00008 #include "FWCore/Framework/interface/EDAnalyzer.h"
00009 #include "FWCore/Framework/interface/MakerMacros.h"
00010 #include "FWCore/Framework/interface/Event.h"
00011 #include "FWCore/Framework/interface/Run.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014
00015 #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
00016 #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
00017
00018 using namespace lhef;
00019
00020 class LHEWriter : public edm::EDAnalyzer {
00021 public:
00022 explicit LHEWriter(const edm::ParameterSet ¶ms);
00023 virtual ~LHEWriter();
00024
00025 protected:
00026 virtual void beginRun(const edm::Run &run, const edm::EventSetup &es);
00027 virtual void endRun(const edm::Run &run, const edm::EventSetup &es);
00028 virtual void analyze(const edm::Event &event, const edm::EventSetup &es);
00029
00030 private:
00031 std::ofstream file;
00032 };
00033
00034 LHEWriter::LHEWriter(const edm::ParameterSet ¶ms)
00035 {
00036 }
00037
00038 LHEWriter::~LHEWriter()
00039 {
00040 }
00041
00042 void LHEWriter::beginRun(const edm::Run &run, const edm::EventSetup &es)
00043 {
00044 edm::Handle<LHERunInfoProduct> product;
00045 run.getByLabel("source", product);
00046
00047 file.open("writer.lhe", std::fstream::out | std::fstream::trunc);
00048 std::copy(product->begin(), product->end(),
00049 std::ostream_iterator<std::string>(file));
00050 }
00051
00052 void LHEWriter::endRun(const edm::Run &run, const edm::EventSetup &es)
00053 {
00054 file << LHERunInfoProduct::endOfFile();
00055 file.close();
00056 }
00057
00058 void LHEWriter::analyze(const edm::Event &event, const edm::EventSetup &es)
00059 {
00060 edm::Handle<LHEEventProduct> product;
00061 event.getByLabel("source", product);
00062
00063 std::copy(product->begin(), product->end(),
00064 std::ostream_iterator<std::string>(file));
00065 }
00066
00067 DEFINE_FWK_MODULE(LHEWriter);