diff --git a/GeneratorInterface/Core/interface/LHEWeightHelper.h b/GeneratorInterface/Core/interface/LHEWeightHelper.h index ef3371c4095d6..f29aaf5f2f7df 100644 --- a/GeneratorInterface/Core/interface/LHEWeightHelper.h +++ b/GeneratorInterface/Core/interface/LHEWeightHelper.h @@ -24,9 +24,10 @@ namespace gen { void parseWeights(); bool isConsistent(); void swapHeaders(); - + void setFailIfInvalidXML(bool value) { failIfInvalidXML_ = value; } private: std::vector headerLines_; + bool failIfInvalidXML_ = false; }; } // namespace gen diff --git a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc index 6b25ac35c4ae0..f06d68d5e81f4 100644 --- a/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc +++ b/GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc @@ -57,6 +57,7 @@ LHEWeightProductProducer::LHEWeightProductProducer(const edm::ParameterSet& iCon [this](const std::string& tag) { return mayConsume(tag); })) { produces(); produces(); + weightHelper_.setFailIfInvalidXML(iConfig.getUntrackedParameter("failIfInvalidXML", false)); } LHEWeightProductProducer::~LHEWeightProductProducer() {} diff --git a/GeneratorInterface/Core/src/LHEWeightHelper.cc b/GeneratorInterface/Core/src/LHEWeightHelper.cc index 5f51c6658e75c..00cd7b2ad6e6b 100644 --- a/GeneratorInterface/Core/src/LHEWeightHelper.cc +++ b/GeneratorInterface/Core/src/LHEWeightHelper.cc @@ -2,6 +2,7 @@ #include #include #include +#include using namespace tinyxml2; @@ -11,7 +12,11 @@ namespace gen { void LHEWeightHelper::parseWeights() { parsedWeights_.clear(); - if (!isConsistent()) { + if (!isConsistent() && failIfInvalidXML_) { + throw std::runtime_error( "XML in LHE is not consistent: Most likely, tags were swapped.\n" \ + "To turn on fault fixing, use 'setFailIfInvalidXML(false)'\n" \ + "WARNING: the tag swapping may lead to weights associated with the incorrect group"); + } else if (!isConsistent()) { swapHeaders(); } @@ -29,7 +34,10 @@ namespace gen { if (xmlError != 0) { std::cerr << "Error in lhe xml file" << std::endl; xmlDoc.PrintError(); - return; + if(failIfInvalidXML_) + throw std::runtime_error("XML is unreadable because of above error."); + else + return; } std::vector nameAlts_ = {"name", "type"}; diff --git a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py index 0c0925dc2e46e..cde648a77d08c 100644 --- a/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py +++ b/GeneratorInterface/Core/test/testGenWeightProducer_cfg.py @@ -26,8 +26,9 @@ 'keep GenWeightInfoProduct_test*Weights*_*_*',]) ) -#process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer", -# lheSourceLabel = cms.string("externalLHEProducer")) +# process.testLHEWeights = cms.EDProducer("LHEWeightProductProducer", +# lheSourceLabel = cms.string("externalLHEProducer"), +# failIfValidXML = cms.untracked.bool(True)) process.testGenWeights = cms.EDProducer("GenWeightProductProducer", genInfo = cms.InputTag("generator"), diff --git a/PhysicsTools/NanoAOD/python/nanogen_cff.py b/PhysicsTools/NanoAOD/python/nanogen_cff.py index ffd7a82c2b324..6e81ab1ce2023 100644 --- a/PhysicsTools/NanoAOD/python/nanogen_cff.py +++ b/PhysicsTools/NanoAOD/python/nanogen_cff.py @@ -11,7 +11,8 @@ genLumiInfoHeader = cms.InputTag("generator")) lheWeights = cms.EDProducer("LHEWeightProductProducer", - lheSourceLabels = cms.vstring(["externalLHEProducer", "source"]) + lheSourceLabels = cms.vstring(["externalLHEProducer", "source"]), + failIfInvalidXML = cms.untracked.bool(True) #lheWeightSourceLabels = cms.vstring(["externalLHEProducer", "source"]) )