From 46bdccd3f50419f385043d96c808fb3faa40cf6b Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Wed, 1 Mar 2023 15:04:52 +0100 Subject: [PATCH] use std::stof with try/catch instead of std::regex --- .../plugins/CandIsolatorFromDeposits.cc | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/PhysicsTools/IsolationAlgos/plugins/CandIsolatorFromDeposits.cc b/PhysicsTools/IsolationAlgos/plugins/CandIsolatorFromDeposits.cc index f800cb77d708e..390a44d851808 100644 --- a/PhysicsTools/IsolationAlgos/plugins/CandIsolatorFromDeposits.cc +++ b/PhysicsTools/IsolationAlgos/plugins/CandIsolatorFromDeposits.cc @@ -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(iConfig.getParameter("src"))), deltaR_(iConfig.getParameter("deltaR")), @@ -108,15 +102,12 @@ CandIsolatorFromDeposits::SingleDeposit::SingleDeposit(const edm::ParameterSet & evdepVetos_.push_back(evdep); } std::string weight = iConfig.getParameter("weight"); - if (isNumber(weight)) { - //std::cout << "Weight is a simple number, " << toNumber(weight) << std::endl; - weight_ = toNumber(weight); + try { + 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) {