CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ExternalLHEAsciiDumper.cc
Go to the documentation of this file.
1 // F. Cossutti
2 // $Date: 2013/03/01 21:45:29 $
3 // $Revision: 1.4 $//
4 
5 // Dump in standard ascii format the LHE file stored as string lumi product
6 
7 
8 // system include files
9 #include <memory>
10 #include <string>
11 #include <sstream>
12 #include <fstream>
13 #include <boost/algorithm/string.hpp>
14 
15 // user include files
19 
25 
27 
29 
30 //
31 // class declaration
32 //
33 
35 public:
38 
39 
40 private:
41  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
42  virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
43 
46 
47  // ----------member data ---------------------------
48 
49 };
50 
52  lheProduct_( ps.getParameter<edm::InputTag>("lheProduct") ),
53  lheFileName_( ps.getParameter<std::string>("lheFileName") )
54 {
55 
56  return;
57 
58 }
59 
61 {
62 }
63 
64 void
66 {
67 }
68 
69 // ------------ method called once each job just after ending the event loop ------------
70 
71 void
73 
75  iRun.getByLabel(lheProduct_,LHEAscii);
76 
77  const std::vector<std::string>& lheOutputs = LHEAscii->getStrings();
78 
79  size_t lastdot = lheFileName_.find_last_of(".");
80  std::string basename = lheFileName_.substr(0, lastdot);
81  std::string extension = lastdot != std::string::npos ? lheFileName_.substr(lastdot+1, std::string::npos) : "";
82 
83  for (unsigned int i = 0; i < lheOutputs.size(); ++i){
84  std::ofstream outfile;
85  if (i == 0)
86  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
87  else {
88  std::stringstream fname;
89  fname << basename << "_" << i ;
90  if (extension != "")
91  fname << "." << extension;
92  outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
93  }
94  outfile << lheOutputs[i];
95  outfile.close();
96  }
97 
98 }
99 
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:176
int i
Definition: DBlmapReader.cc:9
ExternalLHEAsciiDumper(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
list outfile
Definition: EdgesToViz.py:91
tuple out
Definition: dbtoconf.py:99
string fname
main script
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:36