From a1cbbc7a9175d662d9830157938dbb33f15dc7ec Mon Sep 17 00:00:00 2001 From: Fabio Cossutti Date: Thu, 12 Apr 2018 17:39:48 +0200 Subject: [PATCH] Backport of #22935 to 93X --- .../plugins/ExternalLHEAsciiDumper.cc | 10 ++++--- .../plugins/ExternalLHEProducer.cc | 27 ++++++++++++------- .../python/ExternalLHEProducer_cfi.py | 3 ++- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc index 4aa56cddf382c..be486d25eeff5 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc @@ -42,6 +42,8 @@ class ExternalLHEAsciiDumper : public edm::EDAnalyzer { edm::InputTag lheProduct_; std::string lheFileName_; + edm::EDGetTokenT LHEAsciiToken_; + // ----------member data --------------------------- }; @@ -50,6 +52,8 @@ ExternalLHEAsciiDumper::ExternalLHEAsciiDumper(const edm::ParameterSet& ps): lheProduct_( ps.getParameter("lheProduct") ), lheFileName_( ps.getParameter("lheFileName") ) { + + LHEAsciiToken_ = consumes (edm::InputTag(lheProduct_)); return; @@ -70,7 +74,7 @@ void ExternalLHEAsciiDumper::endRun(edm::Run const& iRun, edm::EventSetup const&) { edm::Handle< LHEXMLStringProduct > LHEAscii; - iRun.getByLabel(lheProduct_,LHEAscii); + iRun.getByToken(LHEAsciiToken_,LHEAscii); const std::vector& lheOutputs = LHEAscii->getStrings(); @@ -87,7 +91,7 @@ ExternalLHEAsciiDumper::endRun(edm::Run const& iRun, edm::EventSetup const&) { else { std::stringstream fname; fname << basename << "_" << iout ; - if (extension != "") + if (!extension.empty()) fname << "." << extension; outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app); } @@ -103,7 +107,7 @@ ExternalLHEAsciiDumper::endRun(edm::Run const& iRun, edm::EventSetup const&) { else { std::stringstream fname; fname << basename << "_" << iout ; - if (extension != "") + if (!extension.empty()) fname << "." << extension; outfile.open (fname.str().c_str(), std::ofstream::out | std::ofstream::app); } diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index 2f18416c533bf..98dd211e1f7e5 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc @@ -93,6 +93,7 @@ class ExternalLHEProducer : public edm::one::EDProducer args_; uint32_t npars_; uint32_t nEvents_; + bool storeXML_; unsigned int nThreads_{1}; std::string outputContents_; @@ -133,7 +134,8 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig) : outputFile_(iConfig.getParameter("outputFile")), args_(iConfig.getParameter >("args")), npars_(iConfig.getParameter("numberOfParameters")), - nEvents_(iConfig.getUntrackedParameter("nEvents")) + nEvents_(iConfig.getUntrackedParameter("nEvents")), + storeXML_(iConfig.getUntrackedParameter("storeXML")) { if (npars_ != args_.size()) throw cms::Exception("ExternalLHEProducer") << "Problem with configuration: " << args_.size() << " script arguments given, expected " << npars_; @@ -256,17 +258,21 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) executeScript(); + //fill LHEXMLProduct (streaming read directly into compressed buffer to save memory) std::unique_ptr p(new LHEXMLStringProduct); - std::ifstream instream(outputFile_); - if (!instream) { - throw cms::Exception("OutputOpenError") << "Unable to open script output file " << outputFile_ << "."; - } - instream.seekg (0, instream.end); - int insize = instream.tellg(); - instream.seekg (0, instream.beg); - p->fillCompressedContent(instream, 0.25*insize); - instream.close(); + + //store the XML file only if explictly requested + if (storeXML_) { std::ifstream instream(outputFile_); + if (!instream) { + throw cms::Exception("OutputOpenError") << "Unable to open script output file " << outputFile_ << "."; + } + instream.seekg (0, instream.end); + int insize = instream.tellg(); + instream.seekg (0, instream.beg); + p->fillCompressedContent(instream, 0.25*insize); + instream.close(); + } run.put(std::move(p), "LHEScriptOutput"); // LHE C++ classes translation @@ -499,6 +505,7 @@ ExternalLHEProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptio desc.add >("args"); desc.add("numberOfParameters"); desc.addUntracked("nEvents"); + desc.addUntracked("storeXML", false); descriptions.addDefault(desc); } diff --git a/GeneratorInterface/LHEInterface/python/ExternalLHEProducer_cfi.py b/GeneratorInterface/LHEInterface/python/ExternalLHEProducer_cfi.py index 59e4a9259898b..cbc8824b306f2 100644 --- a/GeneratorInterface/LHEInterface/python/ExternalLHEProducer_cfi.py +++ b/GeneratorInterface/LHEInterface/python/ExternalLHEProducer_cfi.py @@ -5,6 +5,7 @@ outputFile = cms.string("W1Jet_7TeV_madgraph_final.lhe"), numberOfParameters = cms.uint32(10), args = cms.vstring('slc5_ia32_gcc434/madgraph/V5_1.3.27/test','W1Jet_7TeV_madgraph','false','true','wjets','5','20','false','0','99'), - nEvents = cms.untracked.uint32(100) + nEvents = cms.untracked.uint32(100), + storeXML = cms.untracked.bool(False) )