From 95b936cc5790c05d22fd9e0ed75dd0a7d52d0511 Mon Sep 17 00:00:00 2001 From: Purva-Chaudhari Date: Fri, 20 Aug 2021 20:40:55 +0200 Subject: [PATCH 1/2] Remove boost lexical_cast dependency in FWCore --- FWCore/Modules/src/EventContentAnalyzer.cc | 5 ----- FWCore/ParameterSet/src/types.cc | 5 ++--- FWCore/Services/plugins/ProcInfoFetcher.cc | 13 ++++++------- FWCore/Services/plugins/SimpleMemoryCheck.cc | 1 - FWCore/Utilities/src/ReleaseVersion.cc | 11 +++++------ 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/FWCore/Modules/src/EventContentAnalyzer.cc b/FWCore/Modules/src/EventContentAnalyzer.cc index 447bc64694335..ca813d12bd36d 100644 --- a/FWCore/Modules/src/EventContentAnalyzer.cc +++ b/FWCore/Modules/src/EventContentAnalyzer.cc @@ -436,11 +436,6 @@ namespace edm { for (nameMap::const_iterator it = cumulates_.begin(), itEnd = cumulates_.end(); it != itEnd; ++it) { LogAbsolute("EventContent") << std::setw(6) << it->second << " occurrences of key " << it->first << std::endl; } - - // Test boost::lexical_cast We don't need this right now so comment it out. - // int k = 137; - // std::string ktext = boost::lexical_cast(k); - // std::cout << "\nInteger " << k << " expressed as a string is |" << ktext << "|" << std::endl; } void EventContentAnalyzer::fillDescriptions(ConfigurationDescriptions& descriptions) { diff --git a/FWCore/ParameterSet/src/types.cc b/FWCore/ParameterSet/src/types.cc index d5b81cf890cec..84157a443d78a 100644 --- a/FWCore/ParameterSet/src/types.cc +++ b/FWCore/ParameterSet/src/types.cc @@ -8,7 +8,6 @@ #include "FWCore/ParameterSet/interface/types.h" -#include "boost/lexical_cast.hpp" #include "FWCore/ParameterSet/src/split.h" #include "FWCore/Utilities/interface/Parse.h" #include @@ -459,9 +458,9 @@ bool edm::decode(double& to, std::string const& from) { else { try { // std::cerr << "from:" << from << std::endl; - to = boost::lexical_cast(from); + to = std::stod(from); // std::cerr << "to:" << to << std::endl; - } catch (boost::bad_lexical_cast&) { + } catch (const std::invalid_argument&) { return false; } } diff --git a/FWCore/Services/plugins/ProcInfoFetcher.cc b/FWCore/Services/plugins/ProcInfoFetcher.cc index aac69f4e7d359..f493129c29cca 100644 --- a/FWCore/Services/plugins/ProcInfoFetcher.cc +++ b/FWCore/Services/plugins/ProcInfoFetcher.cc @@ -23,7 +23,6 @@ #include //#include #include -#include #include #include @@ -96,27 +95,27 @@ namespace { int getInt() { const char* t = getItem(); //std::cout <<"int '"<(t); + return std::stoi(t); } long getLong() { const char* t = getItem(); //std::cout <<"long '"<(t); + return std::stol(t); } unsigned int getUInt() { const char* t = getItem(); //std::cout <<"uint '"<(t); + return std::stoul(t); } unsigned long getULong() { const char* t = getItem(); //std::cout <<"ulong '"<(t); + return std::stoul(t); } unsigned long long getULongLong() { const char* t = getItem(); //std::cout <<"ulong '"<(t); + return std::stoull(t); } char getChar() { return *getItem(); } std::string getString() { return std::string(getItem()); } @@ -210,7 +209,7 @@ namespace edm { pinfo.num_threads >> pinfo.itrealvalue >> pinfo.starttime >> pinfo.vsize >> pinfo.rss >> pinfo.rlim >> pinfo.startcode >> pinfo.endcode >> pinfo.startstack >> pinfo.kstkesp >> pinfo.kstkeip >> pinfo.signal >> pinfo.blocked >> pinfo.sigignore >> pinfo.sigcatch >> pinfo.wchan; - } catch (boost::bad_lexical_cast& iE) { + } catch (const std::invalid_argument& iE) { LogWarning("ProcInfoFetcher") << "Parsing of Prof file failed:" << iE.what() << std::endl; return ProcInfo(); } diff --git a/FWCore/Services/plugins/SimpleMemoryCheck.cc b/FWCore/Services/plugins/SimpleMemoryCheck.cc index da81b98c76b39..8ed7fcd4de984 100644 --- a/FWCore/Services/plugins/SimpleMemoryCheck.cc +++ b/FWCore/Services/plugins/SimpleMemoryCheck.cc @@ -52,7 +52,6 @@ //#include #include //#include -#include #include #include diff --git a/FWCore/Utilities/src/ReleaseVersion.cc b/FWCore/Utilities/src/ReleaseVersion.cc index eefd8da07d4a4..4fd4c4bcbe9ff 100644 --- a/FWCore/Utilities/src/ReleaseVersion.cc +++ b/FWCore/Utilities/src/ReleaseVersion.cc @@ -1,7 +1,6 @@ #include "FWCore/Utilities/interface/ReleaseVersion.h" #include "boost/algorithm/string.hpp" -#include "boost/lexical_cast.hpp" #include #include @@ -33,17 +32,17 @@ namespace edm { /* if(parts.size() == 4) { if(releaseVersion.find("patch") != std::string::npos) { - patch_ = boost::lexical_cast(parts[3]); + patch_ = std::stoul(parts[3]); } else if(releaseVersion.find("pre") != std::string::npos) { - pre_ = boost::lexical_cast(parts[3]); + pre_ = std::stoul(parts[3]); } else { return; } } */ - major_ = boost::lexical_cast(parts[0]); - minor_ = boost::lexical_cast(parts[1]); - // point_ = boost::lexical_cast(parts[2]); + major_ = std::stoul(parts[0]); + minor_ = std::stoul(parts[1]); + // point_ = std::stoul(parts[2]); irregular_ = false; } catch (std::exception const&) { } From 37da860e4f11c7649a055bebbacdbe45171398f3 Mon Sep 17 00:00:00 2001 From: Purva-Chaudhari Date: Mon, 23 Aug 2021 19:19:41 +0200 Subject: [PATCH 2/2] catch std::exception --- FWCore/ParameterSet/src/types.cc | 2 +- FWCore/Services/plugins/ProcInfoFetcher.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FWCore/ParameterSet/src/types.cc b/FWCore/ParameterSet/src/types.cc index 84157a443d78a..abcfd9316a167 100644 --- a/FWCore/ParameterSet/src/types.cc +++ b/FWCore/ParameterSet/src/types.cc @@ -460,7 +460,7 @@ bool edm::decode(double& to, std::string const& from) { // std::cerr << "from:" << from << std::endl; to = std::stod(from); // std::cerr << "to:" << to << std::endl; - } catch (const std::invalid_argument&) { + } catch (const std::exception&) { return false; } } diff --git a/FWCore/Services/plugins/ProcInfoFetcher.cc b/FWCore/Services/plugins/ProcInfoFetcher.cc index f493129c29cca..83d270b2aba85 100644 --- a/FWCore/Services/plugins/ProcInfoFetcher.cc +++ b/FWCore/Services/plugins/ProcInfoFetcher.cc @@ -209,7 +209,7 @@ namespace edm { pinfo.num_threads >> pinfo.itrealvalue >> pinfo.starttime >> pinfo.vsize >> pinfo.rss >> pinfo.rlim >> pinfo.startcode >> pinfo.endcode >> pinfo.startstack >> pinfo.kstkesp >> pinfo.kstkeip >> pinfo.signal >> pinfo.blocked >> pinfo.sigignore >> pinfo.sigcatch >> pinfo.wchan; - } catch (const std::invalid_argument& iE) { + } catch (const std::exception& iE) { LogWarning("ProcInfoFetcher") << "Parsing of Prof file failed:" << iE.what() << std::endl; return ProcInfo(); }