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::EDAnalyzer {
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>(params.getUntrackedParameter<edm::InputTag>("moduleLabel", std::string("source")) ) ),
41 tokenLHEEvent_(consumes<LHEEventProduct>(params.getUntrackedParameter<edm::InputTag>("moduleLabel", std::string("source")) ) )
42 {
43 }
44 
46 {
47 }
48 
50 {
51  file.open("writer.lhe", std::fstream::out | std::fstream::trunc);
52  file1.open("writer1.lhe", std::fstream::out | std::fstream::trunc);
53 }
54 
56 {
58  //run.getByLabel("source", product);
59  run.getByToken(tokenLHERunInfo_, product);
60 
61  std::copy(product->begin(), product->end(),
62  std::ostream_iterator<std::string>(file));
63 
65  file.close();
66  file1.close();
67 
68  system("cat writer1.lhe >> writer.lhe");
69  system("rm -rf writer1.lhe");
70 }
71 
73 {
75  //event.getByLabel("source", product);
76  event.getByToken(tokenLHEEvent_, product);
77 
78  std::copy(product->begin(), product->end(),
79  std::ostream_iterator<std::string>(file1));
80 }
81 
edm::EDGetTokenT< LHEEventProduct > tokenLHEEvent_
Definition: LHEWriter.cc:36
const_iterator begin() const
const_iterator end() const
~LHEWriter() override
Definition: LHEWriter.cc:45
def copy(args, dbName)
virtual example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
std::ofstream file
Definition: LHEWriter.cc:32
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void endRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: LHEWriter.cc:55
std::ofstream file1
Definition: LHEWriter.cc:33
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:342
void beginRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: LHEWriter.cc:49
void analyze(const edm::Event &event, const edm::EventSetup &es) override
Definition: LHEWriter.cc:72
LHEWriter(const edm::ParameterSet &params)
Definition: LHEWriter.cc:39
edm::EDGetTokenT< LHERunInfoProduct > tokenLHERunInfo_
Definition: LHEWriter.cc:35
HLT enums.
static const std::string & endOfFile()
const_iterator end() const
Definition: event.py:1
Definition: Run.h:44
const_iterator begin() const