Skip to content

Commit

Permalink
Use cms::Exception, more detailed error reporting
Browse files Browse the repository at this point in the history
catch cms::Exception, not std::exception
  • Loading branch information
kdlong committed Nov 3, 2020
1 parent 58340d5 commit f381ae8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
11 changes: 10 additions & 1 deletion GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,16 @@ void LHEWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock&
if (!hasLhe_)
return;

weightHelper_.parseWeights();
try {
weightHelper_.parseWeights();
} catch (cms::Exception& e) {
std::string error = e.what();
error += "\n NOTE: if you want to attempt to process this sample anyway, set failIfInvalidXML = False "
"in the configuration file\n. If you set this flag and the error persists, the issue "
" is fatal and must be solved at the LHE/gridpack level.";
throw cms::Exception("LHEWeightProductProducer") << error;
}

if (weightHelper_.weightGroups().size() == 0)
weightHelper_.addUnassociatedGroup();

Expand Down
15 changes: 7 additions & 8 deletions GeneratorInterface/Core/src/LHEWeightHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ namespace gen {
parsedWeights_.clear();

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");
throw cms::Exception("LHEWeightHelper") <<
"XML in LHE is not consistent: Most likely, XML tags are out of order.";
} else if (!isConsistent()) {
swapHeaders();
}
Expand All @@ -29,7 +27,8 @@ namespace gen {
// in case of &gt; instead of <
if (xmlError != 0 && failIfInvalidXML_) {
xmlDoc.PrintError();
throw std::runtime_error("XML is unreadable because of above error.");
throw cms::Exception("LHEWeightHelper")
<< "The LHE header is not valid XML! Weight information was not properly parsed.";
} else if (xmlError != 0 && !failIfInvalidXML_) {
boost::replace_all(fullHeader, "&lt;", "<");
boost::replace_all(fullHeader, "&gt;", ">");
Expand All @@ -38,9 +37,9 @@ namespace gen {

// error persists (how to handle error?)
if (xmlError != 0) {
std::cerr << "WARNING: Error in parsing XML of LHE weight header!" << std::endl;
xmlDoc.PrintError();
return false;
std::string error = "Fatal error when parsing the LHE header. The header is not valid XML! Parsing error was ";
error += xmlDoc.ErrorStr();
throw cms::Exception("LHEWeightHelper") << error;
}

return true;
Expand Down

0 comments on commit f381ae8

Please sign in to comment.