Skip to content

Commit

Permalink
resolve code check and format issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sroychow committed Nov 5, 2020
1 parent 4719048 commit 76b867c
Show file tree
Hide file tree
Showing 22 changed files with 440 additions and 453 deletions.
1 change: 1 addition & 0 deletions GeneratorInterface/Core/interface/LHEWeightHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace gen {
bool isConsistent();
void swapHeaders();
void setFailIfInvalidXML(bool value) { failIfInvalidXML_ = value; }

private:
std::vector<std::string> headerLines_;
bool failIfInvalidXML_ = false;
Expand Down
8 changes: 4 additions & 4 deletions GeneratorInterface/Core/plugins/GenWeightProductProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void GenWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup
edm::Handle<GenEventInfoProduct> genEventInfo;
iEvent.getByToken(genEventToken_, genEventInfo);

float centralWeight = genEventInfo->weights().size() > 0 ? genEventInfo->weights().at(0) : 1.;
float centralWeight = !genEventInfo->weights().empty() ? genEventInfo->weights().at(0) : 1.;
auto weightProduct = weightHelper_.weightProduct(genEventInfo->weights(), centralWeight);
iEvent.put(std::move(weightProduct));
}
Expand All @@ -82,9 +82,9 @@ void GenWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock&
weightHelper_.parseWeightGroupsFromNames(weightNames_);

auto weightInfoProduct = std::make_unique<GenWeightInfoProduct>();
if (weightHelper_.weightGroups().size() == 0)
weightHelper_.addUnassociatedGroup();
if (weightHelper_.weightGroups().empty())
weightHelper_.addUnassociatedGroup();

