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  virtual ~LHEWriter();
25 
26  protected:
27  virtual void beginRun(const edm::Run &run, const edm::EventSetup &es) override;
28  virtual void endRun(const edm::Run &run, const edm::EventSetup &es) override;
29  virtual 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
std::ofstream file
Definition: LHEWriter.cc:32
def analyze(function, filename, filter=None)
Definition: Profiling.py:11
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
virtual 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:287
virtual void beginRun(const edm::Run &run, const edm::EventSetup &es) override
Definition: LHEWriter.cc:49
virtual void analyze(const edm::Event &event, const edm::EventSetup &es) override
Definition: LHEWriter.cc:72
LHEWriter(const edm::ParameterSet &params)
Definition: LHEWriter.cc:39
virtual ~LHEWriter()
Definition: LHEWriter.cc:45
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:43
const_iterator begin() const