CMS 3D CMS Logo

LHEWriter.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iostream>
3 #include <iterator>
4 #include <fstream>
5 #include <string>
6 #include <memory>
7 
15 
18 
19 using namespace lhef;
20 
21 class LHEWriter : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
22 public:
23  explicit LHEWriter(const edm::ParameterSet &params);
24  ~LHEWriter() override;
25 
26 protected:
27  void beginRun(const edm::Run &run, const edm::EventSetup &es) override;
28  void endRun(const edm::Run &run, const edm::EventSetup &es) override;
29  void analyze(const edm::Event &event, const edm::EventSetup &es) override;
30 
31 private:
32  std::ofstream file;
33  std::ofstream file1;
34 
37 };
38 
40  : tokenLHERunInfo_(consumes<LHERunInfoProduct, edm::InRun>(
41  params.getUntrackedParameter<edm::InputTag>("moduleLabel", std::string("source")))),
42  tokenLHEEvent_(consumes<LHEEventProduct>(
43  params.getUntrackedParameter<edm::InputTag>("moduleLabel", std::string("source")))) {}
44 
46 
48  file.open("writer.lhe", std::fstream::out | std::fstream::trunc);
49  file1.open("writer1.lhe", std::fstream::out | std::fstream::trunc);
50 }
51 
52 void LHEWriter::endRun(const edm::Run &run, const edm::EventSetup &es) {
53  const edm::Handle<LHERunInfoProduct> &product = run.getHandle(tokenLHERunInfo_);
54  //run.getByLabel("source", product);
55  //run.getByToken(tokenLHERunInfo_, product);
56 
57  std::copy(product->begin(), product->end(), std::ostream_iterator<std::string>(file));
58 
60  file.close();
61  file1.close();
62 
63  system("cat writer1.lhe >> writer.lhe");
64  system("rm -rf writer1.lhe");
65 }
66 
68  const edm::Handle<LHEEventProduct> &product = event.getHandle(tokenLHEEvent_);
69  //event.getByLabel("source", product);
70  //event.getByToken(tokenLHEEvent_, product);
71 
72  std::copy(product->begin(), product->end(), std::ostream_iterator<std::string>(file1));
73 }
74 
edm::EDGetTokenT< LHEEventProduct > tokenLHEEvent_
Definition: LHEWriter.cc:36
~LHEWriter() override
Definition: LHEWriter.cc:45
const_iterator end() const
std::ofstream file
Definition: LHEWriter.cc:32
const_iterator begin() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void endRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: LHEWriter.cc:52
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
std::ofstream file1
Definition: LHEWriter.cc:33
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: LHEWriter.cc:47
void analyze(const edm::Event &event, const edm::EventSetup &es) override
Definition: LHEWriter.cc:67
LHEWriter(const edm::ParameterSet &params)
Definition: LHEWriter.cc:39
edm::EDGetTokenT< LHERunInfoProduct > tokenLHERunInfo_
Definition: LHEWriter.cc:35
HLT enums.
const_iterator begin() const
static const std::string & endOfFile()
const_iterator end() const
Definition: event.py:1
Definition: Run.h:45