Skip to content

Commit f734bad

Browse files
committed
Merge pull request #12685 from bendavid/lheheaderscript_53x
Add script to dump LHE header to file
2 parents 14dd186 + 4029595 commit f734bad

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

GeneratorInterface/LHEInterface/plugins/LHEWriter.cc

+13-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ class LHEWriter : public edm::EDAnalyzer {
2626
virtual void beginRun(const edm::Run &run, const edm::EventSetup &es);
2727
virtual void endRun(const edm::Run &run, const edm::EventSetup &es);
2828
virtual void analyze(const edm::Event &event, const edm::EventSetup &es);
29+
30+
std::string output;
2931

3032
private:
3133
std::ofstream file;
3234
};
3335

34-
LHEWriter::LHEWriter(const edm::ParameterSet &params)
36+
LHEWriter::LHEWriter(const edm::ParameterSet &params) :
37+
output(params.getUntrackedParameter<std::string>("output"))
3538
{
3639
}
3740

@@ -43,8 +46,12 @@ void LHEWriter::beginRun(const edm::Run &run, const edm::EventSetup &es)
4346
{
4447
edm::Handle<LHERunInfoProduct> product;
4548
run.getByLabel("source", product);
49+
50+
if (!product.isValid()) {
51+
run.getByLabel("externalLHEProducer", product);
52+
}
4653

47-
file.open("writer.lhe", std::fstream::out | std::fstream::trunc);
54+
file.open(output.c_str(), std::fstream::out | std::fstream::trunc);
4855
std::copy(product->begin(), product->end(),
4956
std::ostream_iterator<std::string>(file));
5057
}
@@ -59,6 +66,10 @@ void LHEWriter::analyze(const edm::Event &event, const edm::EventSetup &es)
5966
{
6067
edm::Handle<LHEEventProduct> product;
6168
event.getByLabel("source", product);
69+
70+
if (!product.isValid()) {
71+
event.getByLabel("externalLHEProducer", product);
72+
}
6273

6374
std::copy(product->begin(), product->end(),
6475
std::ostream_iterator<std::string>(file));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env cmsRun
2+
import FWCore.ParameterSet.Config as cms
3+
4+
from FWCore.ParameterSet.VarParsing import VarParsing
5+
6+
options = VarParsing ('analysis')
7+
8+
# add a list of strings for events to process
9+
options.register ('input',
10+
'',
11+
VarParsing.multiplicity.list,
12+
VarParsing.varType.string,
13+
"Input File")
14+
15+
options.register ('output',
16+
'writer.lhe',
17+
VarParsing.multiplicity.singleton,
18+
VarParsing.varType.string,
19+
"Output File")
20+
21+
options.parseArguments()
22+
23+
inFileName = cms.untracked.vstring (options.input)
24+
outFileName = cms.untracked.string (options.output)
25+
26+
process = cms.Process("Writer")
27+
28+
process.maxEvents = cms.untracked.PSet(input = cms.untracked.int32(-1))
29+
30+
process.source = cms.Source("PoolSource",
31+
processingMode = cms.untracked.string('Runs'),
32+
fileNames = cms.untracked.vstring(inFileName)
33+
)
34+
35+
process.load("FWCore.MessageService.MessageLogger_cfi")
36+
process.MessageLogger.cerr.threshold = 'INFO'
37+
38+
process.writer = cms.EDAnalyzer("LHEWriter",
39+
output=outFileName)
40+
41+
process.path = cms.Path(process.writer)
42+
43+
process.schedule = cms.Schedule(process.path)

GeneratorInterface/LHEInterface/test/testWriter_cfg.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
process.load("FWCore.MessageService.MessageLogger_cfi")
1313
process.MessageLogger.cerr.threshold = 'INFO'
1414

15-
process.writer = cms.EDAnalyzer("LHEWriter")
15+
process.writer = cms.EDAnalyzer("LHEWriter",
16+
outputFile='writer.lhe')
1617

1718
process.outpath = cms.EndPath(process.writer)

0 commit comments

Comments
 (0)