CMS 3D CMS Logo

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:
35  ~ExternalLHEAsciiDumper() override;
36 
37 
38 private:
39  void analyze(const edm::Event&, const edm::EventSetup&) override;
40  void endRun(edm::Run const&, edm::EventSetup const&) override;
41 
44 
46 
47  // ----------member data ---------------------------
48 
49 };
50 
52  lheProduct_( ps.getParameter<edm::InputTag>("lheProduct") ),
53  lheFileName_( ps.getParameter<std::string>("lheFileName") )
54 {
55 
56  LHEAsciiToken_ = consumes <LHEXMLStringProduct,edm::InRun> (edm::InputTag(lheProduct_));
57 
58  return;
59 
60 }
61 
63 {
64 }
65 
66 void
68 {
69 }
70 
71 // ------------ method called once each job just after ending the event loop ------------
72 
73 void
75 
77  iRun.getByToken(LHEAsciiToken_,LHEAscii);
78 
79  const std::vector<std::string>& lheOutputs = LHEAscii->getStrings();
80 
81  unsigned int iout = 0;
82 
83  size_t lastdot = lheFileName_.find_last_of(".");
84  std::string basename = lheFileName_.substr(0, lastdot);
85  std::string extension = lastdot != std::string::npos ? lheFileName_.substr(lastdot+1, std::string::npos) : "";
86 
87  for (unsigned int i = 0; i < lheOutputs.size(); ++i){
88  std::ofstream outfile;
89  if (iout == 0)
90  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
91  else {
92  std::stringstream fname;
93  fname << basename << "_" << iout ;
94  if (!extension.empty())
95  fname << "." << extension;
96  outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
97  }
98  outfile << lheOutputs[i];
99  outfile.close();
100  ++iout;
101  }
102 
103  for (unsigned int i = 0; i < LHEAscii->getCompressed().size(); ++i){
104  std::ofstream outfile;
105  if (iout == 0)
106  outfile.open (lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
107  else {
108  std::stringstream fname;
109  fname << basename << "_" << iout ;
110  if (!extension.empty())
111  fname << "." << extension;
112  outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app);
113  }
114  LHEAscii->writeCompressedContent(outfile,i);
115  outfile.close();
116  ++iout;
117  }
118 
119 }
120 
ExternalLHEAsciiDumper(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void analyze(const edm::Event &, const edm::EventSetup &) override
const std::vector< std::string > & getStrings() const
const std::vector< std::vector< uint8_t > > & getCompressed() const
edm::EDGetTokenT< LHEXMLStringProduct > LHEAsciiToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:342
string fname
main script
HLT enums.
void writeCompressedContent(std::ostream &output, unsigned int i) const
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: Run.h:44