ATLAS Offline Software
Loading...
Searching...
No Matches
PixelConditionsDataStringUtils.h
Go to the documentation of this file.
1#ifndef PixelConditionsData_StringUtils
2#define PixelConditionsData_StringUtils
3
4#include <vector>
5#include <string>
6#include <cctype> //for std::tolower
7
8
10
11 //for PixelConfigCondAlg
12 template <class T = std::string>
13 T
14 fromString(const std::string & s){
15 return s;
16 }
17
18 template<>
19 inline float
20 fromString(const std::string &s){
21 return std::stof(s);
22 }
23
24 template <>
25 inline double
26 fromString(const std::string & s){
27 return std::stod(s);
28 }
29
30 template <>
31 inline int
32 fromString(const std::string & s){
33 return std::stoi(s);
34 }
35
36 template<>
37 inline bool
38 fromString(const std::string & s){
39 std::string v=s;
40 for (char & c: v) c = std::tolower(c);
41 if (v.find("false")!=std::string::npos) return false;
42 if (v.find("true")!=std::string::npos) return true;
43 throw("bad conversion");
44 }
45
46 std::vector<std::string>
47 getParameterString(const std::string& varName, const std::vector<std::string>& buffer);
48
49 template <class T>
50 std::vector<T>
51 getParameter(const std::string& varName, const std::vector<std::string>& buffer){
52 const std::vector<std::string> & varString = getParameterString(varName, buffer);
53 std::vector<T> result;
54 for (const auto & var : varString) {
55 result.emplace_back(fromString<T>(var));
56 }
57 return result;
58 }
59}
60#endif
T fromString(const std::string &s)
std::vector< std::string > getParameterString(const std::string &varName, const std::vector< std::string > &buffer)
std::vector< T > getParameter(const std::string &varName, const std::vector< std::string > &buffer)