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 // system include files
6 #include <memory>
7 #include <string>
8 #include <sstream>
9 #include <fstream>
10 #include <boost/algorithm/string.hpp>
11 
12 // user include files
16 
22 
24 
26 
27 //
28 // class declaration
29 //
30 
32 public:
34  ~ExternalLHEAsciiDumper() override;
35 
36 private:
37  void analyze(const edm::Event&, const edm::EventSetup&) override;
38  void endRun(edm::Run const&, edm::EventSetup const&) override;
39 
42 
44 
45  // ----------member data ---------------------------
46 };
47 
49  : lheProduct_(ps.getParameter<edm::InputTag>("lheProduct")),
50  lheFileName_(ps.getParameter<std::string>("lheFileName")) {
51  LHEAsciiToken_ = consumes<LHEXMLStringProduct, edm::InRun>(edm::InputTag(lheProduct_));
52 
53  return;
54 }
55 
57 
59 
60 // ------------ method called once each job just after ending the event loop ------------
61 
64  iRun.getByToken(LHEAsciiToken_, LHEAscii);
65 
66  const std::vector<std::string>& lheOutputs = LHEAscii->getStrings();
67 
68  unsigned int iout = 0;
69 
70  size_t lastdot = lheFileName_.find_last_of(".");
71  std::string basename = lheFileName_.substr(0, lastdot);
72  std::string extension = lastdot != std::string::npos ? lheFileName_.substr(lastdot + 1, std::string::npos) : "";
73 
74  for (unsigned int i = 0; i < lheOutputs.size(); ++i) {
75  std::ofstream outfile;
76  if (iout == 0)
77  outfile.open(lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
78  else {
79  std::stringstream fname;
80  fname << basename << "_" << iout;
81  if (!extension.empty())
82  fname << "." << extension;
83  outfile.open(fname.str().c_str(), std::ofstream::out | std::ofstream::app);
84  }
85  outfile << lheOutputs[i];
86  outfile.close();
87  ++iout;
88  }
89 
90  for (unsigned int i = 0; i < LHEAscii->getCompressed().size(); ++i) {
91  std::ofstream outfile;
92  if (iout == 0)
93  outfile.open(lheFileName_.c_str(), std::ofstream::out | std::ofstream::app);
94  else {
95  std::stringstream fname;
96  fname << basename << "_" << iout;
97  if (!extension.empty())
98  fname << "." << extension;
99  outfile.open(fname.str().c_str(), std::ofstream::out | std::ofstream::app);
100  }
101  LHEAscii->writeCompressedContent(outfile, i);
102  outfile.close();
103  ++iout;
104  }
105 }
106 
ExternalLHEAsciiDumper::LHEAsciiToken_
edm::EDGetTokenT< LHEXMLStringProduct > LHEAsciiToken_
Definition: ExternalLHEAsciiDumper.cc:43
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
LHEXMLStringProduct::getCompressed
const std::vector< std::vector< uint8_t > > & getCompressed() const
Definition: LHEXMLStringProduct.h:22
edm::Run
Definition: Run.h:45
edm::EDGetTokenT< LHEXMLStringProduct >
edm
HLT enums.
Definition: AlignableModifier.h:19
ExternalLHEAsciiDumper
Definition: ExternalLHEAsciiDumper.cc:31
LHEXMLStringProduct::writeCompressedContent
void writeCompressedContent(std::ostream &output, unsigned int i) const
Definition: LHEXMLStringProduct.cc:84
edmStreamStallGrapher.extension
extension
Definition: edmStreamStallGrapher.py:893
EDAnalyzer.h
ExternalLHEAsciiDumper::~ExternalLHEAsciiDumper
~ExternalLHEAsciiDumper() override
Definition: ExternalLHEAsciiDumper.cc:56
edm::Handle
Definition: AssociativeIterator.h:50
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
MakerMacros.h
ExternalLHEAsciiDumper::lheFileName_
std::string lheFileName_
Definition: ExternalLHEAsciiDumper.cc:41
edm::Run::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Run.h:315
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ExternalLHEAsciiDumper::endRun
void endRun(edm::Run const &, edm::EventSetup const &) override
Definition: ExternalLHEAsciiDumper.cc:62
Run.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ExternalLHEAsciiDumper::lheProduct_
edm::InputTag lheProduct_
Definition: ExternalLHEAsciiDumper.cc:40
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
edm::ParameterSet
Definition: ParameterSet.h:36
LHEXMLStringProduct.h
Event.h
ExternalLHEAsciiDumper::ExternalLHEAsciiDumper
ExternalLHEAsciiDumper(const edm::ParameterSet &)
Definition: ExternalLHEAsciiDumper.cc:48
edm::EventSetup
Definition: EventSetup.h:57
InputTag.h
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
std
Definition: JetResolutionObject.h:76
ExternalLHEAsciiDumper::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ExternalLHEAsciiDumper.cc:58
Frameworkfwd.h
EventSetup.h
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
timingPdfMaker.outfile
outfile
Definition: timingPdfMaker.py:351
ParameterSet.h
edm::Event
Definition: Event.h:73
LHEXMLStringProduct::getStrings
const std::vector< std::string > & getStrings() const
Definition: LHEXMLStringProduct.h:20
edm::InputTag
Definition: InputTag.h:15