Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of #22935 to 93X (Add a flag to prevent storage of LHEXMLStringProduct) #22947

Merged
merged 1 commit into from Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,6 +42,8 @@ class ExternalLHEAsciiDumper : public edm::EDAnalyzer {
edm::InputTag lheProduct_;
std::string lheFileName_;

edm::EDGetTokenT<LHEXMLStringProduct> LHEAsciiToken_;

// ----------member data ---------------------------

};
Expand All @@ -50,6 +52,8 @@ ExternalLHEAsciiDumper::ExternalLHEAsciiDumper(const edm::ParameterSet& ps):
lheProduct_( ps.getParameter<edm::InputTag>("lheProduct") ),
lheFileName_( ps.getParameter<std::string>("lheFileName") )
{

LHEAsciiToken_ = consumes <LHEXMLStringProduct,edm::InRun> (edm::InputTag(lheProduct_));

return;

Expand All @@ -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<std::string>& lheOutputs = LHEAscii->getStrings();

Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
27 changes: 17 additions & 10 deletions GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc
Expand Up @@ -93,6 +93,7 @@ class ExternalLHEProducer : public edm::one::EDProducer<edm::BeginRunProducer,
std::vector<std::string> args_;
uint32_t npars_;
uint32_t nEvents_;
bool storeXML_;
unsigned int nThreads_{1};
std::string outputContents_;

Expand Down Expand Up @@ -133,7 +134,8 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig) :
outputFile_(iConfig.getParameter<std::string>("outputFile")),
args_(iConfig.getParameter<std::vector<std::string> >("args")),
npars_(iConfig.getParameter<uint32_t>("numberOfParameters")),
nEvents_(iConfig.getUntrackedParameter<uint32_t>("nEvents"))
nEvents_(iConfig.getUntrackedParameter<uint32_t>("nEvents")),
storeXML_(iConfig.getUntrackedParameter<bool>("storeXML"))
{
if (npars_ != args_.size())
throw cms::Exception("ExternalLHEProducer") << "Problem with configuration: " << args_.size() << " script arguments given, expected " << npars_;
Expand Down Expand Up @@ -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<LHEXMLStringProduct> 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
Expand Down Expand Up @@ -499,6 +505,7 @@ ExternalLHEProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptio
desc.add<std::vector<std::string> >("args");
desc.add<uint32_t>("numberOfParameters");
desc.addUntracked<uint32_t>("nEvents");
desc.addUntracked<bool>("storeXML", false);

descriptions.addDefault(desc);
}
Expand Down
Expand Up @@ -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)
)