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

use std::stof with try/catch instead of std::regex #40915

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions PhysicsTools/IsolationAlgos/plugins/CandIsolatorFromDeposits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ using namespace edm;
using namespace reco;
using namespace reco::isodeposit;

bool isNumber(const std::string &str) {
static const std::regex re("^[+-]?(\\d+\\.?|\\d*\\.\\d*)$");
return regex_match(str.c_str(), re);
}
double toNumber(const std::string &str) { return atof(str.c_str()); }

CandIsolatorFromDeposits::SingleDeposit::SingleDeposit(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
: srcToken_(iC.consumes<reco::IsoDepositMap>(iConfig.getParameter<edm::InputTag>("src"))),
deltaR_(iConfig.getParameter<double>("deltaR")),
Expand Down Expand Up @@ -108,15 +102,12 @@ CandIsolatorFromDeposits::SingleDeposit::SingleDeposit(const edm::ParameterSet &
evdepVetos_.push_back(evdep);
}
std::string weight = iConfig.getParameter<std::string>("weight");
if (isNumber(weight)) {
//std::cout << "Weight is a simple number, " << toNumber(weight) << std::endl;
weight_ = toNumber(weight);
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we really go with the exception approach (which we generally disfavor), please add

Suggested change
try {
CMS_SA_ALLOW try {

to avoid static analyzer complaints.

weight_ = std::stof(weight);
usesFunction_ = false;
} else {
} catch (...) {
usesFunction_ = true;
//std::cout << "Weight is a function, this might slow you down... " << std::endl;
}
//std::cout << "CandIsolatorFromDeposits::SingleDeposit::SingleDeposit: Total of " << vetos_.size() << " vetos" << std::endl;
}
void CandIsolatorFromDeposits::SingleDeposit::cleanup() {
for (AbsVetos::iterator it = vetos_.begin(), ed = vetos_.end(); it != ed; ++it) {
Expand Down