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: 2012/10/26 12:19:48 $
3 // $Revision: 1.3 $//
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&);
42  virtual void endRun(edm::Run const&, edm::EventSetup const&);
43  virtual void endJob();
44 
46  std::string lheFileName_;
47 
48  // ----------member data ---------------------------
49 
50 };
51 
53  lheProduct_( ps.getParameter<edm::InputTag>("lheProduct") ),
54  lheFileName_( ps.getParameter<std::string>("lheFileName") )
55 {
56 
57  return;
58 
59 }
60 
62 {
63 }
64 
65 void
67 {
68 }
69 
70 // ------------ method called once each job just after ending the event loop ------------
71 
72 void
74 
76  iRun.getByLabel(lheProduct_,LHEAscii);
77 
78  const std::vector<std::string>& lheOutputs = LHEAscii->getStrings();
79 
80  size_t lastdot = lheFileName_.find_last_of(".");
81  std::string basename = lheFileName_.substr(0, lastdot);
82  std::string extension = lastdot != std::string::npos ? lheFileName_.substr(lastdot+1, std::string::npos) : "";
83 
84  for (unsigned int i = 0; i < lheOutputs.size(); ++i){
85  std::ofstream outfile;
86  if (i == 0)
87  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
88  else {
89  std::stringstream fname;
90  fname << basename << "_" << i ;
91  if (extension != "")
92  fname << "." << extension;
93  outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
94  }
95  outfile << lheOutputs[i];
96  outfile.close();
97  }
98 
99 }
100 
102 }
103 
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:177
int i
Definition: DBlmapReader.cc:9
virtual void endRun(edm::Run const &, edm::EventSetup const &)
ExternalLHEAsciiDumper(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
list outfile
Definition: EdgesToViz.py:91
virtual void analyze(const edm::Event &, const edm::EventSetup &)
tuple out
Definition: dbtoconf.py:99
string fname
main script
Definition: Run.h:33