Go to the documentation of this file.00001
00002 #include "DetectorDescription/Core/interface/DDConstant.h"
00003 #include "DetectorDescription/Base/interface/DDException.h"
00004
00005
00006 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00007
00008 DDConstant::DDConstant() : DDBase<DDName,double*>() { }
00009
00010
00011 DDConstant::DDConstant(const DDName & name) : DDBase<DDName,double*>()
00012 {
00013 prep_ = StoreT::instance().create(name);
00014 }
00015
00016 DDConstant::DDConstant(const DDName & name,double* vals)
00017 {
00018 prep_ = StoreT::instance().create(name,vals);
00019 }
00020
00021
00022 std::ostream & operator<<(std::ostream & os, const DDConstant & cons)
00023 {
00024 os << "DDConstant name=" << cons.name();
00025
00026 if(cons.isDefined().second) {
00027 os << " val=" << cons.value();
00028 }
00029 else {
00030 os << " constant is not yet defined, only declared.";
00031 }
00032 return os;
00033 }
00034
00035
00036 void DDConstant::createConstantsFromEvaluator()
00037 {
00038 ExprEvalInterface & ev = ExprEvalSingleton::instance();
00039 ClhepEvaluator * eval = dynamic_cast<ClhepEvaluator*>(&ev);
00040 if (eval){
00041 const std::vector<std::string> & vars = eval->variables();
00042 const std::vector<std::string> & vals = eval->values();
00043 if (vars.size() != vals.size()) {
00044 throw DDException("DDConstants::createConstansFromEvaluator(): different size of variable names & values!") ;
00045 }
00046 size_t i(0), s(vars.size());
00047 for (; i<s; ++i) {
00048 const std::string & sr = vars[i];
00049 typedef std::string::size_type ST;
00050 ST i1 = sr.find("___");
00051 DDName name(std::string(sr,i1+3,sr.size()-1),std::string(sr,0,i1));
00052 double* dv = new double;
00053 *dv = eval->eval(sr.c_str());
00054 DDConstant cst(name,dv);
00055 }
00056 }
00057 else {
00058 throw DDException("DDConstants::createConstansFromEvaluator(): expression-evaluator is not a ClhepEvaluator-implementation!");
00059 }
00060 }
00061
00062