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 
3 // Dump in standard ascii format the LHE file stored as string lumi product
4 
5 
6 // system include files
7 #include <memory>
8 #include <string>
9 #include <sstream>
10 #include <fstream>
11 #include <boost/algorithm/string.hpp>
12 
13 // user include files
17 
23 
25 
27 
28 //
29 // class declaration
30 //
31 
33 public:
36 
37 
38 private:
39  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
40  virtual void endRun(edm::Run const&, edm::EventSetup const&) override;
41 
44 
45  // ----------member data ---------------------------
46 
47 };
48 
50  lheProduct_( ps.getParameter<edm::InputTag>("lheProduct") ),
51  lheFileName_( ps.getParameter<std::string>("lheFileName") )
52 {
53 
54  return;
55 
56 }
57 
59 {
60 }
61 
62 void
64 {
65 }
66 
67 // ------------ method called once each job just after ending the event loop ------------
68 
69 void
71 
73  iRun.getByLabel(lheProduct_,LHEAscii);
74 
75  const std::vector<std::string>& lheOutputs = LHEAscii->getStrings();
76 
77  unsigned int iout = 0;
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 (iout == 0)
86  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
87  else {
88  std::stringstream fname;
89  fname << basename << "_" << iout ;
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  ++iout;
97  }
98 
99  for (unsigned int i = 0; i < LHEAscii->getCompressed().size(); ++i){
100  std::ofstream outfile;
101  if (iout == 0)
102  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
103  else {
104  std::stringstream fname;
105  fname << basename << "_" << iout ;
106  if (extension != "")
107  fname << "." << extension;
108  outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
109  }
110  LHEAscii->writeCompressedContent(outfile,i);
111  outfile.close();
112  ++iout;
113  }
114 
115 }
116 
bool getByLabel(std::string const &label, Handle< PROD > &result) const
Definition: Run.h:200
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
tuple out
Definition: dbtoconf.py:99
string fname
main script
virtual void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:41