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  unsigned int iout = 0;
81 
82  size_t lastdot = lheFileName_.find_last_of(".");
83  std::string basename = lheFileName_.substr(0, lastdot);
84  std::string extension = lastdot != std::string::npos ? lheFileName_.substr(lastdot+1, std::string::npos) : "";
85 
86  for (unsigned int i = 0; i < lheOutputs.size(); ++i){
87  std::ofstream outfile;
88  if (iout == 0)
89  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
90  else {
91  std::stringstream fname;
92  fname << basename << "_" << iout ;
93  if (extension != "")
94  fname << "." << extension;
95  outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
96  }
97  outfile << lheOutputs[i];
98  outfile.close();
99  ++iout;
100  }
101 
102  for (unsigned int i = 0; i < LHEAscii->getCompressed().size(); ++i){
103  std::ofstream outfile;
104  if (iout == 0)
105  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
106  else {
107  std::stringstream fname;
108  fname << basename << "_" << iout ;
109  if (extension != "")
110  fname << "." << extension;
111  outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
112  }
113  LHEAscii->writeCompressedContent(outfile,i);
114  outfile.close();
115  ++iout;
116  }
117 
118 }
119 
121 }
122 
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