File indexing completed on 2025-01-31 09:20:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include "Detector/ParameterMap.h"
0018 #include "DD4hep/Handle.h"
0019
0020 namespace {
0021 static gaudi::ParameterMap::Parameter s_empty;
0022 }
0023
0024
0025 namespace gaudi {
0026
0027
0028 template <typename T> T ParameterMap::Parameter::get() const {
0029 if ( this == &s_empty ) return 0;
0030 return dd4hep::_toType<T>(value);
0031 }
0032
0033
0034 bool ParameterMap::set(const std::string& nam, const std::string& val, const std::string& type) {
0035 const auto i = m_params.find(nam);
0036 if ( i == m_params.end() ) {
0037 return m_params.insert(make_pair(nam,Parameter(val,type))).second;
0038 }
0039 (*i).second.value = val;
0040 (*i).second.type = type;
0041 return false;
0042 }
0043
0044
0045 const ParameterMap::Parameter& ParameterMap::parameter(const std::string& nam, bool throw_if) const {
0046 const auto i = m_params.find(nam);
0047 if ( i != m_params.end() )
0048 return (*i).second;
0049 else if ( throw_if ) {
0050 throw std::runtime_error("ParameterMap: Attempt to access non-existng parameter: "+nam);
0051 }
0052 return s_empty;
0053 }
0054
0055
0056 template <typename T> T ParameterMap::param(const std::string& nam, bool throw_if) const {
0057 return parameter(nam, throw_if).template get<T>();
0058 }
0059
0060 #define INST(x) template x ParameterMap::Parameter::get() const; \
0061 template x ParameterMap::param(const std::string& nam, bool throw_if_not_present) const
0062
0063 INST(bool);
0064 INST(int);
0065 INST(short);
0066 INST(long);
0067 INST(double);
0068 INST(float);
0069 INST(std::string);
0070 }
0071
0072
0073