GeneratorInterface
LHEInterface
plugins
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
11
// user include files
12
#include "
FWCore/Framework/interface/Frameworkfwd.h
"
13
#include "
FWCore/Framework/interface/EDAnalyzer.h
"
14
#include "
FWCore/MessageLogger/interface/MessageLogger.h
"
15
16
#include "
FWCore/Framework/interface/Event.h
"
17
#include "
FWCore/Framework/interface/MakerMacros.h
"
18
#include "
FWCore/Framework/interface/EventSetup.h
"
19
#include "
FWCore/ParameterSet/interface/ParameterSet.h
"
20
#include "
FWCore/Framework/interface/Run.h
"
21
22
#include "
SimDataFormats/GeneratorProducts/interface/LHEXMLStringProduct.h
"
23
24
#include "
FWCore/Utilities/interface/InputTag.h
"
25
26
//
27
// class declaration
28
//
29
30
class
ExternalLHEAsciiDumper
:
public
edm::EDAnalyzer
{
31
public
:
32
explicit
ExternalLHEAsciiDumper
(
const
edm::ParameterSet
&);
33
~ExternalLHEAsciiDumper
()
override
;
34
35
private
:
36
void
analyze
(
const
edm::Event
&,
const
edm::EventSetup
&)
override
;
37
void
endRun
(
edm::Run
const
&,
edm::EventSetup
const
&)
override
;
38
39
edm::InputTag
lheProduct_
;
40
std::string
lheFileName_
;
41
42
edm::EDGetTokenT<LHEXMLStringProduct>
LHEAsciiToken_
;
43
44
// ----------member data ---------------------------
45
};
46
47
ExternalLHEAsciiDumper::ExternalLHEAsciiDumper
(
const
edm::ParameterSet
& ps)
48
: lheProduct_(ps.getParameter<
edm
::
InputTag
>(
"lheProduct"
)),
49
lheFileName_(ps.getParameter<
std
::
string
>(
"lheFileName"
)) {
50
LHEAsciiToken_
= consumes<LHEXMLStringProduct, edm::InRun>(
edm::InputTag
(
lheProduct_
));
51
52
return
;
53
}
54
55
ExternalLHEAsciiDumper::~ExternalLHEAsciiDumper
() {}
56
57
void
ExternalLHEAsciiDumper::analyze
(
const
edm::Event
&,
const
edm::EventSetup
&) {}
58
59
// ------------ method called once each job just after ending the event loop ------------
60
61
void
ExternalLHEAsciiDumper::endRun
(
edm::Run
const
& iRun,
edm::EventSetup
const
&) {
62
edm::Handle<LHEXMLStringProduct>
LHEAscii;
63
iRun.
getByToken
(
LHEAsciiToken_
, LHEAscii);
64
65
const
std::vector<std::string>& lheOutputs = LHEAscii->
getStrings
();
66
67
unsigned
int
iout = 0;
68
69
size_t
lastdot =
lheFileName_
.find_last_of(
'.'
);
70
std::string
basename =
lheFileName_
.substr(0, lastdot);
71
std::string
extension
= lastdot != std::string::npos ?
lheFileName_
.substr(lastdot + 1, std::string::npos) :
""
;
72
73
for
(
unsigned
int
i
= 0;
i
< lheOutputs.size(); ++
i
) {
74
std::ofstream
outfile
;
75
if
(iout == 0)
76
outfile
.open(
lheFileName_
.c_str(),
std::ofstream::out
| std::ofstream::app);
77
else
{
78
std::stringstream
fname
;
79
fname
<< basename <<
"_"
<< iout;
80
if
(!
extension
.empty())
81
fname
<<
"."
<<
extension
;
82
outfile
.open(
fname
.str().c_str(),
std::ofstream::out
| std::ofstream::app);
83
}
84
outfile
<< lheOutputs[
i
];
85
outfile
.close();
86
++iout;
87
}
88
89
for
(
unsigned
int
i
= 0;
i
< LHEAscii->
getCompressed
().size(); ++
i
) {
90
std::ofstream
outfile
;
91
if
(iout == 0)
92
outfile
.open(
lheFileName_
.c_str(),
std::ofstream::out
| std::ofstream::app);
93
else
{
94
std::stringstream
fname
;
95
fname
<< basename <<
"_"
<< iout;
96
if
(!
extension
.empty())
97
fname
<<
"."
<<
extension
;
98
outfile
.open(
fname
.str().c_str(),
std::ofstream::out
| std::ofstream::app);
99
}
100
LHEAscii->
writeCompressedContent
(
outfile
,
i
);
101
outfile
.close();
102
++iout;
103
}
104
}
105
106
DEFINE_FWK_MODULE
(
ExternalLHEAsciiDumper
);
ExternalLHEAsciiDumper::LHEAsciiToken_
edm::EDGetTokenT< LHEXMLStringProduct > LHEAsciiToken_
Definition:
ExternalLHEAsciiDumper.cc:42
mps_fire.i
i
Definition:
mps_fire.py:428
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:30
HLT_FULL_cff.InputTag
InputTag
Definition:
HLT_FULL_cff.py:85964
LHEXMLStringProduct::writeCompressedContent
void writeCompressedContent(std::ostream &output, unsigned int i) const
Definition:
LHEXMLStringProduct.cc:84
EDAnalyzer.h
ExternalLHEAsciiDumper::~ExternalLHEAsciiDumper
~ExternalLHEAsciiDumper() override
Definition:
ExternalLHEAsciiDumper.cc:55
edm::Handle
Definition:
AssociativeIterator.h:50
edm::EDAnalyzer
Definition:
EDAnalyzer.h:28
MakerMacros.h
ExternalLHEAsciiDumper::lheFileName_
std::string lheFileName_
Definition:
ExternalLHEAsciiDumper.cc:40
edm::Run::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition:
Run.h:316
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:61
Run.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition:
AlCaHLTBitMon_QueryRunRegistry.py:256
ExternalLHEAsciiDumper::lheProduct_
edm::InputTag lheProduct_
Definition:
ExternalLHEAsciiDumper.cc:39
edm::ParameterSet
Definition:
ParameterSet.h:47
LHEXMLStringProduct.h
Event.h
ExternalLHEAsciiDumper::ExternalLHEAsciiDumper
ExternalLHEAsciiDumper(const edm::ParameterSet &)
Definition:
ExternalLHEAsciiDumper.cc:47
edm::EventSetup
Definition:
EventSetup.h:57
runGCPTkAlMap.extension
extension
Definition:
runGCPTkAlMap.py:188
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:57
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
Generated for CMSSW Reference Manual by
1.8.16