for (auto& weightGroup : weightHelper_.weightGroups()) {
weightInfoProduct->addWeightGroupInfo(std::make_unique<gen::WeightGroupInfo>(*weightGroup.clone()));
}
Expand Down
38 changes: 19 additions & 19 deletions GeneratorInterface/Core/plugins/LHEWeightProductProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class LHEWeightProductProducer : public edm::one::EDProducer<edm::BeginLuminosit
// TODO: Accept a vector of strings (source, externalLHEProducer) exit if neither are found
LHEWeightProductProducer::LHEWeightProductProducer(const edm::ParameterSet& iConfig)
: lheLabels_(iConfig.getParameter<std::vector<std::string>>("lheSourceLabels")),
lheEventTokens_(edm::vector_transform(lheLabels_,
[this](const std::string& tag) { return mayConsume<LHEEventProduct>(tag); })),
lheRunInfoTokens_(edm::vector_transform(lheLabels_,
[this](const std::string& tag) { return mayConsume<LHERunInfoProduct, edm::InRun>(tag); })),
lheWeightInfoTokens_(edm::vector_transform(lheLabels_,
[this](const std::string& tag) { return mayConsume<GenWeightInfoProduct, edm::InLumi>(tag); })) {
lheEventTokens_(edm::vector_transform(
lheLabels_, [this](const std::string& tag) { return mayConsume<LHEEventProduct>(tag); })),
lheRunInfoTokens_(edm::vector_transform(
lheLabels_, [this](const std::string& tag) { return mayConsume<LHERunInfoProduct, edm::InRun>(tag); })),
lheWeightInfoTokens_(edm::vector_transform(
lheLabels_, [this](const std::string& tag) { return mayConsume<GenWeightInfoProduct, edm::InLumi>(tag); })) {
produces<GenWeightProduct>();
produces<GenWeightInfoProduct, edm::Transition::BeginLuminosityBlock>();
weightHelper_.setFailIfInvalidXML(iConfig.getUntrackedParameter<bool>("failIfInvalidXML", false));
Expand All @@ -72,7 +72,7 @@ void LHEWeightProductProducer::produce(edm::Event& iEvent, const edm::EventSetup
for (auto& token : lheEventTokens_) {
iEvent.getByToken(token, lheEventInfo);
if (lheEventInfo.isValid()) {
break;
break;
}
}

Expand All @@ -85,13 +85,12 @@ void LHEWeightProductProducer::beginRun(edm::Run const& run, edm::EventSetup con
for (auto& label : lheLabels_) {
run.getByLabel(label, lheRunInfoHandle);
if (lheRunInfoHandle.isValid()) {
hasLhe_ = true;
break;
hasLhe_ = true;
break;
}
}
if (!hasLhe_)
return;

return;

typedef std::vector<LHERunInfoProduct::Header>::const_iterator header_cit;
LHERunInfoProduct::Header headerWeightInfo;
Expand Down Expand Up @@ -119,20 +118,21 @@ void LHEWeightProductProducer::beginLuminosityBlockProduce(edm::LuminosityBlock&
}

if (!hasLhe_)
return;
return;

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;
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();
if (weightHelper_.weightGroups().empty())
weightHelper_.addUnassociatedGroup();

auto weightInfoProduct = std::make_unique<GenWeightInfoProduct>();
for (auto& weightGroup : weightHelper_.weightGroups()) {
Expand Down
2 changes: 1 addition & 1 deletion GeneratorInterface/Core/src/GenWeightHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace gen {
{"", index, weightName, weightName, std::unordered_map<std::string, std::string>(), groupIndex});
if (isPartonShowerWeightGroup(parsedWeights_.back())) {
if (showerGroupIndex < 0) {
showerGroupIndex = ++groupIndex;
showerGroupIndex = ++groupIndex;
}
parsedWeights_.back().wgtGroup_idx = showerGroupIndex; // all parton showers are grouped together
}
Expand Down
14 changes: 7 additions & 7 deletions GeneratorInterface/Core/src/LHEWeightHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace gen {
parsedWeights_.clear();

if (!isConsistent() && failIfInvalidXML_) {
throw cms::Exception("LHEWeightHelper") <<
"XML in LHE is not consistent: Most likely, XML tags are out of order.";
throw cms::Exception("LHEWeightHelper")
<< "XML in LHE is not consistent: Most likely, XML tags are out of order.";
} else if (!isConsistent()) {
swapHeaders();
}
Expand All @@ -27,7 +27,7 @@ namespace gen {
// in case of &gt; instead of <
if (xmlError != 0 && failIfInvalidXML_) {
xmlDoc.PrintError();
throw cms::Exception("LHEWeightHelper")
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;", "<");
Expand Down Expand Up @@ -93,11 +93,11 @@ namespace gen {

std::string LHEWeightHelper::parseGroupName(tinyxml2::XMLElement* el) {
std::vector<std::string> nameAlts_ = {"name", "type"};
for (auto nameAtt : nameAlts_) {
for (const auto& nameAtt : nameAlts_) {
if (el->Attribute(nameAtt.c_str())) {
std::string groupName = el->Attribute(nameAtt.c_str());
if (groupName.find(".") != std::string::npos)
groupName.erase(groupName.find("."), groupName.size());
if (groupName.find('.') != std::string::npos)
groupName.erase(groupName.find('.'), groupName.size());
return groupName;
}
}
Expand All @@ -111,7 +111,7 @@ namespace gen {
bool LHEWeightHelper::isConsistent() {
int curLevel = 0;

for (auto line : headerLines_) {
for (const auto& line : headerLines_) {
if (line.find("<weightgroup") != std::string::npos) {
curLevel++;
if (curLevel != 1) {
Expand Down
10 changes: 5 additions & 5 deletions GeneratorInterface/Core/src/WeightHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace gen {
bool WeightHelper::isPartonShowerWeightGroup(const ParsedWeight& weight) {
const std::string& groupname = boost::to_lower_copy(weight.groupname);
std::vector<std::string> psNames = {"isr", "fsr", "nominal", "baseline", "emission"};
for (auto name : psNames) {
for (const auto& name : psNames) {
if (groupname.find(name) != std::string::npos)
return true;
}
Expand Down Expand Up @@ -128,7 +128,7 @@ namespace gen {
} catch (std::invalid_argument& e) {
pdfGroup.setIsWellFormed(false);
}
} else if (pdfGroup.lhaIds().size() > 0) {
} else if (!pdfGroup.lhaIds().empty()) {
return pdfGroup.lhaIds().back() + 1;
} else {
return LHAPDF::lookupLHAPDFID(weight.groupname);
Expand Down Expand Up @@ -240,7 +240,7 @@ namespace gen {

// Fall back to unordered search
int counter = 0;
for (auto weightGroup : weightGroups_) {
for (const auto& weightGroup : weightGroups_) {
if (weightGroup.containsWeight(wgtId, weightIndex))
return counter;
counter++;
Expand Down Expand Up @@ -290,8 +290,8 @@ namespace gen {

wgtPS.cacheWeightIndicesByLabel();
std::vector<std::string> labels = wgtPS.weightLabels();
if (labels.size() > FIRST_PSWEIGHT_ENTRY && labels.at(FIRST_PSWEIGHT_ENTRY).find(":") != std::string::npos &&
labels.at(FIRST_PSWEIGHT_ENTRY).find("=") != std::string::npos) {
if (labels.size() > FIRST_PSWEIGHT_ENTRY && labels.at(FIRST_PSWEIGHT_ENTRY).find(':') != std::string::npos &&
labels.at(FIRST_PSWEIGHT_ENTRY).find('=') != std::string::npos) {
wgtPS.setNameIsPythiaSyntax(true);
}
}
Expand Down
70 changes: 35 additions & 35 deletions GeneratorInterface/LHEInterface/plugins/ExternalLHEProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Description: [one line class summary]
//

class ExternalLHEProducer
: public edm::one::EDProducer<edm::BeginRunProducer, edm::EndRunProducer, edm::BeginLuminosityBlockProducer> {
: public edm::one::EDProducer<edm::BeginRunProducer, edm::EndRunProducer, edm::BeginLuminosityBlockProducer> {
public:
explicit ExternalLHEProducer(const edm::ParameterSet& iConfig);
~ExternalLHEProducer() override;
Expand Down Expand Up @@ -124,15 +124,15 @@ class ExternalLHEProducer
// constructors and destructor
//
ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig)
: scriptName_((iConfig.getParameter<edm::FileInPath>("scriptName")).fullPath()),
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")),
storeXML_(iConfig.getUntrackedParameter<bool>("storeXML")) {
: scriptName_((iConfig.getParameter<edm::FileInPath>("scriptName")).fullPath()),
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")),
storeXML_(iConfig.getUntrackedParameter<bool>("storeXML")) {
if (npars_ != args_.size())
throw cms::Exception("ExternalLHEProducer")
<< "Problem with configuration: " << args_.size() << " script arguments given, expected " << npars_;
<< "Problem with configuration: " << args_.size() << " script arguments given, expected " << npars_;

if (iConfig.exists("nPartonMapping")) {
auto& processMap(iConfig.getParameterSetVector("nPartonMapping"));
Expand All @@ -147,7 +147,7 @@ ExternalLHEProducer::ExternalLHEProducer(const edm::ParameterSet& iConfig)
order = 1;
else
throw cms::Exception("ExternalLHEProducer")
<< "Invalid order specification for process " << processId << ": " << orderStr;
<< "Invalid order specification for process " << processId << ": " << orderStr;

unsigned np(cfg.getParameter<unsigned>("np"));

Expand Down Expand Up @@ -178,13 +178,13 @@ void ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
nextEvent();
if (!partonLevel) {
throw edm::Exception(edm::errors::EventGenerationFailure)
<< "No lhe event found in ExternalLHEProducer::produce(). "
<< "The likely cause is that the lhe file contains fewer events than were requested, which is possible "
<< "in case of phase space integration or uneweighting efficiency problems.";
<< "No lhe event found in ExternalLHEProducer::produce(). "
<< "The likely cause is that the lhe file contains fewer events than were requested, which is possible "
<< "in case of phase space integration or uneweighting efficiency problems.";
}

std::unique_ptr<LHEEventProduct> product(
new LHEEventProduct(*partonLevel->getHEPEUP(), partonLevel->originalXWGTUP()));
new LHEEventProduct(*partonLevel->getHEPEUP(), partonLevel->originalXWGTUP()));
if (partonLevel->getPDF()) {
product->setPDF(*partonLevel->getPDF());
}
Expand All @@ -211,20 +211,20 @@ void ExternalLHEProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSe
np = procDef.second;
} catch (std::out_of_range&) {
throw cms::Exception("ExternalLHEProducer")
<< "Unexpected IDPRUP encountered: " << partonLevel->getHEPEUP()->IDPRUP;
<< "Unexpected IDPRUP encountered: " << partonLevel->getHEPEUP()->IDPRUP;
}

switch (order) {
case 0:
product->setNpLO(np);
product->setNpNLO(-1);
break;
case 1:
product->setNpLO(-1);
product->setNpNLO(np);
break;
default:
break;
case 0:
product->setNpLO(np);
product->setNpNLO(-1);
break;
case 1:
product->setNpLO(-1);
product->setNpNLO(np);
break;
default:
break;
}
}

Expand Down Expand Up @@ -273,9 +273,9 @@ void ExternalLHEProducer::beginRunProduce(edm::Run& run, edm::EventSetup const&

if (!rng.isAvailable()) {
throw cms::Exception("Configuration")
<< "The ExternalLHEProducer module requires the RandomNumberGeneratorService\n"
<< "The ExternalLHEProducer module requires the RandomNumberGeneratorService\n"
"which is not present in the configuration file. You must add the service\n"
"in the configuration file if you want to run ExternalLHEProducer";
"in the configuration file if you want to run ExternalLHEProducer";
}
std::ostringstream randomStream;
randomStream << rng->mySeed();
Expand Down Expand Up @@ -369,9 +369,9 @@ void ExternalLHEProducer::endRunProduce(edm::Run& run, edm::EventSetup const& es
nextEvent();
if (partonLevel) {
throw edm::Exception(edm::errors::EventGenerationFailure)
<< "Error in ExternalLHEProducer::endRunProduce(). "
<< "Event loop is over, but there are still lhe events to process."
<< "This could happen if lhe file contains more events than requested. This is never expected to happen.";
<< "Error in ExternalLHEProducer::endRunProduce(). "
<< "Event loop is over, but there are still lhe events to process."
<< "This could happen if lhe file contains more events than requested. This is never expected to happen.";
}

reader_.reset();
Expand Down Expand Up @@ -442,11 +442,11 @@ void ExternalLHEProducer::executeScript() {

if ((fd_flags = fcntl(filedes[1], F_GETFD, NULL)) == -1) {
throw cms::Exception("ExternalLHEProducer")
<< "Failed to get pipe file descriptor flags (errno=" << rc << ", " << strerror(rc) << ")";
<< "Failed to get pipe file descriptor flags (errno=" << rc << ", " << strerror(rc) << ")";
}
if (fcntl(filedes[1], F_SETFD, fd_flags | FD_CLOEXEC) == -1) {
throw cms::Exception("ExternalLHEProducer")
<< "Failed to set pipe file descriptor flags (errno=" << rc << ", " << strerror(rc) << ")";
<< "Failed to set pipe file descriptor flags (errno=" << rc << ", " << strerror(rc) << ")";
}

argc = 1 + args_.size();
Expand Down Expand Up @@ -478,7 +478,7 @@ void ExternalLHEProducer::executeScript() {

if (pid == -1) {
throw cms::Exception("ForkException")
<< "Unable to fork a child (errno=" << errno << ", " << strerror(errno) << ")";
<< "Unable to fork a child (errno=" << errno << ", " << strerror(errno) << ")";
}

close(filedes[1]);
Expand All @@ -488,7 +488,7 @@ void ExternalLHEProducer::executeScript() {
}
if ((rc2 == sizeof(int)) && rc) {
throw cms::Exception("ExternalLHEProducer")
<< "Failed to execute script (errno=" << rc << ", " << strerror(rc) << ")";
<< "Failed to execute script (errno=" << rc << ", " << strerror(rc) << ")";
}
close(filedes[0]);

Expand All @@ -500,7 +500,7 @@ void ExternalLHEProducer::executeScript() {
continue;
} else {
throw cms::Exception("ExternalLHEProducer")
<< "Failed to read child status (errno=" << errno << ", " << strerror(errno) << ")";
<< "Failed to read child status (errno=" << errno << ", " << strerror(errno) << ")";
}
}
if (WIFSIGNALED(status)) {
Expand Down Expand Up @@ -543,7 +543,7 @@ std::unique_ptr<std::string> ExternalLHEProducer::readOutput() {
<< " (errno=" << errno << ", " << strerror(errno) << ").";
}

return std::unique_ptr<std::string>(new std::string(ss.str()));
return std::make_unique<std::string>(ss.str());
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
Expand Down
Loading

0 comments on commit 76b867c

Please sign in to comment.