CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc

Go to the documentation of this file.
00001 // F. Cossutti
00002 // $Date: 2011/11/13 22:36:09 $
00003 // $Revision: 1.2 $//
00004 
00005 // Dump in standard ascii format the LHE file stored as string lumi product
00006 
00007 
00008 // system include files
00009 #include <memory>
00010 #include <string>
00011 #include <fstream>
00012 
00013 // user include files
00014 #include "FWCore/Framework/interface/Frameworkfwd.h"
00015 #include "FWCore/Framework/interface/EDAnalyzer.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 #include "FWCore/Framework/interface/Event.h"
00019 #include "FWCore/Framework/interface/MakerMacros.h"
00020 #include "FWCore/Framework/interface/EventSetup.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/Framework/interface/Run.h"
00023 
00024 #include "FWCore/Utilities/interface/InputTag.h"
00025 
00026 //
00027 // class declaration
00028 //
00029 
00030 class ExternalLHEAsciiDumper : public edm::EDAnalyzer {
00031 public:
00032   explicit ExternalLHEAsciiDumper(const edm::ParameterSet&);
00033   ~ExternalLHEAsciiDumper();
00034   
00035   
00036 private:
00037   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00038   virtual void endRun(edm::Run const&, edm::EventSetup const&);
00039   virtual void endJob();
00040 
00041   edm::InputTag lheProduct_;
00042   std::string   lheFileName_;
00043 
00044   // ----------member data ---------------------------
00045   
00046 };
00047 
00048 ExternalLHEAsciiDumper::ExternalLHEAsciiDumper(const edm::ParameterSet& ps):
00049   lheProduct_( ps.getParameter<edm::InputTag>("lheProduct") ),
00050   lheFileName_( ps.getParameter<std::string>("lheFileName") )
00051 {
00052   
00053   return;
00054   
00055 }
00056 
00057 ExternalLHEAsciiDumper::~ExternalLHEAsciiDumper()
00058 {
00059 }
00060 
00061 void
00062 ExternalLHEAsciiDumper::analyze(const edm::Event&, const edm::EventSetup&)
00063 {
00064 }
00065 
00066 // ------------ method called once each job just after ending the event loop  ------------
00067 
00068 void
00069 ExternalLHEAsciiDumper::endRun(edm::Run const& iRun, edm::EventSetup const&) {
00070 
00071   edm::Handle< std::string > LHEAscii;
00072   iRun.getByLabel(lheProduct_,LHEAscii);
00073 
00074   const char * theName(lheFileName_.c_str());
00075   std::ofstream outfile;
00076   outfile.open (theName, std::ofstream::out | std::ofstream::app);
00077   outfile << (*LHEAscii);
00078   outfile.close();
00079 
00080 }
00081 
00082 void ExternalLHEAsciiDumper::endJob() {
00083 }
00084 
00085 DEFINE_FWK_MODULE(ExternalLHEAsciiDumper);