Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <memory>
00010 #include <string>
00011 #include <sstream>
00012 #include <fstream>
00013 #include <boost/algorithm/string.hpp>
00014
00015
00016 #include "FWCore/Framework/interface/Frameworkfwd.h"
00017 #include "FWCore/Framework/interface/EDAnalyzer.h"
00018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00019
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/MakerMacros.h"
00022 #include "FWCore/Framework/interface/EventSetup.h"
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 #include "FWCore/Framework/interface/Run.h"
00025
00026 #include "SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h"
00027
00028 #include "FWCore/Utilities/interface/InputTag.h"
00029
00030
00031
00032
00033
00034 class ExternalLHEAsciiDumper : public edm::EDAnalyzer {
00035 public:
00036 explicit ExternalLHEAsciiDumper(const edm::ParameterSet&);
00037 ~ExternalLHEAsciiDumper();
00038
00039
00040 private:
00041 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00042 virtual void endRun(edm::Run const&, edm::EventSetup const&);
00043 virtual void endJob();
00044
00045 edm::InputTag lheProduct_;
00046 std::string lheFileName_;
00047
00048
00049
00050 };
00051
00052 ExternalLHEAsciiDumper::ExternalLHEAsciiDumper(const edm::ParameterSet& ps):
00053 lheProduct_( ps.getParameter<edm::InputTag>("lheProduct") ),
00054 lheFileName_( ps.getParameter<std::string>("lheFileName") )
00055 {
00056
00057 return;
00058
00059 }
00060
00061 ExternalLHEAsciiDumper::~ExternalLHEAsciiDumper()
00062 {
00063 }
00064
00065 void
00066 ExternalLHEAsciiDumper::analyze(const edm::Event&, const edm::EventSetup&)
00067 {
00068 }
00069
00070
00071
00072 void
00073 ExternalLHEAsciiDumper::endRun(edm::Run const& iRun, edm::EventSetup const&) {
00074
00075 edm::Handle< LHEXMLStringProduct > LHEAscii;
00076 iRun.getByLabel(lheProduct_,LHEAscii);
00077
00078 const std::vector<std::string>& lheOutputs = LHEAscii->getStrings();
00079
00080 size_t lastdot = lheFileName_.find_last_of(".");
00081 std::string basename = lheFileName_.substr(0, lastdot);
00082 std::string extension = lastdot != std::string::npos ? lheFileName_.substr(lastdot+1, std::string::npos) : "";
00083
00084 for (unsigned int i = 0; i < lheOutputs.size(); ++i){
00085 std::ofstream outfile;
00086 if (i == 0)
00087 outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
00088 else {
00089 std::stringstream fname;
00090 fname << basename << "_" << i ;
00091 if (extension != "")
00092 fname << "." << extension;
00093 outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
00094 }
00095 outfile << lheOutputs[i];
00096 outfile.close();
00097 }
00098
00099 }
00100
00101 void ExternalLHEAsciiDumper::endJob() {
00102 }
00103
00104 DEFINE_FWK_MODULE(ExternalLHEAsciiDumper);