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