CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/IOMC/Input/plugins/HepMCEventWriter.cc

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/HepMCProduct.h"
00016 
00017 #include "HepMC/IO_GenEvent.h"
00018 
00019 
00020 class HepMCEventWriter : public edm::EDAnalyzer {
00021 public:
00022   explicit HepMCEventWriter(const edm::ParameterSet &params);
00023   virtual ~HepMCEventWriter();
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   HepMC::IO_GenEvent* _output;
00032 
00033 };
00034 
00035 HepMCEventWriter::HepMCEventWriter(const edm::ParameterSet &params)
00036 {
00037 }
00038 
00039 HepMCEventWriter::~HepMCEventWriter()
00040 {
00041 }
00042 
00043 void HepMCEventWriter::beginRun(const edm::Run &run, const edm::EventSetup &es)
00044 {
00045 
00046   _output = new HepMC::IO_GenEvent("GenEvent_ASCII.dat",std::ios::out);
00047 
00048 }
00049 
00050 
00051 void HepMCEventWriter::endRun(const edm::Run &run, const edm::EventSetup &es)
00052 {
00053   if (_output) delete _output;
00054 }
00055 
00056 void HepMCEventWriter::analyze(const edm::Event &event, const edm::EventSetup &es)
00057 {
00058 
00059   edm::Handle<edm::HepMCProduct> product;
00060   event.getByType( product );
00061   
00062   const HepMC::GenEvent* evt = product->GetEvent();
00063 
00064   _output->write_event(evt);
00065 
00066 }
00067 
00068 DEFINE_FWK_MODULE(HepMCEventWriter);