File indexing completed on 2025-01-18 09:14:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include "Parsers/config.h"
0015
0016
0017 #if defined(DD4HEP_PARSER_HEADER)
0018
0019 #define DD4HEP_NEED_EVALUATOR
0020
0021
0022 #include DD4HEP_PARSER_HEADER
0023
0024 #else
0025
0026
0027 #include "Parsers/spirit/ToStream.h"
0028
0029 #endif
0030 #include "Evaluator/Evaluator.h"
0031
0032
0033 #include <sstream>
0034 #include <iostream>
0035 #include <stdexcept>
0036
0037 namespace dd4hep {
0038 const dd4hep::tools::Evaluator& g4Evaluator();
0039 }
0040 namespace {
0041 const dd4hep::tools::Evaluator& eval(dd4hep::g4Evaluator());
0042 }
0043
0044
0045 namespace dd4hep { namespace Parsers {
0046 template <typename T> T evaluate_string(const std::string& ) {
0047 throw "Bad undefined call";
0048 }
0049
0050 template <> double evaluate_string<double>(const std::string& value) {
0051 std::stringstream err;
0052 auto result = eval.evaluate(value, err);
0053 if (result.first != tools::Evaluator::OK) {
0054 throw std::runtime_error("dd4hep::Properties: Severe error during expression evaluation of " +
0055 value + " : " + err.str());
0056 }
0057 return result.second;
0058 }
0059 template <> float evaluate_string<float>(const std::string& value) {
0060 std::stringstream err;
0061 auto result = eval.evaluate(value, err);
0062 if (result.first != tools::Evaluator::OK) {
0063 throw std::runtime_error("dd4hep::Properties: Severe error during expression evaluation of " +
0064 value + " : " + err.str());
0065 }
0066 return (float) result.second;
0067 }
0068 }
0069 }