Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:31

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 #include "Parsers/config.h"
0015 
0016 // Framework include files
0017 #if defined(DD4HEP_PARSER_HEADER)
0018 
0019 #define DD4HEP_NEED_EVALUATOR
0020 // This is the case, if the parsers are externalized
0021 // and the dd4hep namespace is renamed!
0022 #include DD4HEP_PARSER_HEADER
0023 
0024 #else
0025 
0026 // Standard dd4hep parser handling
0027 #include "Parsers/spirit/ToStream.h"
0028 
0029 #endif
0030 #include "Evaluator/Evaluator.h"
0031 
0032 // C/C++ include files
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& /* value */)   {
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 }