From 7951b4a43576f3997b273a73f7a58dbd48e67978 Mon Sep 17 00:00:00 2001 From: Fabio Cossutti Date: Wed, 11 Apr 2018 17:05:14 +0200 Subject: [PATCH 1/2] Add a flag to prevent storage of LHEXMLStringProduct, update the dumper which is no more working --- .../plugins/ExternalLHEAsciiDumper.cc | 6 ++++- .../plugins/ExternalLHEProducer.cc | 27 ++++++++++++------- .../python/ExternalLHEProducer_cfi.py | 3 ++- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc index d6023990db5e1..50a2b68f4f43e 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 --------------------------- }; @@ -51,6 +53,8 @@ ExternalLHEAsciiDumper::ExternalLHEAsciiDumper(const edm::ParameterSet& ps): 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(); diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc index d9291aa1fbcb0..08cc57b926cd0 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_; @@ -258,15 +260,19 @@ ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const& es) //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..2abd6225f4775 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) ) From 1b9b2b858a243846bf405d71170b5cf0dc5b5692 Mon Sep 17 00:00:00 2001 From: Fabio Cossutti Date: Wed, 11 Apr 2018 17:18:49 +0200 Subject: [PATCH 2/2] Fix code style according to scram suggestion --- .../LHEInterface/plugins/ExternalLHEAsciiDumper.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc b/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc index 50a2b68f4f43e..554744386b1a9 100644 --- a/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc +++ b/GeneratorInterface/LHEInterface/plugins/ExternalLHEAsciiDumper.cc @@ -91,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); } @@ -107,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); }