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  size_t lastdot = lheFileName_.find_last_of(".");
78  std::string basename = lheFileName_.substr(0, lastdot);
79  std::string extension = lastdot != std::string::npos ? lheFileName_.substr(lastdot+1, std::string::npos) : "";
80 
81  for (unsigned int i = 0; i < lheOutputs.size(); ++i){
82  std::ofstream outfile;
83  if (i == 0)
84  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
85  else {
86  std::stringstream fname;
87  fname << basename << "_" << i ;
88  if (extension != "")
89  fname << "." << extension;
90  outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
91  }
92  outfile << lheOutputs[i];
93  outfile.close();
94  }
95 
96 }
97 
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
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:41